clippy + cleanup
This commit is contained in:
parent
7049039a77
commit
43585802d8
@ -127,12 +127,10 @@ impl FutureMoves {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// we want to keep only the best move of the agent
|
// we want to keep only the best move of the agent
|
||||||
if color == self.agent_color {
|
if color == self.agent_color && new.len() > 1 {
|
||||||
if new.len() > 1 {
|
// negative, because we want the max value to be at the first index
|
||||||
// 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.sort_by_key(|x| -x.compute_self_value(self.agent_color, 1));
|
new.drain(1..);
|
||||||
new.drain(1..);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.arena.extend(new);
|
self.arena.extend(new);
|
||||||
@ -164,11 +162,11 @@ impl FutureMoves {
|
|||||||
let mut visited = vec![false; self.arena.len()];
|
let mut visited = vec![false; self.arena.len()];
|
||||||
|
|
||||||
for depth in (0..=self.current_depth).rev() {
|
for depth in (0..=self.current_depth).rev() {
|
||||||
for idx in 0..self.arena.len() {
|
for (idx, was_visited) in visited.iter_mut().enumerate() {
|
||||||
if visited[idx] {
|
if *was_visited {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
visited[idx] = true;
|
*was_visited = true;
|
||||||
}
|
}
|
||||||
if self.depth_of(idx) != depth as usize {
|
if self.depth_of(idx) != depth as usize {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
12
src/game.rs
12
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 {
|
pub struct Game {
|
||||||
players: [Box<dyn Agent>; 2],
|
players: [Box<dyn Agent>; 2],
|
||||||
@ -93,15 +97,15 @@ impl Game {
|
|||||||
println!("{}", self);
|
println!("{}", self);
|
||||||
|
|
||||||
match self.board.game_winner(self.players[current_player].color()) {
|
match self.board.game_winner(self.players[current_player].color()) {
|
||||||
crate::board::Winner::Player(piece) => {
|
Winner::Player(piece) => {
|
||||||
println!("{} Wins!", piece.text());
|
println!("{} Wins!", piece.text());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
crate::board::Winner::Tie => {
|
Winner::Tie => {
|
||||||
println!("Game Tied!");
|
println!("Game Tied!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
crate::board::Winner::None => {}
|
Winner::None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.step(current_player);
|
self.step(current_player);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user