瀏覽代碼

include a queue to find the best place to shoot

olinox 6 年之前
父節點
當前提交
c171e0b34c
共有 1 個文件被更改,包括 22 次插入24 次删除
  1. 22 24
      carribean/script.py

+ 22 - 24
carribean/script.py

@@ -746,7 +746,7 @@ class Ship(Entity):
         if self.blocked_since:
             for i in proba:
                 for c in self.area:
-                    proba[i][c] = proba[i].get(c, 0) + 40 * self.blocked_since
+                    proba[i][c] = proba[i].get(c, 0) + 30 * self.blocked_since
                 
         self.cached_next_pos_proba = proba
                 
@@ -929,30 +929,28 @@ class Ship(Entity):
         for ally in self.allies:
             avoid += ally.next_area
         
-        next_positions = target.guess_next_positions(4)
-        for t, next_pos in next_positions.items():
-            dist = Grid.manhattan(self.prow, next_pos)
-            if dist > self.SCOPE:
-                continue
-            if next_pos in avoid:
-                continue
-            
-            dt = 1 + (1 + round(dist / 3)) # time for the cannonball to reach this pos (including fire turn)
-            
-            if dt == t:
-                log(f"[x] precise shoot: dt={dt}, pos={next_pos}")
-                ship.fire(*next_pos)
-                return True
-        
-        # give a try
-        next_pos = next_positions[2]
-        if not next_pos in avoid:
-            dist_p = Grid.manhattan(self.prow, next_pos)
-            if dist_p <= self.SCOPE:
-                ship.fire(*next_pos)
-                return True
+        next_positions = target.next_pos_proba(4)
+        best_shots = Queue()
+        for t, cells in next_positions.items():
+            for c, proba in cells.items():
+                if c in avoid:
+                    continue
+                dist = Grid.manhattan(self.prow, c)
+                if dist > self.SCOPE:
+                    continue
+    
+                dt = 1 + (1 + round(dist / 3)) # time for the cannonball to reach this pos (including fire turn)
+                
+                interest = 30 * abs(dt - t) - proba # the lower the better
+                best_shots.put(c, interest)
             
-        return False
+        try:
+            shoot_at = best_shots.get()
+            log(f"[x] precise shoot: pos={shoot_at}")
+            ship.fire(*shoot_at)
+            return True
+        except IndexError:
+            return False
         
     def can_mine(self):
         return self.last_mining is None or (current_turn - self.last_mining) >= 4