improve leaf handling

This commit is contained in:
Simon Gardling 2025-04-22 15:43:13 -04:00
parent 87c386c9a4
commit 0d81dca8df
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -154,6 +154,8 @@ impl FutureMoves {
self.current_depth = current_depth;
}
let mut leafs = self.leaf_moves().into_iter().collect::<Vec<usize>>();
for _ in self.current_depth..self.config.max_depth {
let pstyle_inner = if cfg!(test) || !self.config.print {
""
@ -167,11 +169,7 @@ impl FutureMoves {
let allowed_size = self.config.max_arena_size - self.arena.len();
let curr_size = Arc::new(AtomicUsize::new(0));
let got = self
.leaf_moves()
.into_iter()
.filter(|&i| self.depth_of(i) == self.current_depth)
.collect::<Vec<usize>>()
leafs = leafs
.into_par_iter()
.progress_with_style(ProgressStyle::with_template(pstyle_inner).unwrap())
.map(|parent_idx| (parent_idx, self.generate_children_raw(parent_idx)))
@ -183,19 +181,21 @@ impl FutureMoves {
true
}
})
.collect::<Vec<(usize, Vec<Move>)>>();
.collect::<Vec<(usize, Vec<Move>)>>()
.into_iter()
.flat_map(|(parent_idx, moves)| {
let start_idx = self.arena.len();
self.arena.extend(moves);
let new_indices = start_idx..self.arena.len();
self.arena[parent_idx].children.extend(new_indices.clone());
new_indices
})
.collect();
// get total # of generated boards
let got_len = curr_size.load(Ordering::Acquire);
got.into_iter().for_each(|(parent_idx, moves)| {
let start_idx = self.arena.len();
self.arena.extend(moves);
let new_indices = start_idx..self.arena.len();
self.arena[parent_idx].children.extend(new_indices);
});
self.prune_bad_children();
self.current_depth += 1;
if got_len == allowed_size {