diff --git a/src/complexagent.rs b/src/complexagent.rs index a5d5458..ca680a8 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 = 14; - const NON_LAZY_DEPTH: usize = 8; + const MAX_DEPTH: usize = 9; + const NON_LAZY_DEPTH: usize = 9; 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 578f92b..b44a28e 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -110,21 +110,37 @@ impl FutureMoves { } let new_color = !parent.color; - let mut new: Vec = - // use [`Board::all_positions`] here instead of [`Board::possible_moves`] - // because we use [`Board::what_if`] later and we want to reduce calls to [`Board::propegate_from_dry`] - Board::all_positions() - .flat_map(|(i, j)| parent.board.what_if(i, j, new_color).map(move |x| (i, j, x))) - .map(|(i, j, new_board)| Move::new(i, j, new_board, new_color, lazy_children, self.agent_color, Some(parent_idx))).collect(); + + // use [`Board::all_positions`] here instead of [`Board::possible_moves`] + // because we use [`Board::what_if`] later and we want to reduce calls to [`Board::propegate_from_dry`] + let mut new: Vec = Board::all_positions() + .flat_map(|(i, j)| { + parent + .board + .what_if(i, j, new_color) + .map(move |x| (i, j, x)) + }) + .map(|(i, j, new_board)| { + Move::new( + i, + j, + new_board, + new_color, + lazy_children, + self.agent_color, + Some(parent_idx), + ) + }) + .collect(); // 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) new.sort_by_key(|x| -x.self_value.abs()); - // keep the TOP_K children `self.agent_color`-color moves + // keep the TOP_K children of their magnitude const TOP_K_CHILDREN: usize = 2; - // we want to keep only the best move of the agent + // we want to keep only the greatest magnitude moves if lazy_children && new.len() > TOP_K_CHILDREN { new.drain(TOP_K_CHILDREN..); } @@ -204,8 +220,7 @@ impl FutureMoves { .map(|(i, &child)| self.arena[child].value * ((i + 1) as i128)) .sum::(); - self.arena[idx].value = - (self.arena[idx].self_value / (depth as i64)) as i128 + children_value; + self.arena[idx].value = self.arena[idx].self_value as i128 + children_value; } } } diff --git a/src/main.rs b/src/main.rs index e6672a5..82924e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,8 @@ pub mod repr; fn main() { let player1 = complexagent::ComplexAgent::new(Piece::Black); // let player2 = complexagent::ComplexAgent::new(Piece::White); - // let player2 = agent::ManualAgent::new(Piece::White); - let player2 = agent::RandomAgent::new(Piece::White); + 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(); }