Commit Graph
5 Commits
Author SHA1 Message Date
rektdieandclaude 6de6fba82a feat: expand nodes on their second visit
Most leaves are visited only once. Their first visit now only settles
terminal states and evaluates the position; the move list, the priors and
the child nodes are created when search comes back a second time. The
root is expanded before the first playout, so a search always has a move.

In a 2 s search of a middlegame position with 1 GB Hash this needs about
35% less tree memory per playout and gives about 7% more playouts per
second than tree reuse alone. The -DRIGBY_VERIFY_TREE build passed 2600+
tree checks in UCI-driven self-play with 1 MB and 16 MB Hash, and a
1-playout search still returns a move.

Bench: 546108

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:29:07 +01:00
rektdieandclaude 3dc4e6c136 feat: collect the tree when the node arena is full
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>
2026-11-15 03:19:28 +01:00
claude 241ad4a546 Merge pull request 'Reuse the search tree between moves' (#1) from tree-reuse into main
Merge pull request 'Reuse the search tree between moves' (#1) from tree-reuse into main

SPRT https://bench.rektdie.com/test/5282/
Elo   | 162.54 +- 22.80 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.13 (-2.94, 2.94) [0.00, 5.00]
Games | N: 472 W: 238 L: 32 D: 202

Bench: 546127
2026-11-15 03:15:32 +01:00
rektdieandclaude 5c017ee43f 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>
2026-11-15 01:23:42 +01:00
rektdieandclaude d3044c0b88 feat: minimal MCTS engine with UCI
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>
2026-11-15 00:31:20 +01:00