Main tweaks

master
Mark 2024-03-05 10:18:34 -08:00
parent fb69990b9d
commit 171d8b8d6c
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 53 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use std::cmp::Ordering;
use anyhow::{bail, Result};
use termion::color::{self};
@ -23,7 +25,7 @@ fn play(
"\r{}{}{}{}",
" ".repeat(6),
if is_first_turn { '╓' } else { '║' },
board,
board.prettyprint()?,
if is_first_turn { '╖' } else { '║' },
);
is_first_turn = false;
@ -49,7 +51,7 @@ fn play(
is_maxi_turn = !is_maxi_turn;
}
println!("\r{}{}", " ".repeat(6), board,);
println!("\r{}{}", " ".repeat(6), board.prettyprint()?);
println!("\r{}{}", " ".repeat(6), " ".repeat(board.size()));
Ok(board)
}
@ -61,7 +63,7 @@ fn main() -> Result<()> {
.unwrap();
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)?;
if a.is_done() {
@ -79,5 +81,53 @@ fn main() -> Result<()> {
);
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(())
}