Main tweaks
parent
fb69990b9d
commit
171d8b8d6c
56
src/main.rs
56
src/main.rs
|
@ -1,3 +1,5 @@
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use termion::color::{self};
|
use termion::color::{self};
|
||||||
|
|
||||||
|
@ -23,7 +25,7 @@ fn play(
|
||||||
"\r{}{}{}{}",
|
"\r{}{}{}{}",
|
||||||
" ".repeat(6),
|
" ".repeat(6),
|
||||||
if is_first_turn { '╓' } else { '║' },
|
if is_first_turn { '╓' } else { '║' },
|
||||||
board,
|
board.prettyprint()?,
|
||||||
if is_first_turn { '╖' } else { '║' },
|
if is_first_turn { '╖' } else { '║' },
|
||||||
);
|
);
|
||||||
is_first_turn = false;
|
is_first_turn = false;
|
||||||
|
@ -49,7 +51,7 @@ fn play(
|
||||||
is_maxi_turn = !is_maxi_turn;
|
is_maxi_turn = !is_maxi_turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\r{}║{}║", " ".repeat(6), board,);
|
println!("\r{}║{}║", " ".repeat(6), board.prettyprint()?);
|
||||||
println!("\r{}╙{}╜", " ".repeat(6), " ".repeat(board.size()));
|
println!("\r{}╙{}╜", " ".repeat(6), " ".repeat(board.size()));
|
||||||
Ok(board)
|
Ok(board)
|
||||||
}
|
}
|
||||||
|
@ -61,7 +63,7 @@ fn main() -> Result<()> {
|
||||||
.unwrap();
|
.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::Diffuse {};
|
||||||
|
|
||||||
let a = play(&mut maxi, Player::Human, &mut mini, Player::Computer)?;
|
let a = play(&mut maxi, Player::Human, &mut mini, Player::Computer)?;
|
||||||
if a.is_done() {
|
if a.is_done() {
|
||||||
|
@ -79,5 +81,53 @@ fn main() -> Result<()> {
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut mini = agents::PlayerAgent::new(Player::Human);
|
||||||
|
let mut maxi = agents::Diffuse {};
|
||||||
|
|
||||||
|
let b = play(&mut maxi, Player::Computer, &mut mini, Player::Human)?;
|
||||||
|
if b.is_done() {
|
||||||
|
println!(
|
||||||
|
"\r\n{}Computer score:{} {:.2}\n\n",
|
||||||
|
color::Fg(Player::Human.color()),
|
||||||
|
color::Fg(color::Reset),
|
||||||
|
b.evaluate().unwrap()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"\r\n{}Quitting{}\r\n",
|
||||||
|
color::Fg(color::Red),
|
||||||
|
color::Fg(color::Reset),
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
match a.evaluate().partial_cmp(&b.evaluate()) {
|
||||||
|
Some(Ordering::Equal) => {
|
||||||
|
println!("\r\nTie");
|
||||||
|
}
|
||||||
|
Some(Ordering::Greater) => {
|
||||||
|
println!(
|
||||||
|
"\r\n{}Human wins{}",
|
||||||
|
color::Fg(Player::Human.color()),
|
||||||
|
color::Fg(color::Reset),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(Ordering::Less) => {
|
||||||
|
println!(
|
||||||
|
"\r\n{}Computer wins{}",
|
||||||
|
color::Fg(Player::Computer.color()),
|
||||||
|
color::Fg(color::Reset),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!(
|
||||||
|
"\r\n{}Error{}",
|
||||||
|
color::Fg(color::Red),
|
||||||
|
color::Fg(color::Reset),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue