Module: Feen::Dumper::PiecePlacement

Defined in:
lib/feen/dumper/piece_placement.rb

Overview

Handles conversion of piece placement data to FEEN notation string

Constant Summary collapse

ERRORS =

Error messages

{
  invalid_type:       "Piece placement must be an Array, got %s",
  inconsistent_shape: "Inconsistent dimension structure detected",
  invalid_cell:       "Invalid cell content: %s (must be String)"
}.freeze

Class Method Summary collapse

Class Method Details

.dump(piece_placement) ⇒ String

Converts a piece placement structure to a FEEN-compliant string

Examples:

2D chess board

PiecePlacement.dump([
  ["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"]
])
# => "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"

3D board

PiecePlacement.dump([
  [["r", "n"], ["p", "p"]],
  [["", ""], ["P", "P"]],
  [["R", "N"], ["", ""]]
])
# => "rn/pp//2/PP//RN/2"

Parameters:

  • piece_placement (Array)

    Hierarchical array representing the board where:

    • Empty squares are represented by empty strings (“”)

    • Pieces are represented by strings (e.g., “r”, “R”, “+P”, “K’”)

    • Dimensions are represented by nested arrays

Returns:

  • (String)

    FEEN piece placement string

Raises:

  • (ArgumentError)

    If the piece placement structure is invalid



43
44
45
46
# File 'lib/feen/dumper/piece_placement.rb', line 43

def self.dump(piece_placement)
  validate_input(piece_placement)
  format_placement(piece_placement)
end