summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-07-22 10:17:57 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-07-22 10:17:57 +0200
commit237c67f87eaab0bab51d83d3dbf7a9632db75b50 (patch)
tree0915b98750d610c3688c3d58ade57c9f9d8834bf
parent9255b4040b192aca63c1dd374e8ae5171a73ecb5 (diff)
Added special case for a point that can be known to be a hit while seeking
Shooting here first will eliminate a ship immediately that might otherwise be dumbly left until the end of the game, where a spot that can only be one ship shows up on the overall probability density graph. It also does meaningful shots while recharging specials shots to speed up the random part of searching.
-rw-r--r--src/knowledge.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/knowledge.rs b/src/knowledge.rs
index 1923f41..4a66e8b 100644
--- a/src/knowledge.rs
+++ b/src/knowledge.rs
@@ -170,6 +170,11 @@ impl Knowledge {
let possible_placements = self.opponent_map.possible_placements();
// let lattice = self.lattice_size(); //TODO use the lattice still?
+ let guaranteed_hits = self.get_points_that_touch_all_possibilities_on_unsunk_ship();
+ if !guaranteed_hits.is_empty() {
+ return (Weapon::SingleShot, guaranteed_hits);
+ }
+
let mut best_shots: HashMap<Weapon, (Vec<Point>, usize)> = HashMap::new();
for &weapon in self.available_weapons.iter() {
@@ -234,6 +239,16 @@ impl Knowledge {
(best.0.clone(), (best.1).0)
}
+ fn get_points_that_touch_all_possibilities_on_unsunk_ship(&self) -> Vec<Point> {
+ self.opponent_map.flat_cell_position_list().iter().cloned().filter(|&point| {
+ self.opponent_map.ships.values()
+ .any(|ref ship| !ship.destroyed &&
+ ship.possible_placements.iter().all(|placement| {
+ placement.touches_point(point)
+ }))
+ }).collect()
+ }
+
fn lattice_size(&self) -> u16 {
let any_long_ships = self.opponent_map.ships.iter()
.any(|(ship, knowledge)| ship.length() >= 4 && !knowledge.destroyed);