Module: Sashite::Feen::Parser::PiecesInHand

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

Overview

Parser for the pieces-in-hand field (second field of FEEN).

Converts a FEEN pieces-in-hand string into a Hands object, decoding captured pieces held by each player with optional count prefixes.

Constant Summary collapse

PLAYER_SEPARATOR =

Player separator in pieces-in-hand field.

"/"
EPIN_PATTERN =

Pattern to match EPIN pieces (optional state prefix, letter, optional derivation suffix).

/\A[-+]?[A-Za-z]'?\z/

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Hands

Parse a FEEN pieces-in-hand string into a Hands object.

Examples:

No pieces in hand

parse("/")  # => Hands.new([], [])

First player has pieces

parse("2P/p")  # => Hands.new([P, P], [p])

Both players have pieces

parse("RBN/2p")  # => Hands.new([R, B, N], [p, p])

Parameters:

  • string (String)

    FEEN pieces-in-hand field string

Returns:

  • (Hands)

    Parsed hands object

Raises:



41
42
43
44
45
46
47
48
# File 'lib/sashite/feen/parser/pieces_in_hand.rb', line 41

def self.parse(string)
  first_str, second_str = split_players(string)

  first_player_pieces = parse_player_pieces(first_str)
  second_player_pieces = parse_player_pieces(second_str)

  Hands.new(first_player_pieces, second_player_pieces)
end