summaryrefslogtreecommitdiff
path: root/src/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.rs')
-rw-r--r--src/game.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/game.rs b/src/game.rs
index 769de73..7ece88d 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -139,7 +139,9 @@ impl GameBoard {
}
}
- // TODO: Good enough for now, but what if these worms are frozen?
+ // TODO: Good enough for now, but what if these worms are
+ // frozen? Then it looks like the move was a banana, but it
+ // actually does nothing.
if json
.opponents
.iter()
@@ -705,7 +707,6 @@ impl GameBoard {
let mut result =
Vec::with_capacity((SNOWBALL_RANGE * 2 + 1).pow(2) as usize - 12); // -12 is from 3 on each corner
- // TODO: Extract to share with bomb throwing
for y in worm.position.y - SNOWBALL_RANGE..=worm.position.y + SNOWBALL_RANGE {
for x in worm.position.x - SNOWBALL_RANGE..=worm.position.x + SNOWBALL_RANGE
{
@@ -785,17 +786,20 @@ impl GameBoard {
.collect()
}
- // TODO: If worm is frozen, there's only one option :(
// TODO: If all of this can be iterators, I can pass in the final filter to this function and only collect once.
pub fn valid_moves(&self, player_index: usize) -> Vec<Command> {
- self.valid_shoot_commands(player_index)
- .iter()
- .chain(self.valid_move_commands(player_index).iter())
- .chain(self.valid_bomb_commands(player_index).iter())
- .chain(self.valid_snowball_commands(player_index).iter())
- .chain([Command::new(Action::DoNothing)].iter())
- .cloned()
- .collect()
+ if self.players[player_index].active_worm_is_frozen_after_tick() {
+ vec![Command::new(Action::DoNothing)]
+ } else {
+ self.valid_shoot_commands(player_index)
+ .iter()
+ .chain(self.valid_move_commands(player_index).iter())
+ .chain(self.valid_bomb_commands(player_index).iter())
+ .chain(self.valid_snowball_commands(player_index).iter())
+ .chain([Command::new(Action::DoNothing)].iter())
+ .cloned()
+ .collect()
+ }
}
}