Class: Sashite::Feen::Position::Hands

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

Overview

Represents the Hands field (Field 2).

Encapsulates off-board pieces held by each player.

Examples:

hands = Hands.new(
  first: [{ piece: <Epin P>, count: 2 }],
  second: [{ piece: <Epin p>, count: 1 }]
)
hands.to_s  # => "2P/p"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first:, second:) ⇒ Hands

Creates a new Hands instance.

Parameters:

  • first (Array<Hash>)

    First player’s hand items

  • second (Array<Hash>)

    Second player’s hand items



31
32
33
34
35
36
# File 'lib/sashite/feen/position/hands.rb', line 31

def initialize(first:, second:)
  @first = Hand.new(first)
  @second = Hand.new(second)

  freeze
end

Instance Attribute Details

#firstHand (readonly)

Returns First player’s hand.

Returns:

  • (Hand)

    First player’s hand



22
23
24
# File 'lib/sashite/feen/position/hands.rb', line 22

def first
  @first
end

#secondHand (readonly)

Returns Second player’s hand.

Returns:

  • (Hand)

    Second player’s hand



25
26
27
# File 'lib/sashite/feen/position/hands.rb', line 25

def second
  @second
end

Instance Method Details

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

Checks equality with another Hands.

Parameters:

  • other (Object)

    The object to compare

Returns:

  • (Boolean)

    true if equal



49
50
51
52
53
# File 'lib/sashite/feen/position/hands.rb', line 49

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

  first == other.first && second == other.second
end

#hashInteger

Returns a hash code.

Returns:

  • (Integer)

    Hash code



60
61
62
# File 'lib/sashite/feen/position/hands.rb', line 60

def hash
  [first, second].hash
end

#to_sString

Returns the canonical string representation.

Returns:

  • (String)

    The hands string



41
42
43
# File 'lib/sashite/feen/position/hands.rb', line 41

def to_s
  "#{first}#{Constants::SEGMENT_SEPARATOR}#{second}"
end