Module: EnPassantPieceControl
- Included in:
- Pawn
- Defined in:
- lib/sapphire-chess/movement_rules/en_passant_piece_control.rb
Instance Method Summary collapse
- #add_en_passant_movement!(moves) ⇒ Object
- #en_passant_target_square(adyacent_enemy_pawn) ⇒ Object
- #pawn_just_moved_two?(square) ⇒ Boolean
- #pawn_to_pass(current_square = location) ⇒ Object
Instance Method Details
#add_en_passant_movement!(moves) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/sapphire-chess/movement_rules/en_passant_piece_control.rb', line 2 def add_en_passant_movement!(moves) adyacent_enemy_pawn = pawn_to_pass.first return if adyacent_enemy_pawn.nil? moves << en_passant_target_square(adyacent_enemy_pawn) end |
#en_passant_target_square(adyacent_enemy_pawn) ⇒ Object
31 32 33 34 35 |
# File 'lib/sapphire-chess/movement_rules/en_passant_piece_control.rb', line 31 def en_passant_target_square(adyacent_enemy_pawn) direction = color == :white ? -1 : 1 [adyacent_enemy_pawn.first + direction, adyacent_enemy_pawn.last] end |
#pawn_just_moved_two?(square) ⇒ Boolean
21 22 23 24 25 26 27 28 29 |
# File 'lib/sapphire-chess/movement_rules/en_passant_piece_control.rb', line 21 def pawn_just_moved_two?(square) if color == :white board.black_player.history.last == [[square.first - 2, square.last], square] else board.white_player.history.last == [[square.first + 2, square.last], square] end end |
#pawn_to_pass(current_square = location) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sapphire-chess/movement_rules/en_passant_piece_control.rb', line 9 def pawn_to_pass(current_square = location) # See Piece#safe_moves, Board#is_a_duplicate? return [] if board.a_duplicate? left_square = [current_square.first, current_square.last - 1] right_square = [current_square.first, current_square.last + 1] [left_square, right_square].select do |square| board[square].is_a?(Pawn) && pawn_just_moved_two?(square) end end |