Initial stab at monte carlo implementation
[entelect-challenge-tower-defence.git] / src / main.rs
1 extern crate zombot;
2 use zombot::*;
3 use zombot::engine::command::Command;
4
5 use std::error::Error;
6
7 const STATE_PATH: &str = "state.json";
8
9 const COMMAND_PATH: &str = "command.txt";
10
11 use std::fs::File;
12 use std::io::prelude::*;
13 use std::process;
14
15 fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command {
16     strategy::monte_carlo::choose_move(settings, state)
17 }
18
19
20 fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
21     let mut file = File::create(filename)?;
22     write!(file, "{}", command)?;
23     Ok(())
24 }
25
26
27 fn main() {
28     println!("Reading in state.json file");
29     let (settings, state) = match json::read_state_from_file(STATE_PATH) {
30         Ok(ok) => ok,
31         Err(error) => {
32             println!("Error while parsing JSON file: {}", error);
33             process::exit(1);
34         }
35     };
36     let command = choose_move(&settings, &state);
37
38     match write_command(COMMAND_PATH, command) {
39         Ok(()) => {}
40         Err(error) => {
41             println!("Error while writing command file: {}", error);
42             process::exit(1);
43         }
44     }
45 }