summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-04-25 13:34:11 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-04-25 13:34:11 +0200
commit6a5cc64a1778fab68ab02a9f3314f62471c8d35c (patch)
tree7471a8117afcf18038d809856123f17f0b1e13fc /src/main.rs
parent88430f31c73f469086b68f2b77d1e1ba5f9178e7 (diff)
Call update vs create after the first move
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 216915c..34d0061 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,6 @@
use std::io::prelude::*;
use std::io::stdin;
-use rand::prelude::*;
-
mod command;
mod json;
mod geometry;
@@ -13,14 +11,25 @@ use command::Command;
use strategy::choose_move;
fn main() {
+ let mut game_board = None;
for line in stdin().lock().lines() {
let round_number = line.expect("Failed to read line from stdin: {}");
let command =
match json::read_state_from_json_file(&format!("./rounds/{}/state.json", round_number)) {
Ok(json_state) => {
- let game_board = game::GameBoard::new(json_state);
- choose_move(&game_board)
+ match &mut game_board {
+ None => {
+ let new_board = game::GameBoard::new(json_state);
+ let command = choose_move(&new_board);
+ game_board = Some(new_board);
+ command
+ },
+ Some(game_board) => {
+ game_board.update(json_state);
+ choose_move(&game_board)
+ }
+ }
},
Err(e) => {
eprintln!("WARN: State file could not be parsed: {}", e);