diff --git a/src/complexagent.rs b/src/complexagent.rs index 938c3da..43db389 100644 --- a/src/complexagent.rs +++ b/src/complexagent.rs @@ -127,12 +127,10 @@ impl FutureMoves { }).collect(); // we want to keep only the best move of the agent - if color == self.agent_color { - if new.len() > 1 { - // negative, because we want the max value to be at the first index - new.sort_by_key(|x| -x.compute_self_value(self.agent_color, 1)); - new.drain(1..); - } + if color == self.agent_color && new.len() > 1 { + // negative, because we want the max value to be at the first index + new.sort_by_key(|x| -x.compute_self_value(self.agent_color, 1)); + new.drain(1..); } self.arena.extend(new); @@ -164,11 +162,11 @@ impl FutureMoves { let mut visited = vec![false; self.arena.len()]; for depth in (0..=self.current_depth).rev() { - for idx in 0..self.arena.len() { - if visited[idx] { + for (idx, was_visited) in visited.iter_mut().enumerate() { + if *was_visited { continue; } else { - visited[idx] = true; + *was_visited = true; } if self.depth_of(idx) != depth as usize { continue; diff --git a/src/game.rs b/src/game.rs index 8626c3d..086b1eb 100644 --- a/src/game.rs +++ b/src/game.rs @@ -1,4 +1,8 @@ -use crate::{agent::Agent, board::Board, piece::Piece}; +use crate::{ + agent::Agent, + board::{Board, Winner}, + piece::Piece, +}; pub struct Game { players: [Box; 2], @@ -93,15 +97,15 @@ impl Game { println!("{}", self); match self.board.game_winner(self.players[current_player].color()) { - crate::board::Winner::Player(piece) => { + Winner::Player(piece) => { println!("{} Wins!", piece.text()); break; } - crate::board::Winner::Tie => { + Winner::Tie => { println!("Game Tied!"); break; } - crate::board::Winner::None => {} + Winner::None => {} } self.step(current_player);