Class: ChessData::Moves::PawnCapture
- Inherits:
-
Object
- Object
- ChessData::Moves::PawnCapture
- Defined in:
- lib/chess_data/moves.rb
Overview
Methods to support a pawn move which makes a capture.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(move) ⇒ PawnCapture
constructor
A new instance of PawnCapture.
-
#make_move(board) ⇒ Object
Returns a new instance of the board after move is made.
- #to_s ⇒ Object
Constructor Details
#initialize(move) ⇒ PawnCapture
Returns a new instance of PawnCapture.
387 388 389 390 391 392 |
# File 'lib/chess_data/moves.rb', line 387 def initialize move @move_string = move move =~ MatchPawnCapture @source = $1 @destination = $2 end |
Instance Method Details
#make_move(board) ⇒ Object
Returns a new instance of the board after move is made.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/chess_data/moves.rb', line 399 def make_move board origin = find_origin board.to_move revised_board = board.clone if @destination == board.enpassant_target revised_board["#{@destination[0]}#{origin[1]}"] = nil end revised_board[origin] = nil revised_board[@destination] = board[origin] revised_board.enpassant_target = "-" revised_board.halfmove_clock = 0 if board.to_move == "w" revised_board.to_move = "b" else revised_board.to_move = "w" revised_board.fullmove_number += 1 end return revised_board end |
#to_s ⇒ Object
394 395 396 |
# File 'lib/chess_data/moves.rb', line 394 def to_s @move_string end |