summaryrefslogtreecommitdiff
path: root/src/shooting.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:46:00 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-05-20 22:46:00 +0200
commitb6a295a9eaf5fec16f72870baae84e6eadd1be33 (patch)
tree6ebe3b0c388d74b4ef48babd00a09cb9a5413dc0 /src/shooting.rs
parent6b8c71c635539a8609f82aa6eb52ea56c2c41c0c (diff)
Implemented lattice restricted battleship searching
Diffstat (limited to 'src/shooting.rs')
-rw-r--r--src/shooting.rs20
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 {