Module: EnPassantBoardControl
- Included in:
- Board
- Defined in:
- lib/sapphire-chess/movement_rules/en_passant_board_control.rb
Instance Method Summary collapse
- #capture_passed_pawn!(target_square) ⇒ Object
- #passed_pawn(target_square) ⇒ Object
- #was_en_passant?(piece, target_square) ⇒ Boolean
Instance Method Details
#capture_passed_pawn!(target_square) ⇒ Object
2 3 4 5 6 |
# File 'lib/sapphire-chess/movement_rules/en_passant_board_control.rb', line 2 def capture_passed_pawn!(target_square) captured_pawn = passed_pawn(target_square) self[captured_pawn] = EmptySquare.instance end |
#passed_pawn(target_square) ⇒ Object
15 16 17 18 19 |
# File 'lib/sapphire-chess/movement_rules/en_passant_board_control.rb', line 15 def passed_pawn(target_square) direction = self[target_square].color == :white ? 1 : -1 [target_square.first + direction, target_square.last] end |
#was_en_passant?(piece, target_square) ⇒ Boolean
8 9 10 11 12 13 |
# File 'lib/sapphire-chess/movement_rules/en_passant_board_control.rb', line 8 def was_en_passant?(piece, target_square) captured_pawn = passed_pawn(target_square) self[target_square].is_a?(Pawn) && self[target_square].pawn_to_pass(piece).include?(captured_pawn) end |