Module: Chess::PlayMovesByType
- Includes:
- PlayKingMoves, PlayPawnMoves
- Included in:
- Player
- Defined in:
- lib/chess/play_moves/play_moves_by_type.rb
Overview
Play all types of moves
Constant Summary
Constants included from Display
Instance Method Summary collapse
-
#play_move_by_type(piece, board, move_pos, inside_valid_moves_flag: false) ⇒ void
play different move based on type of the piece.
-
#play_normal_move(piece, board, move_pos) ⇒ void
play normal move.
-
#update_player_board_data(piece, board, inside_valid_moves_flag) ⇒ void
update some player and board data.
Methods included from PlayKingMoves
#castling_move?, #play_castling_move, #play_king_move, #play_rook_jump_move
Methods included from PlayPawnMoves
#attacking_en_passant?, #move_two_step, #pawn_is_promoting?, #pawn_two_step_move?, #play_pawn_move, #play_pawn_promotion, #remove_en_passant_from_board, #remove_enemy_en_passant_pawn, #set_board_possible_en_passant
Methods included from Display
#bg_color, #color, #display_board, #display_buttons, #king_check_dot, #move_dots, #print_board_data, #print_files, #print_piece_square, #print_square, #prompt_enter_code, #prompt_pawn_promotion_choices, #prompt_save_name, #prompt_select_save, #prompt_start_choices, #redraw_display, #square_bg_color_name, #square_string
Instance Method Details
#play_move_by_type(piece, board, move_pos, inside_valid_moves_flag: false) ⇒ void
This method returns an undefined value.
play different move based on type of the piece
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chess/play_moves/play_moves_by_type.rb', line 16 def play_move_by_type(piece, board, move_pos, inside_valid_moves_flag: false) # rubocop:disable Metrics/MethodLength update_player_board_data(piece, board, inside_valid_moves_flag) if piece.is_a?(Pieces::Pawn) play_pawn_move(piece, board, move_pos, inside_valid_moves_flag) board.reset_half_move unless inside_valid_moves_flag elsif piece.is_a?(Pieces::King) play_king_move(piece, board, move_pos) else play_normal_move(piece, board, move_pos) end change_player_turn(board) remove_en_passant_from_board(board) if @remove_en_passant end |
#play_normal_move(piece, board, move_pos) ⇒ void
This method returns an undefined value.
play normal move
35 36 37 38 39 40 |
# File 'lib/chess/play_moves/play_moves_by_type.rb', line 35 def play_normal_move(piece, board, move_pos) board.remove_piece_at(piece.pos) board.reset_half_move if board.piece_at(*move_pos).is_a?(Pieces::Piece) board.remove_piece_at(move_pos) board.insert_piece_at(piece, move_pos) end |
#update_player_board_data(piece, board, inside_valid_moves_flag) ⇒ void
This method returns an undefined value.
update some player and board data
47 48 49 50 51 |
# File 'lib/chess/play_moves/play_moves_by_type.rb', line 47 def update_player_board_data(piece, board, inside_valid_moves_flag) board.half_move += 1 unless inside_valid_moves_flag @remove_en_passant = true board.full_move += 1 if !inside_valid_moves_flag && piece.black? end |