Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a9bb4072c |
No files matched your search
+3
-22
@@ -592,27 +592,9 @@ bool Searcher::expand(u32 idx, const Position& pos) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Searcher::select_edge(u32 idx, const Position& pos) const {
|
u32 Searcher::select_edge(u32 idx) const {
|
||||||
const Node& node = tree_.node(idx);
|
const Node& node = tree_.node(idx);
|
||||||
|
|
||||||
// Repetitions of this path: a child whose position already occurred on
|
|
||||||
// this playout's path or in the game, with the same side to move and
|
|
||||||
// within the reversible window, would be a draw if chosen now, whatever
|
|
||||||
// its Q says about other paths. Such an edge scores Q = 0. The window
|
|
||||||
// keys are those history_ holds 3, 5, ... plies before `pos` (4, 6, ...
|
|
||||||
// before the child), up to pos.halfmove. A 64-bit filter skips the exact
|
|
||||||
// search for most children.
|
|
||||||
const int n_hist = int(history_.size());
|
|
||||||
const int max_back = std::min(pos.halfmove, n_hist - 1);
|
|
||||||
u64 window_filter = 0;
|
|
||||||
for (int back = 3; back <= max_back; back += 2) window_filter |= 1ULL << (history_[n_hist - 1 - back] & 63);
|
|
||||||
const auto repeats = [&](u64 key) {
|
|
||||||
if (!(window_filter & (1ULL << (key & 63)))) return false;
|
|
||||||
for (int back = 3; back <= max_back; back += 2)
|
|
||||||
if (history_[n_hist - 1 - back] == key) return true;
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// node.q is from the view of the side that moved into this node, so the side
|
// node.q is from the view of the side that moved into this node, so the side
|
||||||
// to move here sees -q. Visits are N(n), the node's own evaluation included.
|
// to move here sees -q. Visits are N(n), the node's own evaluation included.
|
||||||
const float parent_q = node.visits ? -node.q : 0.0f;
|
const float parent_q = node.visits ? -node.q : 0.0f;
|
||||||
@@ -638,8 +620,7 @@ u32 Searcher::select_edge(u32 idx, const Position& pos) const {
|
|||||||
const u32 c = node.first_edge + i;
|
const u32 c = node.first_edge + i;
|
||||||
const Edge& e = tree_.edge(c);
|
const Edge& e = tree_.edge(c);
|
||||||
// The child's Q is from the view of the side to move here.
|
// The child's Q is from the view of the side to move here.
|
||||||
float q = e.visits ? visited_edge_q(e) : fpu;
|
const float q = e.visits ? visited_edge_q(e) : fpu;
|
||||||
if (window_filter && e.child && repeats(tree_.node(e.child).key)) q = 0.0f;
|
|
||||||
const float score = q + explore * e.prior() / float(1 + e.visits);
|
const float score = q + explore * e.prior() / float(1 + e.visits);
|
||||||
if (score > best_score) {
|
if (score > best_score) {
|
||||||
best_score = score;
|
best_score = score;
|
||||||
@@ -690,7 +671,7 @@ void Searcher::playout() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 e = select_edge(idx, pos);
|
const u32 e = select_edge(idx);
|
||||||
Edge& edge = tree_.edge(e);
|
Edge& edge = tree_.edge(e);
|
||||||
pos.make_move(Move::from_raw(edge.move));
|
pos.make_move(Move::from_raw(edge.move));
|
||||||
history_.push_back(pos.key);
|
history_.push_back(pos.key);
|
||||||
|
|||||||
+11
-12
@@ -71,15 +71,15 @@ u16 position_check(const Position& pos);
|
|||||||
// check, about 80 bits.
|
// check, about 80 bits.
|
||||||
class Tree {
|
class Tree {
|
||||||
public:
|
public:
|
||||||
// Edges per node the arenas are sized for: the edge arena gets 128 of
|
// Edges per node the arenas are sized for: the edge arena gets 192 of
|
||||||
// every 160 bytes, the node arena 32. Measured in step 1 of the MCGS plan
|
// every 224 bytes, the node arena 32 (plus the table). In the graph
|
||||||
// (docs/mcgs-log.md, edges per visited node): 13 on average in 5 s
|
// almost every node gets expanded, so it holds about 20 edges per node
|
||||||
// searches without collections, 19-21 in middlegames, 3.6-5.5 in simple
|
// in middlegames (step 1: 18 per distinct position without collections),
|
||||||
// endgames, and 3-9 right after collections (pruned nodes keep their node
|
// and with 8 the edge arena filled first. Collections over the 16 bench
|
||||||
// but lose their edges). Over the 16 bench positions at 5 s and Hash 64,
|
// positions at 5 s and Hash 64 (local, one noisy run): 8 edges gave 67,
|
||||||
// 8 gave 184 collections (main: 200), as few as 13 did, without 13's
|
// 12 gave 53, 16 gave 51 and 20 gave 57; 16 already moves collections into
|
||||||
// 2-3x more collections in the endgames (which fill the node arena first).
|
// the endgames, which fill the node arena first.
|
||||||
static constexpr size_t EDGES_PER_NODE = 8;
|
static constexpr size_t EDGES_PER_NODE = 12;
|
||||||
|
|
||||||
// Splits `bytes` between the node arena, the edge arena and the table.
|
// Splits `bytes` between the node arena, the edge arena and the table.
|
||||||
void resize_bytes(size_t bytes);
|
void resize_bytes(size_t bytes);
|
||||||
@@ -331,9 +331,8 @@ private:
|
|||||||
// Second visit: creates the edges with their priors. False when the
|
// Second visit: creates the edges with their priors. False when the
|
||||||
// arena is full (a collection is then scheduled).
|
// arena is full (a collection is then scheduled).
|
||||||
bool expand(u32 idx, const Position& pos);
|
bool expand(u32 idx, const Position& pos);
|
||||||
// The edge PUCT picks at node `idx`, whose position is `pos` (the last
|
// The edge PUCT picks at node `idx`.
|
||||||
// entry of history_).
|
u32 select_edge(u32 idx) const;
|
||||||
u32 select_edge(u32 idx, const Position& pos) const;
|
|
||||||
// A node's Q from its own value and its children's (see Edge).
|
// A node's Q from its own value and its children's (see Edge).
|
||||||
void recompute_q(Node& node) const;
|
void recompute_q(Node& node) const;
|
||||||
bool is_repetition(const Position& pos) const;
|
bool is_repetition(const Position& pos) const;
|
||||||
|
|||||||
Reference in new issue
Block a user