Added reduced time flag
[entelect-challenge-tower-defence.git] / src / main.rs
index 22f698d..6434c9d 100644 (file)
@@ -1,4 +1,7 @@
 extern crate zombot;
+extern crate time;
+use time::{PreciseTime, Duration};
+
 use zombot::*;
 use zombot::engine::command::Command;
 
@@ -12,8 +15,11 @@ use std::fs::File;
 use std::io::prelude::*;
 use std::process;
 
-fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command {
-    strategy::sample::choose_move(settings, state)
+fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState, start_time: &PreciseTime) -> Command {
+    #[cfg(not(feature = "reduced-time"))] let max_time = Duration::milliseconds(1950);
+    #[cfg(feature = "reduced-time")] let max_time = Duration::milliseconds(950);
+    
+    strategy::monte_carlo::choose_move(settings, state, start_time, max_time)
 }
 
 
@@ -25,18 +31,25 @@ fn write_command(filename: &str, command: Command) -> Result<(), Box<Error> > {
 
 
 fn main() {
-    let (settings, state) = match json::read_state_from_file(STATE_PATH) {
+    let start_time = PreciseTime::now();
+    
+    println!("Reading in state.json file");
+    let (settings, state) = match input::json::read_state_from_file(STATE_PATH) {
         Ok(ok) => ok,
         Err(error) => {
+            println!("Error while parsing JSON file: {}", error);
             process::exit(1);
         }
     };
-    let command = choose_move(&settings, &state);
+    let command = choose_move(&settings, &state, &start_time);
 
     match write_command(COMMAND_PATH, command) {
         Ok(()) => {}
         Err(error) => {
+            println!("Error while writing command file: {}", error);
             process::exit(1);
         }
     }
+
+    println!("Elapsed time: {}", start_time.to(PreciseTime::now()));
 }