Add furthest_to filter mainly for units stutter stepping backwards
@@ -96,6 +96,11 @@ class Units(list):
position = position.position
return min(self, key=lambda unit: unit.position.to2.distance_to(position.to2))
+ def furthest_to(self, position):
+ if isinstance(position, Unit):
+ position = position.position
+ return max(self, key=lambda unit: unit.position.to2.distance_to(position.to2))
+
def closer_than(self, distance, position):
if isinstance(position, Unit):
position = position.position
@@ -143,8 +148,8 @@ class Units(list):
def center(self):
""" Returns the central point of all units in this list """
assert self.exists
- pos = Point2((sum([unit.position.x for unit in self]) / self.amount, \
- sum([unit.position.y for unit in self]) / self.amount))
+ pos = Point2((sum({unit.position.x for unit in self}) / self.amount, \
+ sum({unit.position.y for unit in self}) / self.amount))
return pos
@property
