aboutsummaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
authortslil clingman <>2020-01-26 20:57:55 -0800
committertslil clingman <>2020-01-26 20:57:55 -0800
commit3a1c20ebba57632392443a050fc10d44e3048843 (patch)
tree3f70bcbc43a40d64f58f8454e92d6da6bac7b3f7 /src/game.rs
parent1930b067982a5ee324cd2832ace295e67603d2dc (diff)
Playing against the computer actually works!
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs24
1 files changed, 14 insertions, 10 deletions
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<WinType> {
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
}