ChildrenEvalMethod: add and switch to AverageDivDepth

This commit is contained in:
Simon Gardling 2025-03-12 16:53:07 -04:00
parent e14391d129
commit 31e88e3313
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
4 changed files with 24 additions and 18 deletions

View File

@ -13,7 +13,7 @@ fn extend_layers_no_pruning(depth: usize) -> usize {
max_arena_size: usize::MAX, max_arena_size: usize::MAX,
do_prune: false, do_prune: false,
print: false, print: false,
children_eval_method: ChildrenEvalMethod::Average, children_eval_method: ChildrenEvalMethod::AverageDivDepth,
}; };
let mut fut = FutureMoves::new(Piece::Black, config); let mut fut = FutureMoves::new(Piece::Black, config);
fut.update_from_board(&Board::new().starting_pos()); fut.update_from_board(&Board::new().starting_pos());

View File

@ -26,10 +26,10 @@ pub fn run() {
max_arena_size: usize::MAX, max_arena_size: usize::MAX,
do_prune: false, do_prune: false,
print: false, print: false,
children_eval_method: ChildrenEvalMethod::Average, children_eval_method: ChildrenEvalMethod::AverageDivDepth,
}; };
let configs = [4, 6, 8] let configs = [6]
.into_iter() .into_iter()
.map(move |d| FutureMoveConfig { .map(move |d| FutureMoveConfig {
max_depth: d, max_depth: d,
@ -46,6 +46,16 @@ pub fn run() {
move_c.max_depth < 8 move_c.max_depth < 8
} }
}) })
// .flat_map(move |prev_c| {
// [
// ChildrenEvalMethod::Average,
// ChildrenEvalMethod::AverageDivDepth,
// ]
// .map(move |children_strat| FutureMoveConfig {
// children_eval_method: children_strat,
// ..prev_c
// })
// });
.flat_map(move |prev_c| { .flat_map(move |prev_c| {
if !prev_c.do_prune { if !prev_c.do_prune {
// do not bother making configs when pruning is disabled // do not bother making configs when pruning is disabled
@ -107,7 +117,7 @@ pub fn run() {
let mut arena = PlayerArena::new(vec); let mut arena = PlayerArena::new(vec);
arena.prop_arena(5); arena.prop_arena(100);
println!("{}", arena); println!("{}", arena);
} }

View File

@ -78,6 +78,7 @@ impl std::fmt::Display for FutureMoveConfig {
pub enum ChildrenEvalMethod { pub enum ChildrenEvalMethod {
/// Best (by far) strat compared to Max or Min /// Best (by far) strat compared to Max or Min
Average, Average,
AverageDivDepth,
} }
impl FutureMoves { impl FutureMoves {
@ -271,7 +272,7 @@ impl FutureMoves {
let by_depth_vec = self.by_depth(indexes); let by_depth_vec = self.by_depth(indexes);
// reversed so we build up the value of the closest (in time) moves from the future // 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 (depth, nodes) in by_depth_vec.into_iter().rev() {
for idx in nodes { for idx in nodes {
let children_values = self.arena[idx] let children_values = self.arena[idx]
.children .children
@ -284,6 +285,12 @@ impl FutureMoves {
.into_iter() .into_iter()
.sum::<i32>() .sum::<i32>()
.checked_div(self.arena[idx].children.len() as i32), .checked_div(self.arena[idx].children.len() as i32),
ChildrenEvalMethod::AverageDivDepth => children_values
.into_iter()
.sum::<i32>()
.checked_div(self.arena[idx].children.len() as i32)
.and_then(|x| x.checked_div(depth as i32)),
} }
.unwrap_or(0); .unwrap_or(0);
@ -560,7 +567,7 @@ mod tests {
max_arena_size: 100, max_arena_size: 100,
do_prune: false, do_prune: false,
print: false, print: false,
children_eval_method: ChildrenEvalMethod::Average, children_eval_method: ChildrenEvalMethod::AverageDivDepth,
}; };
#[test] #[test]

View File

@ -24,20 +24,9 @@ fn main() {
max_arena_size: 100_000_000, max_arena_size: 100_000_000,
do_prune: true, do_prune: true,
print: true, print: true,
children_eval_method: ChildrenEvalMethod::Average, children_eval_method: ChildrenEvalMethod::AverageDivDepth,
}, },
); );
// let player2 = complexagent::ComplexAgent::new(
// Piece::White,
// FutureMoveConfig {
// max_depth: 20,
// min_arena_depth_sub: 14,
// top_k_children: 2,
// up_to_minus: 10,
// max_arena_size: 50_000_000,
// do_prune: true,
// },
// );
let player2 = agent::ManualAgent::new(Piece::White); let player2 = agent::ManualAgent::new(Piece::White);
let mut game = Game::new(Box::new(player1), Box::new(player2)); let mut game = Game::new(Box::new(player1), Box::new(player2));