From 89aba4f9304fd9fbe6a87c64027f3729b34fc17c Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 5 Mar 2024 14:58:36 -0800 Subject: [PATCH] Cleanup --- README.md | 2 +- src/agents/human.rs | 20 ++++++++++++-------- src/main.rs | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 755a231..8e75dbf 100644 --- a/README.md +++ b/README.md @@ -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) - `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`. \ No newline at end of file diff --git a/src/agents/human.rs b/src/agents/human.rs index e971afd..498b91a 100644 --- a/src/agents/human.rs +++ b/src/agents/human.rs @@ -35,7 +35,7 @@ impl SymbolSelector { } } - fn up(&mut self, board: &Board) { + fn down(&mut self, board: &Board) { if self.cursor == 0 { self.cursor = self.symbols.len() - 1; } 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 { self.cursor = 0; } else { @@ -92,14 +92,18 @@ impl Human { 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 loop { print!( - "\r{}{}{} ╙{}{}{}{}{}╜ {}", - // Goal - color::Fg(self.player.color()), - if minimize { "Min" } else { "Max" }, - color::Fg(color::Reset), + "\r{}╙{}{}{}{}{}╜ {}", + board_label, // Cursor " ".repeat(self.cursor), color::Fg(self.player.color()), @@ -156,7 +160,7 @@ impl Human { self.symbol_selector.down(board); break; } - Key::Char('\n') => { + Key::Char(' ') | Key::Char('\n') => { let symb = Symb::from_char(self.symbol_selector.current()); if let Some(symb) = symb { let action = PlayerAction { diff --git a/src/main.rs b/src/main.rs index 072ae63..ed2e2d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,9 +60,9 @@ fn play( let mut is_maxi_turn = true; let board_label = format!( - "{}{:6}{}", + "{}{:<6}{}", color::Fg(color::LightBlack), - maxi.player(), + maxi.player().to_string(), color::Fg(color::Reset) );