Module: PGN::PositionFields

Included in:
EPD, FEN
Defined in:
lib/pgn/fen.rb

Overview

Shared FEN/EPD board-field parsing and serialization: the piece-placement field, and the '-'-normalized castling/en-passant fields. FEN and EPD both include this rather than each carrying their own copy.

Instance Method Summary collapse

Instance Method Details

#board_stringString

Returns the FEN/EPD board-string portion.

Returns:

  • (String)

    the FEN/EPD board-string portion



26
27
28
# File 'lib/pgn/fen.rb', line 26

def board_string
  board.fen_board_string
end

#board_string=(board_fen) ⇒ Object

Parameters:

  • board_fen (String)

    the FEN/EPD representation of the board



15
16
17
18
19
20
21
22
23
# File 'lib/pgn/fen.rb', line 15

def board_string=(board_fen)
  squares = board_fen.gsub(/\d/) { |match| '_' * match.to_i }
                     .split('/')
                     .map(&:chars)
                     .map { |row| row.map { |e| e == '_' ? nil : e } }
                     .reverse
                     .transpose
  self.board = PGN::Board.new(squares)
end

#castling=(val) ⇒ Object



6
7
8
# File 'lib/pgn/fen.rb', line 6

def castling=(val)
  @castling = val.nil? || val.empty? ? '-' : val
end

#en_passant=(val) ⇒ Object



10
11
12
# File 'lib/pgn/fen.rb', line 10

def en_passant=(val)
  @en_passant = val.nil? ? '-' : val
end