Module: Sashite::Feen::Parser::PiecePlacement Private

Defined in:
lib/sashite/feen/parser/piece_placement.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 Piece Placement field (Field 1).

The Piece Placement field encodes Board occupancy as a stream of tokens organized into segments separated by one or more slash characters.

Within each segment, the content is a concatenation of placement tokens:

  • Empty-count token: a base-10 integer (≥ 1, no leading zeros)

  • Piece token: a valid EPIN token

Examples:

PiecePlacement.parse("8")
# => { segments: [[8]], separators: [] }

PiecePlacement.parse("r2k/8")
# => { segments: [[<r>, 2, <k>], [8]], separators: ["/"] }

PiecePlacement.parse("8/8//8")
# => { segments: [[8], [8], [8]], separators: ["/", "//"] }

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 Piece Placement field string.

Parameters:

  • input (String)

    The Piece Placement field string

Returns:

  • (Hash)

    A hash with :segments and :separators keys

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sashite/feen/parser/piece_placement.rb', line 39

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

  segments = []
  separators = []
  pos = 0

  while pos < input.bytesize
    # Parse a segment
    segment, pos = parse_segment(input, pos)
    segments << segment

    # Parse separator group if present
    if pos < input.bytesize
      separator, pos = parse_separator(input, pos)
      separators << separator
    end
  end

  { segments: segments, separators: separators }
end