add ChildrenEvalMethod

This commit is contained in:
2025-03-04 09:50:12 -05:00
parent 4300598b38
commit f28027f93e
5 changed files with 67 additions and 82 deletions

View File

@@ -21,7 +21,6 @@ pub struct FutureMoves {
config: FutureMoveConfig,
}
#[derive(Default)]
pub struct FutureMoveConfig {
/// Max depth of that we should try and traverse
pub max_depth: usize,
@@ -43,6 +42,15 @@ pub struct FutureMoveConfig {
pub do_not_prune: bool,
pub print: bool,
pub children_eval_method: ChildrenEvalMethod,
}
#[derive(Debug, Clone, Copy)]
pub enum ChildrenEvalMethod {
Average,
Max,
Min,
}
impl FutureMoves {
@@ -126,21 +134,21 @@ impl FutureMoves {
if cf.is_break() {
// pruning unfinished level
let by_depth = self.by_depth(0..self.arena.len());
let mut bdh = HashMap::new();
for (a, b) in by_depth {
bdh.insert(a, b);
}
// let by_depth = self.by_depth(0..self.arena.len());
// let mut bdh = HashMap::new();
// for (a, b) in by_depth {
// bdh.insert(a, b);
// }
for &i in bdh.get(&(self.current_depth + 1)).unwrap_or(&Vec::new()) {
self.remove(i);
}
// for &i in bdh.get(&(self.current_depth + 1)).unwrap_or(&Vec::new()) {
// self.remove(i);
// }
for &i in bdh.get(&self.current_depth).unwrap_or(&Vec::new()) {
self.arena[i].tried_children = false;
}
// for &i in bdh.get(&self.current_depth).unwrap_or(&Vec::new()) {
// self.arena[i].tried_children = false;
// }
self.refocus_tree();
// self.refocus_tree();
return;
}
@@ -251,12 +259,21 @@ impl FutureMoves {
// reversed so we build up the value of the closest (in time) moves from the future
for (_, nodes) in by_depth_vec.into_iter().rev() {
for idx in nodes {
let children_value = self.arena[idx]
let children_values = self.arena[idx]
.children
.iter()
.flat_map(|&child| self.arena[child].value)
.max()
.unwrap_or(0);
.collect::<Vec<_>>();
let children_value = match self.config.children_eval_method {
ChildrenEvalMethod::Average => children_values
.into_iter()
.sum::<i128>()
.checked_div(self.arena[idx].children.len() as i128),
ChildrenEvalMethod::Max => children_values.into_iter().max(),
ChildrenEvalMethod::Min => children_values.into_iter().min(),
}
.unwrap_or(0);
// we use `depth` and divided `self_value` by it, idk if this is worth it
// we should really setup some sort of ELO rating for each commit, playing them against

View File

@@ -1,4 +1,4 @@
mod board_value;
mod future_moves;
mod r#move;
pub use future_moves::{FutureMoveConfig, FutureMoves};
pub use future_moves::{ChildrenEvalMethod, FutureMoveConfig, FutureMoves};