diff options
Diffstat (limited to 'src/shooting.rs')
-rw-r--r-- | src/shooting.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/shooting.rs b/src/shooting.rs index 616ebf3..4d87d86 100644 --- a/src/shooting.rs +++ b/src/shooting.rs @@ -17,14 +17,18 @@ pub fn shoot_smartly(knowledge: &Knowledge) -> Action { } fn seek_shoot(knowledge: &Knowledge) -> Point { - let mut shot: Point; - - while { - shot = Point::random(knowledge.map_size); - let ref target = knowledge.opponent_map.cells[shot.x as usize][shot.y as usize]; - target.shot_attempted() - } {} - shot + let possibilities = knowledge.get_most_possibility_shots_on_lattice(); + if possibilities.is_empty() { + println!("All possible shots on the current lattice have been tried!"); + Point::new(0,0) + } + else { + let mut rng = rand::thread_rng(); + let between = Range::new(0, possibilities.len()); + let i = between.ind_sample(&mut rng); + + possibilities[i as usize] + } } fn destroy_shoot(knowledge: &Knowledge) -> Point { |