add FutureMoves::check_arena
This commit is contained in:
parent
bd00c29ad4
commit
5f7a5fdb00
@ -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),
|
||||
|
||||
@ -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<String> {
|
||||
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user