Module: Chess::PlayKingMoves
- Included in:
- PlayMovesByType
- Defined in:
- lib/chess/play_moves/play_king_moves.rb
Overview
PlayKingMoves
Instance Method Summary collapse
-
#castling_move?(piece, board, move_pos) ⇒ Boolean
check if move is a castling_move.
-
#play_castling_move(piece, board, move_pos) ⇒ void
plays the castling move (a special move which moves 2 pieces a king and a rook).
-
#play_king_move(piece, board, move_pos) ⇒ void
plays the given castling move or normal move for king.
-
#play_rook_jump_move(piece, board, rook_move_pos) ⇒ void
plays the move of jumping rook over to the other side of king.
Instance Method Details
#castling_move?(piece, board, move_pos) ⇒ Boolean
check if move is a castling_move
24 25 26 27 |
# File 'lib/chess/play_moves/play_king_moves.rb', line 24 def castling_move?(piece, board, move_pos) castling_moves = piece.castling_moves(board) castling_moves.include?(move_pos) end |
#play_castling_move(piece, board, move_pos) ⇒ void
This method returns an undefined value.
plays the castling move (a special move which moves 2 pieces a king and a rook)
33 34 35 36 |
# File 'lib/chess/play_moves/play_king_moves.rb', line 33 def play_castling_move(piece, board, move_pos) play_normal_move(piece, board, move_pos) play_rook_jump_move(piece, board, move_pos) end |
#play_king_move(piece, board, move_pos) ⇒ void
This method returns an undefined value.
plays the given castling move or normal move for king
13 14 15 16 17 18 19 |
# File 'lib/chess/play_moves/play_king_moves.rb', line 13 def play_king_move(piece, board, move_pos) if castling_move?(piece, board, move_pos) play_castling_move(piece, board, move_pos) else play_normal_move(piece, board, move_pos) end end |
#play_rook_jump_move(piece, board, rook_move_pos) ⇒ void
This method returns an undefined value.
plays the move of jumping rook over to the other side of king
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chess/play_moves/play_king_moves.rb', line 44 def play_rook_jump_move(piece, board, rook_move_pos) # rubocop:disable Metrics/MethodLength king_file = piece.pos.first king_rank = piece.pos.last if king_file == 'c' rook = board.piece_at('a', king_rank) rook_move_pos = ['d', king_rank] play_normal_move(rook, board, rook_move_pos) elsif king_file == 'g' rook = board.piece_at('h', king_rank) rook_move_pos = ['f', king_rank] play_normal_move(rook, board, rook_move_pos) end end |