diff options
Diffstat (limited to 'src/json.rs')
-rw-r--r-- | src/json.rs | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/src/json.rs b/src/json.rs index 798c567..86b35ea 100644 --- a/src/json.rs +++ b/src/json.rs @@ -53,7 +53,7 @@ pub struct PlayerWorm { pub digging_range: u32, pub movement_range: u32, pub weapon: Weapon, - pub banana_bombs: Option<Bomb> + pub banana_bombs: Option<Bomb>, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] @@ -61,6 +61,7 @@ pub struct PlayerWorm { pub struct Opponent { pub id: i32, pub score: i32, + pub current_worm_id: i32, pub worms: Vec<OpponentWorm>, pub remaining_worm_selections: u8, } @@ -159,7 +160,7 @@ pub struct Bomb { pub damage: i32, pub range: u8, pub count: u8, - pub damage_radius: u8 + pub damage_radius: u8, } impl State { @@ -170,6 +171,14 @@ impl State { .filter(|w| w.health > 0) .position(|w| w.id == self.current_worm_id) } + + pub fn opponent_active_worm_index(&self) -> Option<usize> { + self.opponents[0] + .worms + .iter() + .filter(|w| w.health > 0) + .position(|w| w.id == self.opponents[0].current_worm_id) + } } #[cfg(test)] @@ -234,6 +243,7 @@ mod test { { "id": 2, "score": 100, + "currentWormId": 3, "remainingWormSelections": 2, "worms": [ { @@ -328,39 +338,43 @@ mod test { score: 100, health: 300, remaining_worm_selections: 1, - worms: vec![PlayerWorm { - id: 1, - health: 100, - position: Position { x: 24, y: 29 }, - weapon: Weapon { - damage: 1, - range: 3, + worms: vec![ + PlayerWorm { + id: 1, + health: 100, + position: Position { x: 24, y: 29 }, + weapon: Weapon { + damage: 1, + range: 3, + }, + digging_range: 1, + movement_range: 1, + banana_bombs: Some(Bomb { + damage: 20, + range: 5, + count: 3, + damage_radius: 2, + }), }, - digging_range: 1, - movement_range: 1, - banana_bombs: Some(Bomb { - damage: 20, - range: 5, - count: 3, - damage_radius: 2 - }), - }, PlayerWorm { - id: 2, - health: 150, - position: Position { x: 1, y: 16 }, - weapon: Weapon { - damage: 1, - range: 3, + PlayerWorm { + id: 2, + health: 150, + position: Position { x: 1, y: 16 }, + weapon: Weapon { + damage: 1, + range: 3, + }, + digging_range: 1, + movement_range: 1, + banana_bombs: None, }, - digging_range: 1, - movement_range: 1, - banana_bombs: None, - }], + ], }, opponents: vec![Opponent { id: 2, score: 100, remaining_worm_selections: 2, + current_worm_id: 3, worms: vec![OpponentWorm { id: 1, health: 100, |