Module: Feen::Dumper

Defined in:
lib/feen/dumper.rb,
lib/feen/dumper/style_turn.rb,
lib/feen/dumper/pieces_in_hand.rb,
lib/feen/dumper/piece_placement.rb

Overview

Module responsible for converting internal data structures to FEEN notation strings. This implements the serialization part of the FEEN (Forsyth–Edwards Enhanced Notation) format.

Defined Under Namespace

Modules: PiecePlacement, PiecesInHand, StyleTurn

Constant Summary collapse

FIELD_SEPARATOR =

Field separator used between the three main components of FEEN notation

" "
ERRORS =

Error messages for validation

{
  invalid_piece_placement_type: "Piece placement must be an Array, got %s",
  invalid_style_turn_type:      "Style turn must be an Array with exactly two elements, got %s",
  invalid_pieces_in_hand_type:  "Pieces in hand must be an Array, got %s"
}.freeze

Class Method Summary collapse

Class Method Details

.dump(piece_placement:, pieces_in_hand:, style_turn:) ⇒ String

Converts position components to a complete FEEN string.

Examples:

Creating a FEEN string for chess initial position

Feen::Dumper.dump(
  piece_placement: [
    ["r", "n", "b", "q", "k", "b", "n", "r"],
    ["p", "p", "p", "p", "p", "p", "p", "p"],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["", "", "", "", "", "", "", ""],
    ["P", "P", "P", "P", "P", "P", "P", "P"],
    ["R", "N", "B", "Q", "K", "B", "N", "R"]
  ],
  pieces_in_hand: [],
  style_turn: ["CHESS", "chess"]
)
# => "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR / CHESS/chess"

Parameters:

  • piece_placement (Array)

    Board position data structure representing the spatial distribution of pieces across the board, where each cell is represented by a String (or empty string for empty cells)

  • pieces_in_hand (Array<String>)

    Pieces available for dropping onto the board. May include PNN modifiers (per FEEN v1.0.0 specification)

  • style_turn (Array<String>)

    A two-element array where the first element is the active player’s style and the second is the inactive player’s style

Returns:

  • (String)

    Complete FEEN string representation compliant with the specification

Raises:

  • (ArgumentError)

    If any input parameter is invalid

See Also:



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/feen/dumper.rb', line 50

def self.dump(piece_placement:, pieces_in_hand:, style_turn:)
  # Validate input types
  validate_inputs(piece_placement, style_turn, pieces_in_hand)

  # Process each component with appropriate submodule and combine into final FEEN string
  [
    PiecePlacement.dump(piece_placement),
    PiecesInHand.dump(*pieces_in_hand),
    StyleTurn.dump(*style_turn)
  ].join(FIELD_SEPARATOR)
end