feat: reuse the search tree between moves

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>
This commit is contained in:
rektdieandclaude committed 2026-11-15 01:23:42 +01:00
1 parent d3044c0b88
commit 5c017ee43f
4 files changed
+175 -3

No files matched your search

+7 -1
View File
@@ -16,7 +16,9 @@ Every change is validated with SPRT on OpenBench.
- Placeholder evaluation until the network exists: a small hand-written
evaluation behind a capture-only quiescence search for the value, and move
heuristics (captures, promotions, checks, pawn threats) for the policy.
- Single-threaded, no tree reuse between moves.
- Tree reuse between moves: the subtree of the new position is packed to the
front of the node arena in place, so it costs no extra memory.
- Single-threaded.
## Building
@@ -28,6 +30,10 @@ make
make EXE=Rigby-dev
```
Compiling with `-DRIGBY_VERIFY_TREE` checks the whole tree before and after every
reuse (legal moves, visit counts) and aborts on the first inconsistency. It is slow,
for debugging only.
## UCI
Standard commands: `uci`, `isready`, `ucinewgame`, `position`, `go`