← board

Flagship demo — chess engine (real-world app + cross-target oracle + benchmark)

Purpose — three jobs in one program

  1. Flagship demo. A real application, not a test: recognizable, non-toy, real algorithms (search / eval / hashing). Shows the language does serious work.
  2. Feature-coverage torture test. Intentionally exercises as much of the language surface as practical (matrix below). When the demo compiles and perft matches known constants, a huge slice of the compiler is validated at once.
  3. Cross-target oracle + benchmark. Same source on all 5 targets (x86-64 / i386 / aarch64 / arm32 / riscv32 / xtensa). Two deterministic outputs:
    • Correctness: perft(N) leaf-node counts are exact known integers → byte-identical across every target via the existing output-equality harness. Any codegen bug in move-gen / recursion / Int64 shifts the count.
    • Performance: same code → measure nodes/sec, and (where the target exposes a cycle counter) cycles per node. Lets us compare codegen quality per target / per clock tick. A real cross-ISA benchmark from one source.

Why chess specifically

Feature-coverage matrix (criteria 2)

Language feature Where exercised
static arrays mailbox board array[0..63] of TPiece
dynamic arrays move lists, PV line
records TMove (from/to/flags), TUndo, TPair in TT
enums piece kind, color, castling-right, square
sets castling rights, square / attack masks
recursion alpha-beta / negamax search
Int64 / UInt64 bitboards + Zobrist 64-bit hash — stresses 64-bit math on the 32-bit targets (i386 / arm32 / riscv32 / xtensa); see [[project_i386_int64_codegen]] equivalents
generators (yield) move generation as generator of TMove
for x in for m in GenMoves(pos) do — directly consumes feature-for-in-iteration
procedural types eval-term function table / search-callback
short-circuit and/or legality + bounds guards ([[project_shortcircuit_landed]])
managed strings + parsing UCI protocol over stdin/UART; FEN parse/emit
collections / hashing transposition table (open-addressed, Zobrist keyed)
classes / VMT (optional) engine vs board object split
exceptions (optional) illegal-input / abort-search path

It consumes the for-in + generator arcs: demo and feature work reinforce each other rather than duplicating effort.

Known gaps + how to close them

Chess alone skips floats and networking / GUI. Deliberate — keep the oracle path integer-deterministic. Optional closers:

ESP32 fit (criteria 3)

Benchmark methodology (criteria: perf comparison)

Slices

  1. Board + movegen + perft (mailbox). No search, no eval. Lands the oracle: perft(1..6) matches published constants on x86-64, then cross-bootstrap. Movegen written as a generator + driven by for m in.
  2. Search + eval. Negamax + alpha-beta, integer material/PST eval. Fixed FEN / fixed depth reproducible best-move output.
  3. Transposition table + Zobrist. 64-bit hashing → Int64 stress; TT as a collection. Re-validate perft (hash must not change counts).
  4. UCI + FEN I/O. String parse/emit, interactive surface.
  5. Benchmark harness. nodes/sec + cycles/node per target, integer output, wired into the cross harness.
  6. (optional) bitboard variant / --float-eval — extra 64-bit + float coverage.

Acceptance

Alternative demos

Chess is the chosen flagship. The ranked catalog of other demo/test-app candidates — selection criteria, hard filters, and why each alternative was kept or rejected — lives in its own ticket: idea-demo-app-candidates.

Log