Add reset button

This commit is contained in:
2022-01-05 22:10:04 +01:00
parent 0e8eb7b767
commit c7f82769e3
4 changed files with 32 additions and 1 deletions

View File

@@ -230,6 +230,14 @@ impl Ui {
Err("choose_move takes 1 arg".to_owned())
}
}
fn reset(&mut self, args: &[&str]) -> Result<String, String> {
if let [] = args {
self.engine.reset();
Ok(format!("{}", self.engine.get_state()))
} else {
Err("reset doesn't take args".to_owned())
}
}
fn handle_command(&mut self, s: &str) -> Result<String, String> {
let mut cmd = s.split(',');
// There will be at least an empty string => otherwise panic
@@ -241,6 +249,7 @@ impl Ui {
"make_move" => self.make_move(&args),
"set_state" => self.set_state(&args),
"choose_move" => self.choose_move(&args),
"reset" => self.reset(&args),
"" => Err("No command given".to_owned()),
_ => Err("Invalid command".to_owned()),
}