arena fixes

This commit is contained in:
Simon Gardling 2025-02-26 10:34:35 -05:00
parent 63a20d875f
commit fd7701cd79
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 21 additions and 17 deletions

View File

@ -46,7 +46,7 @@ impl FutureMoves {
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
.filter(|&idx| {
let got = &self.arena[idx];
got.is_lazy || got.children.is_empty()
got.is_trimmed || got.children.is_empty()
})
.filter(|&idx| self.is_connected_to_root(idx))
.collect::<Vec<usize>>()
@ -317,23 +317,25 @@ impl FutureMoves {
// values are needed in order to prune and see what's best
self.compute_values(0..self.arena_len());
let by_depth =
self.by_depth((0..self.arena.len()).filter(|&i| self.is_connected_to_root(i)));
let by_depth = self.by_depth(0..self.arena.len());
const TOP_K_CHIL: usize = 2;
// the lower the value, the more conservative
const UP_TO: usize = 5;
// the lower the value, the more conservative, what level to stop pruning at?
// a lower value allows more possible paths
let up_to = self.current_depth - 2;
// start pruning at X depth before self.max_depth
const START_PRUNING_AT_MINUS: usize = 2;
if self.max_depth > self.current_depth + START_PRUNING_AT_MINUS {
// start pruning at X depth before self.max_depth is reached
// used for pruning during tree generation before the tree is fully grown
const START_PRUNING_AT_MINUS: usize = 3;
if self.max_depth.saturating_sub(START_PRUNING_AT_MINUS) > self.current_depth {
return;
}
for (depth, indexes) in by_depth {
// TODO! maybe update by_depth every iteration or something?
if depth > UP_TO {
if depth > up_to {
return;
}
@ -344,10 +346,10 @@ impl FutureMoves {
for idx in indexes {
let mut m = self.arena[idx].clone();
if m.is_lazy {
if m.is_trimmed {
continue;
}
m.is_lazy = true;
m.is_trimmed = true;
m.sort_children(&mut self.arena);
if m.children.len() > TOP_K_CHIL {
let drained = m.children.drain(TOP_K_CHIL..);
@ -358,6 +360,8 @@ impl FutureMoves {
self.arena[idx] = m;
}
}
// rebuild tree to exclude the things that were pruned
self.refocus_tree();
}
@ -444,7 +448,7 @@ mod tests {
value: None,
self_value: 0,
color: Piece::Black,
is_lazy: false,
is_trimmed: false,
});
futm.update_root_idx_raw(0);
@ -546,7 +550,7 @@ mod tests {
value: None,
self_value: 0,
color: Piece::Black,
is_lazy: false,
is_trimmed: false,
});
futm.update_root_idx_raw(0);
@ -610,7 +614,7 @@ mod tests {
value: None,
self_value: 0,
color: Piece::Black,
is_lazy: false,
is_trimmed: false,
});
futm.update_root_idx_raw(0);

View File

@ -31,8 +31,8 @@ pub struct Move {
/// Which color made a move on this move?
pub color: Piece,
/// Was this child lazily created? (it will have delayed child generation)
pub is_lazy: bool,
/// Was this move's children previously trimmed?
pub is_trimmed: bool,
}
lazy_static! {
@ -57,7 +57,7 @@ impl Move {
children: Vec::new(),
value: None,
color,
is_lazy: false,
is_trimmed: false,
self_value: 0,
};
m.self_value = m.compute_self_value(agent_color);