|
|
@@ -27,6 +27,9 @@ class DidNotAct(Exception):
|
|
|
class Queue():
|
|
|
def __init__(self):
|
|
|
self.items = []
|
|
|
+
|
|
|
+ def __bool__(self):
|
|
|
+ return bool(self.items)
|
|
|
|
|
|
def put(self, item, priority):
|
|
|
heapq.heappush(self.items, (priority, item))
|
|
|
@@ -45,9 +48,6 @@ class InterestQueue(Queue):
|
|
|
self.items += other.items
|
|
|
return self
|
|
|
|
|
|
- def __bool__(self):
|
|
|
- return bool(self.items)
|
|
|
-
|
|
|
def put(self, 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
|
|
|
|
|
|
for x, y in self.zone(target_pos, 10):
|
|
|
- if ship.moving_cost(x, y) > 10:
|
|
|
+ if ship.moving_cost(x, y) > 100:
|
|
|
continue
|
|
|
- if self.manhattan((x, y), target_pos) < 2:
|
|
|
+ if self.manhattan((x, y), target_pos) <= 1:
|
|
|
continue
|
|
|
|
|
|
interest = 0 # the lower the better
|
|
|
|
|
|
+ interest += ship.moving_cost(x, y)
|
|
|
+
|
|
|
# avoid cells too close from borders
|
|
|
if not (3 <= x <= (self.w - 3) and 3 <= y < (self.h - 3)):
|
|
|
interest += 10
|
|
|
@@ -271,7 +273,7 @@ class Grid(Base):
|
|
|
shooting_spots.put((x, y), interest)
|
|
|
|
|
|
return shooting_spots.get()
|
|
|
-
|
|
|
+
|
|
|
# geometrical algorithms
|
|
|
@staticmethod
|
|
|
def from_cubic(xu, yu, zu):
|
|
|
@@ -295,7 +297,7 @@ class Grid(Base):
|
|
|
for _ in range(0, radius):
|
|
|
current = buffer
|
|
|
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]
|
|
|
|
|
|
@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)
|
|
|
|
|
|
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
|
|
|
|
|
|
except IndexError:
|