Class: PGN::EPD
Overview
EPD translates between strings in Extended Position Description
and a Position. EPD is the FEN-like position format used by
EPD tools:
it shares FEN's first four fields (piece placement, side to move,
castling availability, en passant target square) and then carries a
trailing list of operations (ops) instead of the halfmove/fullmove
counters.
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#board ⇒ Object
Returns the value of attribute board.
-
#castling ⇒ Object
readonly
Returns the value of attribute castling.
-
#en_passant ⇒ Object
readonly
Returns the value of attribute en_passant.
-
#ops ⇒ Object
Returns the value of attribute ops.
Instance Method Summary collapse
-
#initialize(epd_string = nil) ⇒ EPD
constructor
A new instance of EPD.
- #inspect ⇒ Object
-
#to_position ⇒ PGN::Position
A Position for this EPD.
-
#to_s ⇒ String
The EPD string (four fields, then
opsif present).
Methods included from PositionFields
#board_string, #board_string=, #castling=, #en_passant=
Constructor Details
#initialize(epd_string = nil) ⇒ EPD
Returns a new instance of EPD.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pgn/epd.rb', line 25 def initialize(epd_string = nil) return unless epd_string fields = epd_string.split(' ', 5) self.board_string = fields[0] self.active = fields[1] self.castling = fields[2] self.en_passant = fields[3] self.ops = fields[4] end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
19 20 21 |
# File 'lib/pgn/epd.rb', line 19 def active @active end |
#board ⇒ Object
Returns the value of attribute board.
19 20 21 |
# File 'lib/pgn/epd.rb', line 19 def board @board end |
#castling ⇒ Object (readonly)
Returns the value of attribute castling.
20 21 22 |
# File 'lib/pgn/epd.rb', line 20 def castling @castling end |
#en_passant ⇒ Object (readonly)
Returns the value of attribute en_passant.
20 21 22 |
# File 'lib/pgn/epd.rb', line 20 def en_passant @en_passant end |
#ops ⇒ Object
Returns the value of attribute ops.
19 20 21 |
# File 'lib/pgn/epd.rb', line 19 def ops @ops end |
Instance Method Details
#inspect ⇒ Object
50 51 52 |
# File 'lib/pgn/epd.rb', line 50 def inspect to_s end |
#to_position ⇒ PGN::Position
Returns a Position for this EPD. Halfmove and fullmove default to 0 and 1 (EPD does not carry them).
39 40 41 42 |
# File 'lib/pgn/epd.rb', line 39 def to_position player, castling_rights, ep = position_fields PGN::Position.new(board, player, castling_rights, ep, 0, 1) end |
#to_s ⇒ String
Returns the EPD string (four fields, then ops if present).
46 47 48 |
# File 'lib/pgn/epd.rb', line 46 def to_s [board_string, active, castling, en_passant, ops].compact.reject(&:empty?).join(' ') end |