diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-06-28 21:20:37 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-06-28 21:20:37 +0200 |
commit | a07cbfd67849b98a881f930e12e07c429e604ac4 (patch) | |
tree | 4b4ad859c169d6366ca2e6e91d0ef09e5986396f /src/main.rs | |
parent | e20e7f0a9029d33c67869951371cc03965127b31 (diff) |
updated active worm in update
This might change weirdly because of the select move.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/main.rs b/src/main.rs index de2940d..00b96cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,44 +4,46 @@ use std::path::Path; use time::{Duration, PreciseTime}; -use steam_powered_wyrm::command::{Command, Action}; -use steam_powered_wyrm::strategy::choose_move; -use steam_powered_wyrm::json; +use steam_powered_wyrm::command::{Action, Command}; use steam_powered_wyrm::game; +use steam_powered_wyrm::json; +use steam_powered_wyrm::strategy::choose_move; fn main() { - let max_time = Duration::milliseconds(950); + let max_time = Duration::milliseconds(900); let mut game_board = None; let mut strategy_cache = None; for line in stdin().lock().lines() { let start_time = PreciseTime::now(); - + let round_number = line.expect("Failed to read line from stdin: {}"); - - let command = - match json::read_state_from_json_file(&Path::new(&format!("./rounds/{}/state.json", round_number))) { - Ok(json_state) => { - match &mut game_board { - None => { - let new_board = game::GameBoard::new(json_state); - let (command, cache) = choose_move(&new_board, strategy_cache, &start_time, max_time); - strategy_cache = Some(cache); - game_board = Some(new_board); - command - }, - Some(game_board) => { - game_board.update(json_state); - let (command, cache) = choose_move(&game_board, strategy_cache, &start_time, max_time); - strategy_cache = Some(cache); - command - } - } - }, - Err(e) => { - eprintln!("WARN: State file could not be parsed: {}", e); - Command::new(Action::DoNothing) + + let command = match json::read_state_from_json_file(&Path::new(&format!( + "./rounds/{}/state.json", + round_number + ))) { + Ok(json_state) => match &mut game_board { + None => { + let new_board = game::GameBoard::new(json_state); + let (command, cache) = + choose_move(&new_board, strategy_cache, &start_time, max_time); + strategy_cache = Some(cache); + game_board = Some(new_board); + command + } + Some(game_board) => { + game_board.update(json_state); + let (command, cache) = + choose_move(&game_board, strategy_cache, &start_time, max_time); + strategy_cache = Some(cache); + command } - }; + }, + Err(e) => { + eprintln!("WARN: State file could not be parsed: {}", e); + Command::new(Action::DoNothing) + } + }; println!("C;{};{}", round_number, command); } } |