Minor fixes

master
Mark 2024-03-04 18:46:16 -08:00
parent a35ba24a13
commit 67185e321b
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 12 additions and 4 deletions

View File

@ -9,7 +9,9 @@ use util::{Player, Symb};
fn play(
maxi: &mut dyn agents::MaximizerAgent,
maxi_player: Player,
mini: &mut dyn agents::MinimizerAgent,
mini_player: Player,
) -> Result<Board> {
let mut board = Board::new();
let mut is_first_turn = true;
@ -32,18 +34,19 @@ fn play(
} else {
mini.step_min(&board)?
};
is_maxi_turn = !is_maxi_turn;
if !board.play(
action,
if is_maxi_turn {
Player::Human
maxi_player
} else {
Player::Computer
mini_player
},
) {
bail!("agent made invalid move")
}
is_maxi_turn = !is_maxi_turn;
}
println!("\r{}{}", " ".repeat(6), board,);
@ -52,10 +55,15 @@ fn play(
}
fn main() -> Result<()> {
rayon::ThreadPoolBuilder::new()
.num_threads(4)
.build_global()
.unwrap();
let mut maxi = agents::PlayerAgent::new(Player::Human);
let mut mini = agents::MinMaxTree {};
let a = play(&mut maxi, &mut mini)?;
let a = play(&mut maxi, Player::Human, &mut mini, Player::Computer)?;
if a.is_done() {
println!(
"\r\n{}Your score:{} {:.2}\n\n",