With tree reuse the arena fills up quickly: at 8+0.08 with Hash=64 it
was full on 19 of 30 moves of a self-play game. A full tree could not
expand anything any more, it only re-evaluated leaves.
Now a failed allocation triggers a collection after the playout. The
children of every node below a visit threshold are dropped (the node
keeps its visits and Q and becomes a leaf again), and the rest is packed
in place with the same block compaction as tree reuse. The threshold is
the smallest one that brings the tree down to half the arena; visits only
shrink going down, so one pass over the tree gives the size kept for
every threshold.
A collection of a full 64 MB tree (3.3M nodes) takes about 21 ms and
keeps about 40%. The -DRIGBY_VERIFY_TREE build checks the tree after
every collection: 3200+ checks in self-play with 1 MB and 16 MB Hash,
no inconsistency.
Bench: 546127
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the new position continues the previous game, find its node in the
old tree (matching the keys of the positions played since) and make it
the root. Its subtree is packed to the front of the arena in place: child
blocks are always allocated after their parent's, so moving the kept
blocks in their original order only moves them towards the front.
A root that was a draw inside the old tree (repetition, 50 moves) or was
never expanded starts afresh. ucinewgame and Hash changes drop the tree.
Built with -DRIGBY_VERIFY_TREE, the engine checks every tree before and
after reuse (legal moves, visit counts); 2900+ such checks over self-play
games, with 16 MB and 1 MB hash, found no inconsistency.
Bench: 546127
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bitboard board with fancy magics and fully legal move generation, checked
by a perft suite. PUCT search over a node arena with FPU reduction and
in-tree draw detection. Hand-written value (eval + quiescence) and
heuristic policy stand in until the network is trained. UCI loop with a
search thread, OpenBench-compatible bench and Makefile.
Bench: 546127
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>