diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-06-26 16:42:43 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-06-26 16:42:43 +0200 |
commit | 40712a1c1b61c6e110f1bddd3e955bbfb797e5ab (patch) | |
tree | 12c698809ba240a5e62deddc9f1e2e7366fc9719 /src/game.rs | |
parent | 1aeab6da05a0c7b7dad4d06a38b282a82d5e1a51 (diff) |
Implemented select move rules
Diffstat (limited to 'src/game.rs')
-rw-r--r-- | src/game.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/game.rs b/src/game.rs index a4a4a23..ffa8cb9 100644 --- a/src/game.rs +++ b/src/game.rs @@ -40,18 +40,20 @@ impl GameBoard { let player = Player { active_worm: json.active_worm_index().unwrap(), moves_score: json.my_player.score - json.my_player.health_score(), + select_moves: json.my_player.remaining_worm_selections, 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, - weapon_range: commando_range - }).collect() + weapon_range: commando_range, + }).collect(), }; let opponent = Player { active_worm: 0, moves_score: json.opponents[0].score - json.opponents[0].health_score(), + select_moves: json.opponents[0].remaining_worm_selections, worms: json.opponents.iter().flat_map(|o| &o.worms).map(|w| Worm { id: w.id, health: w.health, @@ -138,7 +140,7 @@ impl GameBoard { pub fn simulate(&mut self, moves: [Command; 2]) { let actions = [moves[0].action, moves[1].action]; - // TODO: simulate_select + self.simulate_select(moves); self.simulate_moves(actions); self.simulate_digs(actions); // TODO: simulate_bombs @@ -160,6 +162,17 @@ impl GameBoard { }; } + fn simulate_select(&mut self, moves: [Command; 2]) { + moves.iter().zip(self.players.iter_mut()) + .for_each(|(m, player)| { + if let Some(worm) = m.worm { + debug_assert!(player.select_moves > 0, "Could not make select move, out of select tokens"); + player.select_moves = player.select_moves.saturating_sub(1); + player.active_worm = player.find_worm_position(worm).unwrap_or(0); + } + }); + } + fn simulate_moves(&mut self, actions: [Action; 2]) { match actions { [Action::Move(p1), Action::Move(p2)] if p1.x == p2.x && p1.y == p2.y => { |