Module: Sashite::Feen::Parser::Hands Private

Defined in:
lib/sashite/feen/parser/hands.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parser for FEEN Hands field (Field 2).

The Hands field encodes off-board pieces held by each player:

<FIRST-HAND>/<SECOND-HAND>

Each hand is a concatenation of hand items with no separators:

[<count>]<piece>

Where:

  • <piece> is a valid EPIN token

  • <count> is an optional multiplicity (≥ 2 if present, absent = 1)

Hand items MUST be in canonical order:

  1. By multiplicity — descending (larger counts first)

  2. By base letter — case-insensitive alphabetical order

  3. By letter case — uppercase before lowercase

  4. By state modifier — - before ‘+` before none

  5. By terminal marker — absent before present

  6. By derivation marker — absent before present

Examples:

Hands.parse("/")
# => { first: [], second: [] }

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

See Also:

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a FEEN Hands field string.

Parameters:

  • input (String)

    The Hands field string

Returns:

  • (Hash)

    A hash with :first and :second keys, each containing an array of hand items

Raises:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sashite/feen/parser/hands.rb', line 50

def self.parse(input)
  validate_delimiter!(input)

  first_str, second_str = input.split(Constants::SEGMENT_SEPARATOR, -1)

  first_items = parse_hand(first_str)
  second_items = parse_hand(second_str)

  validate_canonical_order!(first_items)
  validate_canonical_order!(second_items)

  {
    first:  first_items,
    second: second_items
  }
end