Merge pull request 'MCGS: stop a playout at a child that is ahead of its edge' (#24) from mcgs-v-stop into main

A playout stops at a child that has more visits than its edge and backs up the child's Q (MCGS variant 5a).

SPRT: https://bench.rektdie.com/test/5316/

Elo   | 12.35 +- 6.40 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.31 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4898 W: 1609 L: 1435 D: 1854
Penta | [91, 544, 1073, 582, 159]

Bench: 609350
This commit was merged in pull request #24.
This commit is contained in:
claude committed 2026-11-16 23:19:45 +01:00
commit 150a876b2a
1 file changed
+12 -5
+12 -5
View File
@@ -650,7 +650,7 @@ void Searcher::playout() {
edge_path_.clear(); edge_path_.clear();
// How the playout ended; it decides what happens to the last node. // 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(); u32 idx = tree_.root();
path_.push_back(idx); path_.push_back(idx);
int depth = 0; int depth = 0;
@@ -712,17 +712,24 @@ void Searcher::playout() {
} }
idx = edge.child; idx = edge.child;
path_.push_back(idx); 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; value = -tree_.node(idx).q;
leaf = DEPTH_LIMIT; leaf = STOPPED;
break; break;
} }
} }
// The last node. A new node already has its one visit (N = base = 1); a // 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 // 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 // of their own value (q = u stays). A path draw has no node, and a node
// the depth limit is left as it is: only the edge into it counts the visit. // where the playout stopped is left as it is: only the edge into it counts
// the visit.
if (leaf == TERMINAL || leaf == NOT_EXPANDED) { if (leaf == TERMINAL || leaf == NOT_EXPANDED) {
Node& node = tree_.node(path_.back()); Node& node = tree_.node(path_.back());
node.visits++; node.visits++;