Module: Sashite::Feen::Dumper::PiecesInHand

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

Overview

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

Converts a Hands object into its FEEN string representation, encoding captured pieces held by each player in canonical sorted order.

Constant Summary collapse

PLAYER_SEPARATOR =

Player separator in pieces-in-hand field.

"/"

Class Method Summary collapse

Class Method Details

.dump(hands) ⇒ String

Dump a Hands object into its FEEN pieces-in-hand string.

Generates canonical representation with pieces sorted according to FEEN ordering rules: by quantity (descending), base letter (ascending), case (uppercase first), prefix (-, +, none), and suffix (none, ‘).

Examples:

No pieces in hand

dump(hands)
# => "/"

First player has pieces

dump(hands)
# => "2P/p"

Both players have pieces

dump(hands)
# => "RBN/2p"

Parameters:

  • hands (Hands)

    The hands object containing pieces for both players

Returns:

  • (String)

    FEEN pieces-in-hand field string



36
37
38
39
40
41
# File 'lib/sashite/feen/dumper/pieces_in_hand.rb', line 36

def self.dump(hands)
  first_player_str = dump_player_pieces(hands.first_player)
  second_player_str = dump_player_pieces(hands.second_player)

  "#{first_player_str}#{PLAYER_SEPARATOR}#{second_player_str}"
end