summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-04-25 13:34:11 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-04-25 13:34:11 +0200
commit6a5cc64a1778fab68ab02a9f3314f62471c8d35c (patch)
tree7471a8117afcf18038d809856123f17f0b1e13fc
parent88430f31c73f469086b68f2b77d1e1ba5f9178e7 (diff)
Call update vs create after the first move
-rw-r--r--src/game.rs13
-rw-r--r--src/main.rs17
2 files changed, 26 insertions, 4 deletions
diff --git a/src/game.rs b/src/game.rs
index 70960aa..a42f1e6 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -14,6 +14,7 @@ struct Player {
}
struct Worm {
+ id: i32,
health: i32,
position: Point2d<i8>,
weapon_damage: i32,
@@ -46,6 +47,7 @@ impl GameBoard {
player: Player {
active_worm: json.active_worm_index().unwrap(),
worms: json.my_player.worms.iter().map(|w| Worm {
+ id: w.id,
health: w.health,
position: Point2d::new(w.position.x, w.position.y),
weapon_damage: commando_damage,
@@ -55,6 +57,7 @@ impl GameBoard {
opponent: Player {
active_worm: 0,
worms: json.opponents.iter().flat_map(|o| &o.worms).map(|w| Worm {
+ id: w.id,
health: w.health,
position: Point2d::new(w.position.x, w.position.y),
weapon_damage: commando_damage,
@@ -74,4 +77,14 @@ impl GameBoard {
}
}
}
+
+ pub fn update(&mut self, json: json::State) {
+ // TODO
+ // What can change?
+ // - Worm health (and dead worms die)
+ // - Active worms += 1
+ // - The worms may move
+ // - The powerups may be taken
+ // - The map cells may change from dirt to not dirt
+ }
}
diff --git a/src/main.rs b/src/main.rs
index 216915c..34d0061 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,6 @@
use std::io::prelude::*;
use std::io::stdin;
-use rand::prelude::*;
-
mod command;
mod json;
mod geometry;
@@ -13,14 +11,25 @@ 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) => {
- let game_board = game::GameBoard::new(json_state);
- choose_move(&game_board)
+ 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);