Class: Sashite::Feen::Position
- Inherits:
-
Object
- Object
- Sashite::Feen::Position
- Defined in:
- lib/sashite/feen/position.rb,
lib/sashite/feen/position/hands.rb,
lib/sashite/feen/position/style_turn.rb,
lib/sashite/feen/position/piece_placement.rb
Overview
Represents a parsed FEEN (Field Expression Encoding Notation) position.
A Position encapsulates the three FEEN fields:
-
Piece Placement: Board occupancy
-
Hands: Off-board pieces held by each player
-
Style-Turn: Player styles and active player
Instances are immutable (frozen after creation).
Defined Under Namespace
Classes: Hand, Hands, PiecePlacement, StyleTurn
Instance Attribute Summary collapse
-
#hands ⇒ Hands
readonly
Off-board pieces.
-
#piece_placement ⇒ PiecePlacement
readonly
Board occupancy.
-
#style_turn ⇒ StyleTurn
readonly
Player styles and active player.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks equality with another Position.
-
#hash ⇒ Integer
Returns a hash code for the Position.
-
#initialize(piece_placement:, hands:, style_turn:) ⇒ Position
constructor
Creates a new Position instance from parsed components.
-
#inspect ⇒ String
Returns an inspect string for the Position.
-
#to_s ⇒ String
Returns the canonical FEEN string representation.
Constructor Details
#initialize(piece_placement:, hands:, style_turn:) ⇒ Position
Creates a new Position instance from parsed components.
43 44 45 46 47 48 49 |
# File 'lib/sashite/feen/position.rb', line 43 def initialize(piece_placement:, hands:, style_turn:) @piece_placement = PiecePlacement.new(**piece_placement) @hands = Hands.new(**hands) @style_turn = StyleTurn.new(**style_turn) freeze end |
Instance Attribute Details
#hands ⇒ Hands (readonly)
Returns Off-board pieces.
32 33 34 |
# File 'lib/sashite/feen/position.rb', line 32 def hands @hands end |
#piece_placement ⇒ PiecePlacement (readonly)
Returns Board occupancy.
29 30 31 |
# File 'lib/sashite/feen/position.rb', line 29 def piece_placement @piece_placement end |
#style_turn ⇒ StyleTurn (readonly)
Returns Player styles and active player.
35 36 37 |
# File 'lib/sashite/feen/position.rb', line 35 def style_turn @style_turn end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks equality with another Position.
66 67 68 69 70 71 72 |
# File 'lib/sashite/feen/position.rb', line 66 def ==(other) return false unless self.class === other piece_placement == other.piece_placement && hands == other.hands && style_turn == other.style_turn end |
#hash ⇒ Integer
Returns a hash code for the Position.
79 80 81 |
# File 'lib/sashite/feen/position.rb', line 79 def hash [piece_placement, hands, style_turn].hash end |
#inspect ⇒ String
Returns an inspect string for the Position.
86 87 88 |
# File 'lib/sashite/feen/position.rb', line 86 def inspect "#<#{self.class} #{self}>" end |
#to_s ⇒ String
Returns the canonical FEEN string representation.
54 55 56 57 58 59 60 |
# File 'lib/sashite/feen/position.rb', line 54 def to_s [ piece_placement.to_s, hands.to_s, style_turn.to_s ].join(Constants::FIELD_SEPARATOR) end |