Method: PGN::Position#move

Defined in:
lib/pgn/position.rb

#move(str) ⇒ PGN::Position

Returns the resulting position.

Examples:

queens_pawn = PGN::Position.start.move("d4")

Parameters:

  • str (String)

    the move to make in SAN

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pgn/position.rb', line 80

def move(str)
  move       = PGN::Move.new(str, player)
  calculator = PGN::MoveCalculator.new(board, move)

  new_castling = castling - calculator.castling_restrictions
  new_halfmove = if calculator.increment_halfmove?
                   halfmove + 1
                 else
                   0
                 end
  new_fullmove = if calculator.increment_fullmove?
                   fullmove + 1
                 else
                   fullmove
                 end
  no_move = str == '--'
  PGN::Position.new(
    no_move ? board : calculator.result_board,
    next_player,
    new_castling,
    calculator.en_passant_square,
    new_halfmove,
    new_fullmove
  )
end