clippy + cleanup

This commit is contained in:
Simon Gardling 2025-02-17 15:06:36 -05:00
parent 7049039a77
commit 43585802d8
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 15 additions and 13 deletions

View File

@ -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;

View File

@ -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<dyn Agent>; 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);