浏览代码

various fixes

olinox 6 年之前
父节点
当前提交
5a77448214
共有 1 个文件被更改,包括 10 次插入8 次删除
  1. 10 8
      carribean/script.py

+ 10 - 8
carribean/script.py

@@ -27,6 +27,9 @@ class DidNotAct(Exception):
 class Queue():
 class Queue():
     def __init__(self):
     def __init__(self):
         self.items = []
         self.items = []
+    
+    def __bool__(self):
+        return bool(self.items)
 
 
     def put(self, item, priority):
     def put(self, item, priority):
         heapq.heappush(self.items, (priority, item))
         heapq.heappush(self.items, (priority, item))
@@ -45,9 +48,6 @@ class InterestQueue(Queue):
         self.items += other.items
         self.items += other.items
         return self
         return self
     
     
-    def __bool__(self):
-        return bool(self.items)
-    
     def put(self, item):
     def put(self, item):
         heapq.heappush(self.items, item)
         heapq.heappush(self.items, item)
         
         
@@ -254,13 +254,15 @@ class Grid(Base):
         target_pos = target.next_pos if type(target) is Ship else target.pos
         target_pos = target.next_pos if type(target) is Ship else target.pos
         
         
         for x, y in self.zone(target_pos, 10):
         for x, y in self.zone(target_pos, 10):
-            if ship.moving_cost(x, y) > 10:
+            if ship.moving_cost(x, y) > 100:
                 continue
                 continue
-            if self.manhattan((x, y), target_pos) < 2:
+            if self.manhattan((x, y), target_pos) <= 1:
                 continue
                 continue
             
             
             interest = 0 # the lower the better
             interest = 0 # the lower the better
             
             
+            interest += ship.moving_cost(x, y)
+            
             # avoid cells too close from borders
             # avoid cells too close from borders
             if not (3 <= x <= (self.w - 3) and 3 <= y < (self.h - 3)):
             if not (3 <= x <= (self.w - 3) and 3 <= y < (self.h - 3)):
                 interest += 10
                 interest += 10
@@ -271,7 +273,7 @@ class Grid(Base):
             shooting_spots.put((x, y), interest)
             shooting_spots.put((x, y), interest)
 
 
         return shooting_spots.get()
         return shooting_spots.get()
-
+    
     # geometrical algorithms
     # geometrical algorithms
     @staticmethod
     @staticmethod
     def from_cubic(xu, yu, zu):
     def from_cubic(xu, yu, zu):
@@ -295,7 +297,7 @@ class Grid(Base):
         for _ in range(0, radius):
         for _ in range(0, radius):
             current = buffer
             current = buffer
             for x, y in current:
             for x, y in current:
-                buffer |= frozenset(self.neighbors(x, y))
+                buffer |= frozenset(self.abs_neighbors(x, y))
         return [c for c in buffer if 0 <= c[0] < self.w and 0 <= c[1] < self.h]       
         return [c for c in buffer if 0 <= c[0] < self.w and 0 <= c[1] < self.h]       
 
 
     @staticmethod
     @staticmethod
@@ -848,7 +850,7 @@ while True:
             acquired = sorted([(s, s.objectives.get()) for s in grid.owned_ships if not s.objective], key= lambda x: x[1].interest)
             acquired = sorted([(s, s.objectives.get()) for s in grid.owned_ships if not s.objective], key= lambda x: x[1].interest)
             
             
             for s, o in acquired:
             for s, o in acquired:
-                if not s.objective and not any(al.objective.target is o.target for al in s.allies):
+                if not s.objective and not any(al.objective.target is o.target for al in s.allies if al.objective):
                     s.objective = o
                     s.objective = o
             
             
         except IndexError:
         except IndexError: