cleanup
This commit is contained in:
@@ -59,6 +59,7 @@ impl FutureMoves {
|
|||||||
self.arena.len()
|
self.arena.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns indexes of leaf [`Move`]s, sorted by their depth (increasing order)
|
||||||
fn leaf_moves(&self) -> Vec<usize> {
|
fn leaf_moves(&self) -> Vec<usize> {
|
||||||
let mut indexes = (0..self.arena.len())
|
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)
|
// we want to select all nodes that don't have children, or are lazy (need to maybe be regenerated)
|
||||||
@@ -122,7 +123,6 @@ impl FutureMoves {
|
|||||||
self.prune_bad_children();
|
self.prune_bad_children();
|
||||||
self.current_depth += 1;
|
self.current_depth += 1;
|
||||||
if cf.is_break() {
|
if cf.is_break() {
|
||||||
// println!("extend_layers: early break");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +231,7 @@ impl FutureMoves {
|
|||||||
.map(|&child| self.arena[child].value.expect("child has no value??"))
|
.map(|&child| self.arena[child].value.expect("child has no value??"))
|
||||||
// average value of children
|
// average value of children
|
||||||
.sum::<i128>()
|
.sum::<i128>()
|
||||||
|
// divide in order to calculate average value of all children
|
||||||
.checked_div(self.arena[idx].children.len() as i128)
|
.checked_div(self.arena[idx].children.len() as i128)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
@@ -350,17 +351,16 @@ impl FutureMoves {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.is_connected_to_root(idx) {
|
||||||
|
errors.push(format!("{}: not connected to root in any way", idx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errors
|
errors
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prune_bad_children(&mut self) {
|
fn prune_bad_children(&mut self) {
|
||||||
if self
|
if self.config.max_depth > self.current_depth + self.config.min_arena_depth_sub {
|
||||||
.config
|
|
||||||
.max_depth
|
|
||||||
.saturating_sub(self.config.min_arena_depth_sub)
|
|
||||||
> self.current_depth
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,23 +425,23 @@ impl FutureMoves {
|
|||||||
|
|
||||||
let mut index_map = vec![None; self.arena.len()];
|
let mut index_map = vec![None; self.arena.len()];
|
||||||
|
|
||||||
let new_start: Vec<(usize, usize, Move)> = retain
|
let (indexes, moves): (Vec<(usize, usize)>, Vec<Move>) = retain
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate() // old_idx
|
.enumerate() // old_idx
|
||||||
.zip(self.arena.drain(..))
|
.zip(self.arena.drain(..))
|
||||||
.filter(|&((_, keep), _)| keep) // filter out un-related nodes
|
.filter(|&((_, keep), _)| keep) // filter out un-related nodes
|
||||||
.map(|((old_idx, _), node)| (old_idx, node))
|
.map(|((old_idx, _), node)| (old_idx, node))
|
||||||
.enumerate() // new_idx
|
.enumerate() // new_idx
|
||||||
.map(|(a, (b, c))| (a, b, c))
|
.map(|(new_idx, (old_idx, node))| ((new_idx, old_idx), node))
|
||||||
.collect();
|
.unzip();
|
||||||
|
|
||||||
for &(new_idx, old_idx, _) in &new_start {
|
for (new_idx, old_idx) in indexes {
|
||||||
index_map[old_idx] = Some(new_idx);
|
index_map[old_idx] = Some(new_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.arena = new_start
|
self.arena = moves
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, _, mut node)| {
|
.map(|mut node| {
|
||||||
if let Some(parent) = node.parent.as_mut() {
|
if let Some(parent) = node.parent.as_mut() {
|
||||||
if let Some(new_parent) = index_map[*parent] {
|
if let Some(new_parent) = index_map[*parent] {
|
||||||
*parent = new_parent;
|
*parent = new_parent;
|
||||||
@@ -452,8 +452,9 @@ impl FutureMoves {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for c in node.children.as_mut_slice() {
|
for c in node.children.as_mut_slice() {
|
||||||
debug_assert!(
|
debug_assert_ne!(
|
||||||
index_map.get(*c).unwrap().is_some(),
|
index_map.get(*c).and_then(|&x| x),
|
||||||
|
None,
|
||||||
"index_map should contain the child's index"
|
"index_map should contain the child's index"
|
||||||
);
|
);
|
||||||
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
|
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
|
||||||
|
|||||||
Reference in New Issue
Block a user