mcts: reroot moves only the root index (no compaction between moves)
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>
This commit is contained in:
1 parent
f4b79a472c
commit
d38f0b133a
2 files changed
+46
-22
No files matched your search
+7
-5
@@ -94,9 +94,9 @@ public:
|
||||
u32 find(u64 key, u16 check) const;
|
||||
// Enters a node, which must not be in the table yet, by its key.
|
||||
void insert(u32 idx);
|
||||
// Makes `new_root` the root and packs what is reachable from it to the
|
||||
// front of the arenas; everything else is dropped. Returns the number of
|
||||
// nodes kept.
|
||||
// Makes `new_root` the root. Nothing is moved or dropped: what the new
|
||||
// root no longer reaches goes at the next collection. Returns the number
|
||||
// of nodes in the graph.
|
||||
size_t reroot(u32 new_root);
|
||||
// Frees memory when an arena is full: the least visited parts of the graph
|
||||
// are cut back to leaves until at most `keep_fraction` of each arena is in
|
||||
@@ -337,7 +337,8 @@ private:
|
||||
void recompute_q(Node& node) const;
|
||||
bool is_repetition(const Position& pos) const;
|
||||
// Finds the node for `root` in the previous graph and makes it the root.
|
||||
// Returns the number of nodes kept, 0 when nothing could be reused.
|
||||
// Returns the number of nodes in the graph (some may no longer be
|
||||
// reachable), 0 when nothing could be reused.
|
||||
size_t reuse_tree(const Position& root);
|
||||
// True when the root node's edges are exactly the legal moves of `root`.
|
||||
bool root_edges_valid(const Position& root) const;
|
||||
@@ -345,7 +346,8 @@ private:
|
||||
void clear_tree(const Position& root);
|
||||
#ifdef RIGBY_VERIFY_TREE
|
||||
// Checks the graph from root_pos_; `history` ends with the root's key.
|
||||
void verify_tree(const std::vector<u64>& history) const;
|
||||
// `collected`: right after a collection, when every node must be reachable.
|
||||
void verify_tree(const std::vector<u64>& history, bool collected = false) const;
|
||||
#endif
|
||||
|
||||
void compute_time_limit(const SearchLimits& limits);
|
||||
|
||||
Reference in new issue
Block a user