From 3a1c20ebba57632392443a050fc10d44e3048843 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Sun, 26 Jan 2020 20:57:55 -0800 Subject: Playing against the computer actually works! --- src/game.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/game.rs') diff --git a/src/game.rs b/src/game.rs index 04bd76a..be9d23d 100644 --- a/src/game.rs +++ b/src/game.rs @@ -650,6 +650,7 @@ impl GameState { return None; } + // TODO: this does not handle the case dragon edge case fn check_win(&self) -> Option { if let Some(w) = self.check_road_win() { return Some(w); @@ -731,17 +732,20 @@ impl Game { pub fn query_action_lines(&self) -> String { let mut result = String::new(); let mut newline = true; - result += "0. "; - for i in 0..self.actions.len() { - if i > 1 && newline { - // TODO: Is placing the opponent's first stone the zeroeth action? - result += &format!("{}. ", i); - } - result += &format!("{} ", self.actions[i]); - if i > 0 && !newline { - result.push('\n'); + let num_actions = self.actions.len(); + if num_actions > 0 { + result += "0. "; + for i in 0..num_actions { + if i > 1 && newline { + // TODO: Is placing the opponent's first stone the zeroeth action? + result += &format!("{}. ", i); + } + result += &format!("{} ", self.actions[i]); + if i > 0 && !newline { + result.push('\n'); + } + newline = !newline; } - newline = !newline; } result } -- cgit v1.3.1