blob: 34d00611e713eb82080052dc38e68a1873339969 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use std::io::prelude::*;
use std::io::stdin;
mod command;
mod json;
mod geometry;
mod game;
mod strategy;
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) => {
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);
Command::DoNothing
}
};
println!("C;{};{}", round_number, command);
}
}
|