Minor fixes
parent
a35ba24a13
commit
67185e321b
16
src/main.rs
16
src/main.rs
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue