From 1ddb001e0bc9aedfe0a103ec69752af90dc6b03a Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 16 Nov 2026 23:23:39 +0100 Subject: [PATCH] refactor: rename MCTS to MCGS (src/mcgs.h, src/mcgs.cpp) Rigby searches a graph since PR #23, so the search files, the banner, the Makefile header and the README now say MCGS. The README describes the graph search, reuse, collection and Hash memory as they are now. Internal names (Tree, RIGBY_VERIFY_TREE) are unchanged. No behaviour change: zero warnings, bench identical to main twice. Bench: 608763 Co-Authored-By: Claude Opus 5.5 --- Makefile | 2 +- README.md | 37 ++++++++++++++++++++++--------------- src/{mcts.cpp => mcgs.cpp} | 2 +- src/{mcts.h => mcgs.h} | 2 +- src/pretty.cpp | 2 +- src/uci.cpp | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) rename src/{mcts.cpp => mcgs.cpp} (99%) rename src/{mcts.h => mcgs.h} (99%) diff --git a/Makefile b/Makefile index d257b19..6dbae69 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Rigby - MCTS chess engine +# Rigby - MCGS chess engine # OpenBench calls: make EXE= [EVALFILE=] [CXX=] # POLICYFILE= picks the built-in policy network; POLICYFILE= builds none # (move heuristics). diff --git a/README.md b/README.md index 8285a2e..658edf6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Rigby -Rigby is a UCI chess engine built on Monte Carlo Tree Search (PUCT). The goal is a -neural-network-guided MCTS engine, later a Monte Carlo Graph Search (MCGS), with a -value and policy network trained with [bullet](https://github.com/jw1912/bullet) on +Rigby is a UCI chess engine built on Monte Carlo Graph Search (MCGS) with PUCT +selection. The goal is a neural-network-guided MCGS engine with a value and policy +network trained with [bullet](https://github.com/jw1912/bullet) on data generated by Leela Chess Zero, and CUDA inference. Every change is validated with SPRT on OpenBench. @@ -14,8 +14,14 @@ Every change is validated with SPRT on OpenBench. - Chess960: any castling rook placement, X-FEN and Shredder-FEN castling rights, `UCI_Chess960` for king-takes-rook castling notation. Verified with the 960 positions of the standard Chess960 perft suite to depth 5 (`perftfile`). -- PUCT search: node arena with contiguous children, first-play urgency reduction, - two-fold repetition, 50-move and insufficient-material draws inside the tree. +- Monte Carlo Graph Search: a position reached by different move orders is one + node, found through a key table. Edges carry their own visits, so a node's Q + is the visit-weighted mix of its children. PUCT selection with first-play + urgency reduction. A playout stops at a child that already has more visits + than the edge leading to it and backs up that child's Q. +- Repetition and 50-move draws depend on the path, so they are counted only on + the edges of the current path, never stored in nodes. Insufficient-material + draws are terminal nodes. - Value: a `(768 -> 128)x2 -> 1` network trained with bullet on Lc0 data (`networks/rigby-value-v1.bin`, embedded at build time; see `train/README.md`), behind a capture-only quiescence search. @@ -23,11 +29,11 @@ Every change is validated with SPRT on OpenBench. (`networks/rigby-policy-v1.bin`, embedded at build time; see `train/README.md`). Built without one (`POLICYFILE=`), move heuristics (captures, promotions, checks, pawn threats). -- 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. -- When the arena is full, the least visited parts of the tree are cut back to - leaves (keeping their visits and Q) and the rest is packed, so search never - stops expanding. +- Graph reuse between moves: only the root moves to the new position. The next + collection keeps what the root reaches. +- When the node or edge arena is full, the least visited parts of the graph are + cut back to leaves (keeping their visits and Q), the rest is packed in place + and the key table is rebuilt, so search never stops expanding. - Single-threaded. ## Building @@ -44,9 +50,10 @@ make EVALFILE=path/to/quantised.bin `EVALFILE` defaults to `networks/rigby-value-v1.bin`. `POLICYFILE` defaults to `networks/rigby-policy-v1.bin`; `POLICYFILE=` builds the move heuristics instead. -Compiling with `-DRIGBY_VERIFY_TREE` checks the whole tree before and after every -reuse and after every collection (legal moves, visit counts) and aborts on the first -inconsistency. It is slow, for debugging only. +Compiling with `-DRIGBY_VERIFY_TREE` checks the whole graph before and after every +reuse and after every collection (legal moves, visit counts, keys and the key table) +and aborts on the first inconsistency. Such a build also has a `verify` command that +runs these checks on test positions. It is slow, for debugging only. ## UCI @@ -84,7 +91,7 @@ terminal). | Option | Default | Meaning | | --- | --- | --- | -| Hash | 64 | Tree memory in MB. A node takes 20 bytes. | +| Hash | 64 | Graph memory in MB: 32-byte nodes, 16-byte edges and the key table. | | Threads | 1 | Only 1 for now. | | MoveOverhead | 20 | Milliseconds kept back per move. | | CPuct | 160 | Exploration constant x100. | @@ -97,5 +104,5 @@ terminal). ## Bench `Rigby bench` runs 5000 playouts on each of 16 positions. The reported node count is -the number of positions visited in the tree over all playouts, so it changes +the number of positions visited in the graph over all playouts, so it changes whenever search behaviour changes, while the playout count stays fixed. diff --git a/src/mcts.cpp b/src/mcgs.cpp similarity index 99% rename from src/mcts.cpp rename to src/mcgs.cpp index f92b560..68c8b24 100644 --- a/src/mcts.cpp +++ b/src/mcgs.cpp @@ -1,4 +1,4 @@ -#include "mcts.h" +#include "mcgs.h" #include #include diff --git a/src/mcts.h b/src/mcgs.h similarity index 99% rename from src/mcts.h rename to src/mcgs.h index 7cef7c6..adbaa75 100644 --- a/src/mcts.h +++ b/src/mcgs.h @@ -153,7 +153,7 @@ private: void rebuild_table(); }; -// Butterfly history for MCTS (after Vine, aronpetkovski.com/blog/butterfly-history-mcts): +// Butterfly history (after Vine, aronpetkovski.com/blog/butterfly-history-mcts): // every playout scores each move on its path with the playout's result, and // the score is added to the move's policy logit when a node is expanded. class ButterflyHistory { diff --git a/src/pretty.cpp b/src/pretty.cpp index 1cb493f..23ce722 100644 --- a/src/pretty.cpp +++ b/src/pretty.cpp @@ -437,7 +437,7 @@ std::string banner(const std::string& name, const std::string& version, const st Line title; title.add(name, TITLE).add(" " + version, VALUE); Line right; - right.add("MCTS chess engine", LABEL); + right.add("MCGS chess engine", LABEL); box.top(title, right); box.row(Line{}); Line by; diff --git a/src/uci.cpp b/src/uci.cpp index e79bcc8..dc72666 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -11,7 +11,7 @@ #include #include "eval.h" -#include "mcts.h" +#include "mcgs.h" #include "perft.h" #include "policy.h" #include "position.h"