eng_LeavesInCheck is exact: whole-book identity, perft, fuzz and constructed
pin/ep/double-check cases all match the full attack walk. The slim unaligned
early-out form saves about 2.3% on the fixed C64 middlegame but still overflows
Atari MAIN by 149 bytes; a dedicated vacated-ray scan overflows by 661.
Default ENGINE_FAST_LEGAL off so shipping maps stay at Phase B. The native
suite forces the switch on so the candidate cannot go stale.
The last known absence with a price attached: 62% of self-play games
drawn, all by repetition, 57% of those in positions the engine itself
scored as winning.
A 16-bit key carried by eng_Make and eng_Unmake, built as a sibling of
eval_MoveDelta - same cases, same rule that a delta reads no board
state, so the pair cannot disagree. History is a 128-entry ring pushed
by make and popped by unmake, which holds the real game and the current
search line in one array; undo, redo and the UCI replay maintain it for
free. Castling rights are folded in when a position is compared,
because a king that steps off e1 and back leaves the same pieces on the
same squares and is not the same position. negamax scores one repeat
as a draw; board_ApplyMove applies the threefold.
+44 Elo at equal nodes, +38 at equal time, 512 games, 3.7 sigma.
Self-play draws 53% to 32%. Costs 9% on a real C64 - the host said
5.5%, which would have credited the change with points it had not
earned. RODATA +1584, CODE +1038, BSS +260.
The match harness had been counting threefold draws as games that ran
out the ply limit, so it could not see its own headline result.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The old engine was weak for one structural reason. cpu_ScorePieceSubTree
looked like minimax but had a branching factor of one: at each level it
followed only the single reply a static heuristic ranked first, so it
evaluated one predicted line per root move and never saw a refutation the
heuristic missed. Two things compounded it - the root considered only one
move per piece, and the scoring functions returned move desirability rather
than position value, which is not a quantity minimax can validly accumulate
across plies.
What replaces it:
engine.c 0x88 board, make/unmake against a per-ply state stack, legal
move generation, and attack queries by ray-cast. The stored
attack database is gone - eng_IsAttacked walks outwards from a
square instead of rebuilding 64 squares' worth of state after
every trial move.
eval.c material and piece-square tables as a pure position value,
kept as a running total updated incrementally by make/unmake.
search.c iterative-deepening negamax with alpha-beta, MVV-LVA and killer
ordering, and a quiescence search over captures.
board.c becomes the adapter between engine and display; plat.h and the 0-63
tile numbering are untouched, so no platform file needed editing - including
the three that cannot be built here.
Verified: perft exact on all five reference positions to depth 5, and to
depth 6 on the two that publish one. Against the engine it replaces, at that
engine's strongest setting: 6 wins, 0 losses.
Smaller than what it replaces despite doing far more - 31129 bytes total on
the c64 at optspeed against 31543 for the two engines' worth of machinery it
supersedes, and 514 bytes less RAM. All five buildable targets fit.
tests/ carries the harness this was developed against: perft, a game fuzzer,
castling scenarios, an internal match runner, on-target C64 benchmarks, and
a UCI adapter for playing external engines. It stops being gitignored here -
the exclusion was scaffolding added during the rework to keep git status
quiet, and the harness is the evidence for everything above.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>