Class: Sashite::Feen::Position
- Inherits:
-
Object
- Object
- Sashite::Feen::Position
- Defined in:
- lib/sashite/feen/position.rb
Overview
Immutable representation of a complete board game position.
Combines piece placement, pieces in hand, and style-turn information into a single unified position object. This represents a complete snapshot of the game state at a given moment.
Instance Attribute Summary collapse
-
#hands ⇒ Hands
readonly
Pieces held in hand by each player.
-
#placement ⇒ Placement
readonly
Board piece placement configuration.
-
#styles ⇒ Styles
readonly
Game styles and active player indicator.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare two positions for equality.
-
#hash ⇒ Integer
Generate hash code for position.
-
#initialize(placement, hands, styles) ⇒ Position
constructor
Create a new immutable Position object.
-
#to_s ⇒ String
Convert position to its canonical FEEN string representation.
Constructor Details
#initialize(placement, hands, styles) ⇒ Position
Create a new immutable Position object.
33 34 35 36 37 38 39 |
# File 'lib/sashite/feen/position.rb', line 33 def initialize(placement, hands, styles) @placement = placement @hands = hands @styles = styles freeze end |
Instance Attribute Details
#hands ⇒ Hands (readonly)
Returns Pieces held in hand by each player.
17 18 19 |
# File 'lib/sashite/feen/position.rb', line 17 def hands @hands end |
#placement ⇒ Placement (readonly)
Returns Board piece placement configuration.
14 15 16 |
# File 'lib/sashite/feen/position.rb', line 14 def placement @placement end |
#styles ⇒ Styles (readonly)
Returns Game styles and active player indicator.
20 21 22 |
# File 'lib/sashite/feen/position.rb', line 20 def styles @styles end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare two positions for equality.
60 61 62 63 64 65 |
# File 'lib/sashite/feen/position.rb', line 60 def ==(other) other.is_a?(Position) && placement == other.placement && hands == other.hands && styles == other.styles end |
#hash ⇒ Integer
Generate hash code for position.
72 73 74 |
# File 'lib/sashite/feen/position.rb', line 72 def hash [placement, hands, styles].hash end |
#to_s ⇒ String
Convert position to its canonical FEEN string representation.
Generates a deterministic FEEN string. The same position will always produce the same canonical string, enabling position equality via string comparison.
52 53 54 |
# File 'lib/sashite/feen/position.rb', line 52 def to_s Dumper.dump(self) end |