improve evenness of FutureMoves tree
This commit is contained in:
parent
00238fc1f1
commit
10389ad8ee
@ -42,3 +42,7 @@ criterion = { version = "0.5", features = [ "html_reports" ] }
|
|||||||
[[bench]]
|
[[bench]]
|
||||||
name = "future_children"
|
name = "future_children"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
# fix weird warnings about `test` not being expected
|
||||||
|
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(test)'] }
|
||||||
|
|||||||
@ -59,10 +59,38 @@ impl FutureMoves {
|
|||||||
self.arena.len()
|
self.arena.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn leaf_moves(&self) -> Vec<usize> {
|
||||||
|
let mut indexes = (0..self.arena.len())
|
||||||
|
// 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_trimmed && !got.tried_children && got.winner == Winner::None
|
||||||
|
})
|
||||||
|
.filter(|&idx| self.is_connected_to_root(idx))
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
// we want to try and make the tree even in depth
|
||||||
|
// by first generating children for younger moves
|
||||||
|
indexes.sort_by_key(|&x| self.depth_of(x));
|
||||||
|
indexes
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find the current depth of the arena by
|
||||||
|
/// looking at leaf moves and finding the smallest value
|
||||||
|
fn determine_current_depth(&self) -> Option<usize> {
|
||||||
|
// leaf_moves is sorted from min to max depth
|
||||||
|
self.leaf_moves().first().map(|&i| self.depth_of(i))
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate children for all children of `nodes`
|
/// Generate children for all children of `nodes`
|
||||||
/// only `pub` for the sake of benchmarking
|
/// only `pub` for the sake of benchmarking
|
||||||
pub fn extend_layers(&mut self) {
|
pub fn extend_layers(&mut self) {
|
||||||
for _ in (self.current_depth + 1)..=self.config.max_depth {
|
// recover from partial tree extention
|
||||||
|
if let Some(current_depth) = self.determine_current_depth() {
|
||||||
|
self.current_depth = current_depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
for _ in self.current_depth..self.config.max_depth {
|
||||||
let pstyle_inner = if cfg!(test) {
|
let pstyle_inner = if cfg!(test) {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
@ -73,13 +101,10 @@ impl FutureMoves {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let cf = (0..self.arena.len())
|
let cf = self
|
||||||
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
|
.leaf_moves()
|
||||||
.filter(|&idx| {
|
.into_iter()
|
||||||
let got = &self.arena[idx];
|
.filter(|&i| self.depth_of(i) == self.current_depth)
|
||||||
!got.is_trimmed && !got.tried_children && got.winner == Winner::None
|
|
||||||
})
|
|
||||||
.filter(|&idx| self.is_connected_to_root(idx))
|
|
||||||
.collect::<Vec<usize>>()
|
.collect::<Vec<usize>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.progress_with_style(ProgressStyle::with_template(pstyle_inner).unwrap())
|
.progress_with_style(ProgressStyle::with_template(pstyle_inner).unwrap())
|
||||||
@ -198,7 +223,7 @@ impl FutureMoves {
|
|||||||
let by_depth_vec = self.by_depth(indexes);
|
let by_depth_vec = self.by_depth(indexes);
|
||||||
|
|
||||||
// reversed so we build up the value of the closest (in time) moves from the future
|
// reversed so we build up the value of the closest (in time) moves from the future
|
||||||
for (depth, nodes) in by_depth_vec.into_iter().rev() {
|
for (_, nodes) in by_depth_vec.into_iter().rev() {
|
||||||
for idx in nodes {
|
for idx in nodes {
|
||||||
let children_value = self.arena[idx]
|
let children_value = self.arena[idx]
|
||||||
.children
|
.children
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user