Author SHA1 Message Date
rektdieandclaude 59d5af56f3 mcts: stop a playout at a child that is ahead of its edge (MCGS variant 5a)
With always-descend, a playout runs through existing nodes until it reaches
a new position or a draw of its path. In reversible endgames it wanders
through cycles: mean playout depth 28 against main's 6 in KR v K (bench
15), at 0.15x main's playouts/s, with 30 % of playouts ending in a
repetition.

KataGo's stop rule: when the child an edge leads to already has more
visits than the edge (other move orders reached it), the playout ends
there. The edge counts the visit and its parent recomputes from the
child's current Q; the child is left as it is. In a tree the two counts are
equal, so this only fires on transpositions. The depth limit now ends a
playout the same way.

The bench changes because playouts stop at transpositions.

Checked: zero warnings; VERIFY build: `verify` (a)-(d), the VERIFY searches of plan section 6 with 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: 609350

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:36:01 +01:00
+12 -5
View File
@@ -650,7 +650,7 @@ void Searcher::playout() {
edge_path_.clear();
// How the playout ended; it decides what happens to the last node.
enum Leaf { NEW_NODE, TERMINAL, NOT_EXPANDED, PATH_DRAW, DEPTH_LIMIT } leaf;
enum Leaf { NEW_NODE, TERMINAL, NOT_EXPANDED, PATH_DRAW, STOPPED } leaf;
u32 idx = tree_.root();
path_.push_back(idx);
int depth = 0;
@@ -712,17 +712,24 @@ void Searcher::playout() {
}
idx = edge.child;
path_.push_back(idx);
if (depth >= MAX_PLAYOUT_DEPTH) {
// Stop rule (KataGo, plan variant 5a): a child that already has more
// visits than this edge (other move orders reached it) is ahead of
// what this edge needs. The playout ends there: the edge counts the
// visit with the child's current value, and the child is left as it
// is. In a tree the two counts are equal and this never happens. The
// depth limit ends a playout the same way.
if (tree_.node(idx).visits > edge.visits || depth >= MAX_PLAYOUT_DEPTH) {
value = -tree_.node(idx).q;
leaf = DEPTH_LIMIT;
leaf = STOPPED;
break;
}
}
// The last node. A new node already has its one visit (N = base = 1); a
// terminal node and a node that could not be expanded count one more visit
// of their own value (q = u stays). A path draw has no node, and a node at
// the depth limit is left as it is: only the edge into it counts the visit.
// of their own value (q = u stays). A path draw has no node, and a node
// where the playout stopped is left as it is: only the edge into it counts
// the visit.
if (leaf == TERMINAL || leaf == NOT_EXPANDED) {
Node& node = tree_.node(path_.back());
node.visits++;