Module: Sashite::Feen::Dumper::PiecePlacement

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

Overview

Dumper for the piece placement field (first field of FEEN).

Converts a Placement object into its FEEN string representation, encoding board configuration using EPIN notation with:

  • Empty square compression (consecutive nils → numbers)

  • Exact separator preservation (from Placement.separators)

  • Support for any irregular board structure

The dumper produces canonical FEEN strings that enable perfect round-trip conversion (dump → parse → dump).

Class Method Summary collapse

Class Method Details

.dump(placement) ⇒ String

Dump a Placement object into its FEEN piece placement string.

Process:

  1. For 1D boards: dump single rank directly

  2. For multi-D boards: interleave ranks with their separators

  3. Compress consecutive empty squares into numbers

  4. Convert pieces to EPIN strings

Examples:

Chess starting position

dump(placement)
# => "+rnbq+kbn+r/+p+p+p+p+p+p+p+p/8/8/8/8/+P+P+P+P+P+P+P+P/+RNBQ+KBN+R"

Empty 8x8 board

dump(placement)
# => "8/8/8/8/8/8/8/8"

1D board

dump(placement)
# => "K2P3k"

Irregular 3D board

dump(placement)
# => "5/5//5/5/5"

Very large board

dump(placement)
# => "100/100/100"

Parameters:

  • placement (Placement)

    The board placement object

Returns:

  • (String)

    FEEN piece placement field string



49
50
51
52
53
54
55
# File 'lib/sashite/feen/dumper/piece_placement.rb', line 49

def self.dump(placement)
  # Special case: 1D board (no separators)
  return dump_rank(placement.ranks[0]) if placement.one_dimensional?

  # Multi-dimensional: interleave ranks and separators
  dump_multi_dimensional(placement)
end