Add reset button
This commit is contained in:
@@ -13,6 +13,9 @@ impl Engine {
|
||||
board,
|
||||
}
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.board.reset()
|
||||
}
|
||||
pub fn get_state(&self) -> &board::Board {
|
||||
&self.board
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user