Step 3 rerooted by compacting what the new root reaches (plan 3.6.6,
mark/compact with T = 0). In a graph, a reversible endgame keeps almost the
whole graph reachable from the new root, so every move paid O(graph) before
its first playout. Replaying a 2+0.02 game that step 3 lost on time (Hash 16,
rook endgame, half-move clock about 70): the reroot averaged 3.3 ms per move,
max 14.5 ms, against 0.3 ms for main. Under load that is more than the
increment, and step 3 ran out of time in 2 of 100 games.
Now reroot only sets the root. Nodes the new root no longer reaches keep
their memory and their table entries (search may link to them again) until
the next collection, which keeps only what the root reaches. In the same
replay, the time before the first playout is 0 ms on average.
VERIFY: verify_tree requires every node to be reachable only right after a
collection; the table must always hold every node of the arena. Check (b)
now checks that a reroot changes nothing and that the next collection keeps
exactly the nodes the new root reaches, unchanged.
Checked: zero warnings, bench unchanged (bench never reuses a graph),
`verify` (a)-(d), the VERIFY searches of plan section 6 including forced GC
at Hash 1 and 2, the reuse sequence at Hash 64, Hash 1 and from the 960
start, and the go nodes 1/2, go depth 1 smoke positions.
Bench: 764208
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(c) searches five positions with forced or frequent repetitions and
50-move draws (the knight shuffle in the game history, the perpetual-check
bench position, KR v K at half-move 95, and two pawn endgames), checks every
node state from its position alone (verify_tree), and requires the draws to
show up as edge draw counts, the 50-move ones included.
(d) reports the table against the surviving nodes after every forced
collection and reroot of (b); verify_tree checks it in full.
VERIFY builds only. Bench: 764208 (unchanged)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bench: 764208
One node per position, found through a key table, as in docs/mcgs-plan.md
sections 3.1-3.5 and 3.6.5:
- Key table: open addressing with linear probing over 8-byte slots
{key_hi, node}, a power of two of at least twice the node arena. A hit
needs the full 64-bit key and the node's 16-bit check (about 80 bits).
It is rebuilt from the survivors after every collection and reroot.
- create_node: a position's first visit creates and evaluates its node
(checkmate, stalemate, insufficient material except at the root, then
ValueHash, then the net) with N = base = 1, q = u. The root is created
and evaluated through it.
- Descent: after make_move, repetition and the 50-move rule (mate first)
are judged before the lookup and recorded only as the edge's draw count.
An edge is linked on first selection, to an existing node when the
table has one. MAX_PLAYOUT_DEPTH = 512 guards against key collisions.
- Backprop: each path edge counts the visit (and the draw), each path
node recomputes q = (base*u - sum (N-D)*c.q) / N, summed in double.
ValueHash is stored for every path node; butterfly history as before.
A playout whose node allocation fails is dropped and the graph collected.
- Selection, best move, smart pruning, score, PV and dashboard read edges,
with path draws counted as 0. The PV stops after a repeated position.
- The root's edges are checked against its legal moves at search start;
the graph is cleared otherwise.
- GC threshold: visited bitmap and the root counted apart, so the estimate
stays an upper bound on a DAG.
- Hash: node arena, edge arena (8 edges per node, unchanged) and the
table share the graph's budget; the table's power of two is rounded
down or up, whichever leaves more nodes.
- VERIFY: verify_tree checks the graph per plan 3.8 (keys, table, states
from the position alone, edges, N = base + edge visits, q = u on
leaves); check (b) of `verify` identifies nodes by key.
The bench changes (663779 -> 764208) because the tree becomes a graph:
transpositions share nodes, so playouts run through existing nodes and
their depths and the positions they visit change; the root gets its own
evaluation and N = 1 + the edges' visits; and repetitions and the 50-move
rule are judged on every playout instead of once per node.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured over the 16 bench positions at 5 s, Hash 64 (local, single
runs): collections main 200; edges per node 4: 217, 6: 183, 8: 184,
13: 184, 20: 249. 13 cut middlegame collections further but gave 2-3x
more in the endgames; 8 stays close to main everywhere.
Bench: 663779
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(a) Along random games from standard and Chess960 positions (50 games of
up to 300 plies from each of 7 FENs), the incremental key and the position
check equal those of the same position set up from its FEN.
(b) After a 30000-playout search on four positions (standard, middlegame,
pawn endgame, Chess960): three forced collections down to 1/2, 1/4 and 1/8
of the tree, each compared with a snapshot taken by move path (visits, q,
u, base, state, key, check, and every edge). Survivors must be unchanged,
pruned nodes must keep visits and q with u = q and base = visits, both
arenas must end within their targets, and no pruned node may have more
visits than a kept one. Then a reroot two plies down the best line must
keep that subtree exactly. verify_tree runs after each step.
Only compiled with -DRIGBY_VERIFY_TREE. Bench: 663779
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tree now has two arenas. An Edge (16 bytes: child, visits, draws, move,
policy) is written for every legal move at expansion; a Node (32 bytes: key,
first_edge, visits, q, u, base, num_edges, state, check) is created only
when its edge is first selected, and evaluated on that visit.
Search is unchanged: edge visits are kept equal to the child's visits, and
selection, FPU and the root decisions read edge.visits and edge.policy with
the child's q, in the same float order. Path-dependent draws stay in
node.state. key and check are set at node creation, u and base by pruning;
nothing reads them yet, and edge.draws stays 0.
The root index is a member. Garbage collection and rerooting use
mark -> forwarding -> slide -> remap over both arenas, which no longer
assumes that a block is allocated after its parent's. The threshold rule is
the tree-exact one, with a histogram per arena; a pruned node keeps its
visits and q. A playout that finds the node arena full ends at the parent,
like a failed expansion, and schedules a collection.
VERIFY builds check the whole tree after every reroot, collection and
search: in-degree 1, nothing unreachable in either arena, key and check,
the node state recomputed from the position and its path, one edge per
legal move, edge visits equal to the child's, and |q|, |u| <= 1.
info string reused now counts nodes (positions), not child slots.
Bench: 663779
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sha256 4bc384f273d8ce9312bfde78484dce503c8d1b51b43aacc6352646b3c270b3cd.
Run with: perftfile tests/fischer.epd 5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mcgsstats 1000, 5000 and 5000 16, plus an extra no-GC run at Hash 1024
for the edges-per-node growth ratio. Derived bounds, the ValueHash
cross-check (leaf_tt 54-66 % overall, inside 37-85 %) and the arena
split input for step 2. Stats-build numbers, local machine.
Bench: 663779
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Book and adjudication from tests 5307-5309 (UHO_Lichess_4852_v1.epd),
LTC 40.0+0.40 at Hash 256 since Rigby has no LTC preset yet, the stats
branch is never merged, and the Chess960 perft suite (found in an old
session scratchpad, passes depth 5 on main) gets committed by step 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Research on graph search (KataGo, Czech et al., Lc0 dag_classic, Ceres,
Monty, GHI literature) and the design for turning Rigby's MCTS into
Monte-Carlo Graph Search: 16-byte edges with per-edge draw counts,
32-byte nodes keyed by the full Zobrist key plus a 16-bit check,
idempotent backprop, path-dependent draws decided during descent, and
mark-and-slide compaction for two arenas. Ordered steps with gates and
SPRT recommendations. Empty mcgs-log.md for per-branch results.
No code change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>