Class: Sashite::Feen::Position::StyleTurn

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

Overview

Represents the Style-Turn field (Field 3).

Encapsulates player styles and active player information.

Examples:

st = StyleTurn.new(active: <Sin C>, inactive: <Sin c>)
st.first_to_move?  # => true
st.to_s            # => "C/c"

API:

  • public

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active:, inactive:) ⇒ StyleTurn

Creates a new StyleTurn instance.

Parameters:

  • Active player’s style

  • Inactive player’s style

API:

  • public



29
30
31
32
33
34
# File 'lib/sashite/feen/position/style_turn.rb', line 29

def initialize(active:, inactive:)
  @active_style = active
  @inactive_style = inactive

  freeze
end

Instance Attribute Details

#active_styleSashite::Sin::Identifier (readonly)

Returns Active player’s style.

Returns:

  • Active player’s style

API:

  • public



20
21
22
# File 'lib/sashite/feen/position/style_turn.rb', line 20

def active_style
  @active_style
end

#inactive_styleSashite::Sin::Identifier (readonly)

Returns Inactive player’s style.

Returns:

  • Inactive player’s style

API:

  • public



23
24
25
# File 'lib/sashite/feen/position/style_turn.rb', line 23

def inactive_style
  @inactive_style
end

Instance Method Details

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

Checks equality with another StyleTurn.

Parameters:

  • The object to compare

Returns:

  • true if equal

API:

  • public



61
62
63
64
65
# File 'lib/sashite/feen/position/style_turn.rb', line 61

def ==(other)
  return false unless self.class === other

  active_style == other.active_style && inactive_style == other.inactive_style
end

#first_to_move?Boolean

Returns true if first player is to move.

Returns:

API:

  • public



39
40
41
# File 'lib/sashite/feen/position/style_turn.rb', line 39

def first_to_move?
  active_style.side == :first
end

#hashInteger

Returns a hash code.

Returns:

  • Hash code

API:

  • public



72
73
74
# File 'lib/sashite/feen/position/style_turn.rb', line 72

def hash
  [active_style, inactive_style].hash
end

#second_to_move?Boolean

Returns true if second player is to move.

Returns:

API:

  • public



46
47
48
# File 'lib/sashite/feen/position/style_turn.rb', line 46

def second_to_move?
  active_style.side == :second
end

#to_sString

Returns the canonical string representation.

Returns:

  • The style-turn string

API:

  • public



53
54
55
# File 'lib/sashite/feen/position/style_turn.rb', line 53

def to_s
  "#{active_style}#{Constants::SEGMENT_SEPARATOR}#{inactive_style}"
end