Minor fixes
parent
a35ba24a13
commit
67185e321b
16
src/main.rs
16
src/main.rs
|
@ -9,7 +9,9 @@ use util::{Player, Symb};
|
||||||
|
|
||||||
fn play(
|
fn play(
|
||||||
maxi: &mut dyn agents::MaximizerAgent,
|
maxi: &mut dyn agents::MaximizerAgent,
|
||||||
|
maxi_player: Player,
|
||||||
mini: &mut dyn agents::MinimizerAgent,
|
mini: &mut dyn agents::MinimizerAgent,
|
||||||
|
mini_player: Player,
|
||||||
) -> Result<Board> {
|
) -> Result<Board> {
|
||||||
let mut board = Board::new();
|
let mut board = Board::new();
|
||||||
let mut is_first_turn = true;
|
let mut is_first_turn = true;
|
||||||
|
@ -32,18 +34,19 @@ fn play(
|
||||||
} else {
|
} else {
|
||||||
mini.step_min(&board)?
|
mini.step_min(&board)?
|
||||||
};
|
};
|
||||||
is_maxi_turn = !is_maxi_turn;
|
|
||||||
|
|
||||||
if !board.play(
|
if !board.play(
|
||||||
action,
|
action,
|
||||||
if is_maxi_turn {
|
if is_maxi_turn {
|
||||||
Player::Human
|
maxi_player
|
||||||
} else {
|
} else {
|
||||||
Player::Computer
|
mini_player
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
bail!("agent made invalid move")
|
bail!("agent made invalid move")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_maxi_turn = !is_maxi_turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\r{}║{}║", " ".repeat(6), board,);
|
println!("\r{}║{}║", " ".repeat(6), board,);
|
||||||
|
@ -52,10 +55,15 @@ fn play(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
rayon::ThreadPoolBuilder::new()
|
||||||
|
.num_threads(4)
|
||||||
|
.build_global()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut maxi = agents::PlayerAgent::new(Player::Human);
|
let mut maxi = agents::PlayerAgent::new(Player::Human);
|
||||||
let mut mini = agents::MinMaxTree {};
|
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() {
|
if a.is_done() {
|
||||||
println!(
|
println!(
|
||||||
"\r\n{}Your score:{} {:.2}\n\n",
|
"\r\n{}Your score:{} {:.2}\n\n",
|
||||||
|
|
Loading…
Reference in New Issue