From 19b5b856db8bd13483c4b187aaad08d7dd3f76bf Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 28 Feb 2025 23:36:47 -0500 Subject: [PATCH] logic improvements --- benches/future_children.rs | 7 ++++--- src/logic/future_moves.rs | 12 +++++++----- src/logic/move.rs | 6 +++--- src/main.rs | 14 ++++++++------ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/benches/future_children.rs b/benches/future_children.rs index 02c9024..498b9a4 100644 --- a/benches/future_children.rs +++ b/benches/future_children.rs @@ -7,10 +7,11 @@ use othello::{ fn extend_layers_no_pruning(depth: usize, arena_size: usize) -> usize { let config = FutureMoveConfig { max_depth: depth, - min_arena_depth_sub: 4, - top_k_children: 2, - up_to_minus: usize::MAX, // disable pruning + min_arena_depth_sub: 0, + top_k_children: 5, + up_to_minus: 4, max_arena_size: arena_size, + do_not_prune: true, }; let mut fut = FutureMoves::new(Piece::Black, config); fut.set_root_from_board(Board::new().starting_pos()); diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index bbed4f9..a84bda4 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -41,6 +41,8 @@ pub struct FutureMoveConfig { /// Max size of the arena, will not generate more if /// the arena is of that size or bigger pub max_arena_size: usize, + + pub do_not_prune: bool, } impl FutureMoves { @@ -227,10 +229,7 @@ impl FutureMoves { .children .iter() .flat_map(|&child| self.arena[child].value) - // sum values of children - .sum::() - // divide in order to calculate average value of all children - .checked_div(self.arena[idx].children.len() as i128) + .max() .unwrap_or(0); // we use `depth` and divided `self_value` by it, idk if this is worth it @@ -358,7 +357,9 @@ impl FutureMoves { } fn prune_bad_children(&mut self) { - if self.config.max_depth > self.current_depth + self.config.min_arena_depth_sub { + if self.config.max_depth > (self.current_depth + self.config.min_arena_depth_sub) + || self.config.do_not_prune + { return; } @@ -469,6 +470,7 @@ mod tests { top_k_children: 1, up_to_minus: 0, max_arena_size: 100, + do_not_prune: true, }; #[test] diff --git a/src/logic/move.rs b/src/logic/move.rs index c93548c..2f98d7f 100644 --- a/src/logic/move.rs +++ b/src/logic/move.rs @@ -77,8 +77,8 @@ impl Move { /// Sort children of the [`Move`] by their self_value in `arena` pub fn sort_children(&mut self, arena: &[Move]) { - // negative, because we want the max value to be at the first index - // abs because we want the most EXTREME possible outcome (win or lose for example) - self.children.sort_by_key(|&i| -arena[i].self_value.abs()); + self.children.sort_by(|&a, &b| { + arena[b].value.cmp(&arena[a].value) // Descending order for agent's max nodes + }); } } diff --git a/src/main.rs b/src/main.rs index a21dcc2..378e296 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,24 +14,26 @@ fn main() { Piece::Black, FutureMoveConfig { max_depth: 20, - min_arena_depth_sub: 3, + min_arena_depth_sub: 14, top_k_children: 2, - up_to_minus: usize::MAX, // disable pruning + up_to_minus: 10, max_arena_size: 50_000_000, + do_not_prune: false, }, ); // let player2 = complexagent::ComplexAgent::new( // Piece::White, // FutureMoveConfig { // max_depth: 20, - // min_arena_depth_sub: 3, + // min_arena_depth_sub: 14, // top_k_children: 2, - // up_to_minus: 5, - // max_arena_size: 2_000_000, + // up_to_minus: 10, + // max_arena_size: 50_000_000, + // do_not_prune: false, // }, // ); + let player2 = agent::ManualAgent::new(Piece::White); - // let player2 = agent::RandomAgent::new(Piece::White); let mut game = Game::new(Box::new(player1), Box::new(player2)); game.game_loop(); }