future_moves + generate_children things

This commit is contained in:
Simon Gardling 2025-02-28 21:42:03 -05:00
parent 86d4455321
commit ff1ded0a74
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -110,7 +110,7 @@ impl FutureMoves {
.into_iter()
.progress_with_style(ProgressStyle::with_template(pstyle_inner).unwrap())
.try_for_each(|node_idx| {
self.generate_children(node_idx).last();
self.generate_children(node_idx);
self.arena[node_idx].tried_children = true;
if self.arena_len() >= self.config.max_arena_size {
@ -144,10 +144,10 @@ impl FutureMoves {
false
}
/// Creates children for a parent (`parent`), returns an iterator it's children's indexes
/// Creates children for a parent (`parent_idx`)
/// Completely unchecked, the caller should be the one who tests to make sure child generation
/// hasn't already been tried on a parent
fn generate_children(&mut self, parent_idx: usize) -> impl Iterator<Item = usize> {
fn generate_children(&mut self, parent_idx: usize) {
let parent = &self.arena[parent_idx];
let new_color = !parent.color;
@ -175,11 +175,9 @@ impl FutureMoves {
let new_indices = start_idx..self.arena.len();
for child_idx in new_indices.clone() {
for child_idx in new_indices {
self.set_parent_child(parent_idx, child_idx);
}
new_indices
}
/// Given an index from `self.arena`, what depth is it at? 0-indexed
@ -228,8 +226,8 @@ impl FutureMoves {
let children_value = self.arena[idx]
.children
.iter()
.map(|&child| self.arena[child].value.expect("child has no value??"))
// average value of children
.flat_map(|&child| self.arena[child].value)
// sum values of children
.sum::<i128>()
// divide in order to calculate average value of all children
.checked_div(self.arena[idx].children.len() as i128)