Class: Sashite::Feen::Styles

Inherits:
Object
  • Object
show all
Defined in:
lib/sashite/feen/styles.rb

Overview

Immutable representation of game styles and active player.

Stores the style identifiers (SIN) for both players, with the active player’s style indicating whose turn it is to move. The case of each style identifier indicates which player uses it (uppercase = first player, lowercase = second player).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active, inactive) ⇒ Styles

Create a new immutable Styles object.

Examples:

Chess game, white to move

styles = Styles.new(sin_C, sin_c)

Chess game, black to move

styles = Styles.new(sin_c, sin_C)

Cross-style game, first player to move

styles = Styles.new(sin_C, sin_m)


34
35
36
37
38
39
# File 'lib/sashite/feen/styles.rb', line 34

def initialize(active, inactive)
  @active = active
  @inactive = inactive

  freeze
end

Instance Attribute Details

#activeObject (readonly)



16
17
18
# File 'lib/sashite/feen/styles.rb', line 16

def active
  @active
end

#inactiveObject (readonly)



19
20
21
# File 'lib/sashite/feen/styles.rb', line 19

def inactive
  @inactive
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compare two styles for equality.



56
57
58
59
60
# File 'lib/sashite/feen/styles.rb', line 56

def ==(other)
  other.is_a?(Styles) &&
    active == other.active &&
    inactive == other.inactive
end

#hashInteger

Generate hash code for styles.



67
68
69
# File 'lib/sashite/feen/styles.rb', line 67

def hash
  [active, inactive].hash
end

#to_sString

Convert styles to their FEEN string representation.

Examples:

styles.to_s
# => "C/c"


48
49
50
# File 'lib/sashite/feen/styles.rb', line 48

def to_s
  Dumper::StyleTurn.dump(self)
end