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)

Parameters:

  • active (Object)

    SIN identifier for active player’s style

  • inactive (Object)

    SIN identifier for inactive player’s style



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)

Returns Style identifier of the active player (to move).

Returns:

  • (Object)

    Style identifier of the active player (to move)



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

def active
  @active
end

#inactiveObject (readonly)

Returns Style identifier of the inactive player (waiting).

Returns:

  • (Object)

    Style identifier of the inactive player (waiting)



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.

Parameters:

  • other (Styles)

    Another styles object

Returns:

  • (Boolean)

    True if active and inactive styles are equal



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.

Returns:

  • (Integer)

    Hash code based on active and inactive 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"

Returns:

  • (String)

    FEEN style-turn field



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

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