summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2019-07-16 20:35:00 +0200
committerJustin Worthe <justin@worthe-it.co.za>2019-07-16 20:35:00 +0200
commite95f3370c6d0a4a5ec87bff23ab7981e8f447540 (patch)
tree60279b5b007d9671e6c2a4d05fadc72643b75d1a
parentf4c4a2953c20a7083c4671057d6f8464f20a4c10 (diff)
Prevent invalid bomb selections in simulations
-rw-r--r--src/game.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/game.rs b/src/game.rs
index 2a6aebb..dbf02e5 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -518,21 +518,25 @@ impl GameBoard {
Some(worm.id)
};
- let mut result = Vec::with_capacity(11 * 11 - 12);
-
- for y in worm.position.y - 5..=worm.position.y + 5 {
- for x in worm.position.x - 5..=worm.position.x + 5 {
- let target = Point2d::new(x, y);
- if (worm.position - target).magnitude_squared() < 36 {
- result.push(Command {
- worm: select,
- action: Action::Bomb(target),
- });
+ if select.is_none() || self.players[player_index].select_moves > 0 {
+ let mut result = Vec::with_capacity(11 * 11 - 12);
+
+ for y in worm.position.y - 5..=worm.position.y + 5 {
+ for x in worm.position.x - 5..=worm.position.x + 5 {
+ let target = Point2d::new(x, y);
+ if (worm.position - target).magnitude_squared() < 36 {
+ result.push(Command {
+ worm: select,
+ action: Action::Bomb(target),
+ });
+ }
}
}
- }
- result
+ result
+ } else {
+ Vec::new()
+ }
}
None => Vec::new(),
}