master
Mark 2024-03-05 14:58:36 -08:00
parent e8614dd29f
commit 89aba4f930
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 15 additions and 11 deletions

View File

@ -23,6 +23,6 @@ As always, run this project with `cargo run`. The app takes one argument by defa
- `chase`: Play against a simple extremum-chasing agent (easy) - `chase`: Play against a simple extremum-chasing agent (easy)
- `diffuse`: Play against a slightly more intellegent extremum chaser (medium) - `diffuse`: Play against a slightly more intellegent extremum chaser (medium)
For example, `cargo run -- random` will play a game against a random player. For example, `cargo run -- random` will play a game against a random player. Use your arrow keys and space bar to play the game.
Additional options are available, see `cargo run -- --help`. Additional options are available, see `cargo run -- --help`.

View File

@ -35,7 +35,7 @@ impl SymbolSelector {
} }
} }
fn up(&mut self, board: &Board) { fn down(&mut self, board: &Board) {
if self.cursor == 0 { if self.cursor == 0 {
self.cursor = self.symbols.len() - 1; self.cursor = self.symbols.len() - 1;
} else { } else {
@ -51,7 +51,7 @@ impl SymbolSelector {
} }
} }
fn down(&mut self, board: &Board) { fn up(&mut self, board: &Board) {
if self.cursor == self.symbols.len() - 1 { if self.cursor == self.symbols.len() - 1 {
self.cursor = 0; self.cursor = 0;
} else { } else {
@ -92,14 +92,18 @@ impl Human {
self.symbol_selector.check(board); self.symbol_selector.check(board);
let board_label = format!(
"{}{:<6}{}",
color::Fg(self.player.color()),
if minimize { "Min" } else { "Max" },
color::Fg(color::Reset)
);
// Ask for input until we get a valid move // Ask for input until we get a valid move
loop { loop {
print!( print!(
"\r{}{}{} ╙{}{}{}{}{}╜ {}", "\r{}╙{}{}{}{}{}╜ {}",
// Goal board_label,
color::Fg(self.player.color()),
if minimize { "Min" } else { "Max" },
color::Fg(color::Reset),
// Cursor // Cursor
" ".repeat(self.cursor), " ".repeat(self.cursor),
color::Fg(self.player.color()), color::Fg(self.player.color()),
@ -156,7 +160,7 @@ impl Human {
self.symbol_selector.down(board); self.symbol_selector.down(board);
break; break;
} }
Key::Char('\n') => { Key::Char(' ') | Key::Char('\n') => {
let symb = Symb::from_char(self.symbol_selector.current()); let symb = Symb::from_char(self.symbol_selector.current());
if let Some(symb) = symb { if let Some(symb) = symb {
let action = PlayerAction { let action = PlayerAction {

View File

@ -60,9 +60,9 @@ fn play(
let mut is_maxi_turn = true; let mut is_maxi_turn = true;
let board_label = format!( let board_label = format!(
"{}{:6}{}", "{}{:<6}{}",
color::Fg(color::LightBlack), color::Fg(color::LightBlack),
maxi.player(), maxi.player().to_string(),
color::Fg(color::Reset) color::Fg(color::Reset)
); );