From 05ccf5572b39fe254c7b0464cc78a1b623f732c7 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 13 May 2017 21:43:27 +0200 Subject: Added checking if state is in use before shooting --- src/shooting.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/shooting.rs') diff --git a/src/shooting.rs b/src/shooting.rs index 14f2b81..c2ca56e 100644 --- a/src/shooting.rs +++ b/src/shooting.rs @@ -1,6 +1,16 @@ use actions::*; use math::*; +use state::*; -pub fn shoot_randomly(map_size: u16) -> Action { - Action::Shoot(Point::random(map_size)) +pub fn shoot_randomly(state: &State) -> Action { + let mut shot: Point; + + while { + shot = Point::random(state.map_size); + let ref target = state.opponent_map.cells[shot.x as usize][shot.y as usize]; + target.damaged || target.missed + } {} + + + Action::Shoot(shot) } -- cgit v1.2.3