From 510767263a0060ad13b2488a9402b1d176ad65ef Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 25 Apr 2019 16:50:06 +0200 Subject: Test that match replay matches my simulation --- src/game.rs | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/game.rs') diff --git a/src/game.rs b/src/game.rs index 626a377..dad72cd 100644 --- a/src/game.rs +++ b/src/game.rs @@ -3,42 +3,42 @@ use crate::command::Command; use crate::json; pub struct GameBoard { - players: [Player; 2], - powerups: Vec, - map: Map, + pub players: [Player; 2], + pub powerups: Vec, + pub map: Map, } -struct Player { - active_worm: usize, - worms: Vec +pub struct Player { + pub active_worm: usize, + pub worms: Vec } -struct Worm { - id: i32, - health: i32, - position: Point2d, - weapon_damage: i32, - weapon_range: u8 +pub struct Worm { + pub id: i32, + pub health: i32, + pub position: Point2d, + pub weapon_damage: i32, + pub weapon_range: u8 } -enum Powerup { +pub enum Powerup { Health(Point2d, i32) } -struct Map { - size: u8, +pub struct Map { + pub size: u8, /// This is 2d, each row is size long - cells: Vec + pub cells: Vec } -enum CellType { +pub enum CellType { Air, Dirt, DeepSpace, } -enum SimulationOutcome { +pub enum SimulationOutcome { PlayerWon(usize), Draw, Continue, @@ -98,6 +98,17 @@ impl GameBoard { } pub fn simulate(&mut self, moves: [Command; 2]) -> SimulationOutcome { + for player in &mut self.players { + player.active_worm = (player.active_worm + 1) % player.worms.len(); + } SimulationOutcome::Continue } } + +impl Player { + pub fn find_worm(&self, id: i32) -> Option<&Worm> { + self.worms + .iter() + .find(|w| w.id == id) + } +} -- cgit v1.2.3