diff --git a/src/complexagent.rs b/src/complexagent.rs index dc3d4b4..b636e19 100644 --- a/src/complexagent.rs +++ b/src/complexagent.rs @@ -12,8 +12,8 @@ pub struct ComplexAgent { #[allow(dead_code)] impl ComplexAgent { pub const fn new(color: Piece) -> Self { - const MAX_DEPTH: usize = 18; - const NON_LAZY_DEPTH: usize = 5; + const MAX_DEPTH: usize = 8; + const NON_LAZY_DEPTH: usize = 8; Self { color, future_moves: FutureMoves::new(color, MAX_DEPTH, NON_LAZY_DEPTH), diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 6da7acf..7264245 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -299,6 +299,44 @@ impl FutureMoves { self.refocus_tree(); self.extend_layers(); self.compute_values(0..self.arena.len()); + + // check arena's consistancy + assert_eq!(self.check_arena().join("\n"), ""); + } + + /// Checks the consistancy of the Arena (parents and children) + /// returns a vector of errors ([`String`]) + pub fn check_arena(&self) -> Vec { + let mut errors = vec![]; + for idx in 0..self.arena.len() { + let m = &self.arena[idx]; + if let Some(parent) = m.parent { + if !(0..self.arena.len()).contains(&parent) { + errors.push(format!("{}: parent is out of range ({})", idx, parent)); + } + + if !self.arena[parent].children.contains(&idx) { + errors.push(format!( + "{}: parent ({}) doesn't list {} as child", + idx, parent, idx + )); + } + } + + for &child_idx in &m.children { + if !(0..self.arena.len()).contains(&child_idx) { + errors.push(format!("{}: parent is out of range ({})", idx, child_idx)); + } + + if self.arena[child_idx].parent != Some(idx) { + errors.push(format!( + "{}: child ({}) does not list self as parent", + idx, child_idx + )); + } + } + } + errors } fn prune_bad_children(&mut self) {