summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-08-07 18:44:52 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-08-07 18:44:52 +0200
commitbcf28f2fcb7935b316a5a2f660b065faae51f0d9 (patch)
tree02f01f9c1897435c789146ebaee4339ae1eb0113
parentbc6901717058e6ff0609869dcb6e26c15d1e10cc (diff)
There is only one valid move once frozen
-rw-r--r--src/game.rs26
-rw-r--r--src/game/player.rs6
2 files changed, 21 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()
+ }
}
}
diff --git a/src/game/player.rs b/src/game/player.rs
index be9d515..6c2efb2 100644
--- a/src/game/player.rs
+++ b/src/game/player.rs
@@ -82,6 +82,12 @@ impl Player {
.map(|worm| worm.rounds_until_unfrozen > 0)
.unwrap_or(false)
}
+
+ pub fn active_worm_is_frozen_after_tick(&self) -> bool {
+ self.active_worm()
+ .map(|worm| worm.rounds_until_unfrozen > 1)
+ .unwrap_or(false)
+ }
}
#[cfg(test)]