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