From e95f3370c6d0a4a5ec87bff23ab7981e8f447540 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Tue, 16 Jul 2019 20:35:00 +0200 Subject: Prevent invalid bomb selections in simulations --- src/game.rs | 28 ++++++++++++++++------------ 1 file 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(), } -- cgit v1.2.3