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

+1
View File
@@ -209,6 +209,7 @@ void uci_loop() {
send("readyok");
} else if (cmd == "ucinewgame") {
e.stop();
e.searcher.new_game();
e.pos.set_fen(START_FEN);
e.history = {e.pos.key};
} else if (cmd == "position") {