diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index dd858e9..37b5acd 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -154,6 +154,8 @@ impl FutureMoves { self.current_depth = current_depth; } + let mut leafs = self.leaf_moves().into_iter().collect::>(); + 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::>() + 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::)>>(); + .collect::)>>() + .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 {