From 057a4fe886848322adf4e48ad9709a289434dc1b Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 5 May 2018 20:37:53 +0200 Subject: Initial commit with sample bot and embedded game engine --- src/state_json.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/state_json.rs (limited to 'src/state_json.rs') diff --git a/src/state_json.rs b/src/state_json.rs new file mode 100644 index 0000000..429db6d --- /dev/null +++ b/src/state_json.rs @@ -0,0 +1,86 @@ +use std::fs::File; +use std::io::prelude::*; +use serde_json; +use std::error::Error; + +pub fn read_state_from_file(filename: &str) -> Result> { + let mut file = File::open(filename)?; + let mut content = String::new(); + file.read_to_string(&mut content)?; + let state = serde_json::from_str(content.as_ref())?; + Ok(state) +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct State { + pub game_details: GameDetails, + pub players: Vec, + pub game_map: Vec>, +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GameDetails { + pub round: u32, + pub map_width: u32, + pub map_height: u32, + pub building_prices: BuildingPrices +} + +#[derive(Deserialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub struct BuildingPrices { + pub energy: u32, + pub defense: u32, + pub attack: u32 +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Player { + pub player_type: char, + pub energy: u32, + pub health: u32, + pub hits_taken: u32, + pub score: u32 +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GameCell { + pub x: u32, + pub y: u32, + pub buildings: Vec, + pub missiles: Vec, + pub cell_owner: char +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BuildingState { + pub health: u32, + pub construction_time_left: i32, + pub price: u32, + pub weapon_damage: u32, + pub weapon_speed: u32, + pub weapon_cooldown_time_left: u32, + pub weapon_cooldown_period: u32, + pub destroy_multiplier: u32, + pub construction_score: u32, + pub energy_generated_per_turn: u32, + pub building_type: String, + pub x: u32, + pub y: u32, + pub player_type: char +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct MissileState { + pub damage: u32, + pub speed: u32, + pub x: u32, + pub y: u32, + pub player_type: char +} -- cgit v1.2.3