Cleanup
parent
e8614dd29f
commit
89aba4f930
|
@ -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`.
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue