summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-05-22 20:38:47 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-05-22 20:38:47 +0200
commite9a514409565c17a4a86e8c6402be8d7a4f399ae (patch)
tree839dc6e223014ef519fe4d2d020aea996b562e44 /src/game.rs
parent63da94f7f1b25eddeb9ffd379f37c1a32e750fdb (diff)
Added a strategy cache for reusing previous round data
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/game.rs b/src/game.rs
index e3fb5c0..fe54f40 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -80,7 +80,7 @@ impl GameBoard {
}
pub fn update(&mut self, json: json::State) {
- for w in json.my_player.worms {
+ for w in &json.my_player.worms {
if let Some(worm) = self.players[0].find_worm_mut(w.id) {
worm.health = w.health;
worm.position = Point2d::new(w.position.x, w.position.y);
@@ -105,15 +105,15 @@ impl GameBoard {
self.map.clear(Point2d::new(cell.x, cell.y))
}
}
-
- self.round += 1;
- debug_assert_eq!(json.current_round, self.round);
-
- // Remove dead worms and update active worm
+
for player in &mut self.players {
player.clear_dead_worms();
player.next_active_worm();
}
+ debug_assert_eq!(json.active_worm_index().unwrap(), self.players[0].active_worm);
+
+ self.round += 1;
+ debug_assert_eq!(json.current_round, self.round);
}
pub fn simulate(&mut self, moves: [Command; 2]) {