From d0f7aa9e680df92e16a31c139bab76d4ee23b208 Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Wed, 12 Aug 2015 01:59:48 +0200 Subject: A minor target locking fix. Cell could stay locked onto an "edible" cell even after it has become inedible. --- strategy.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/strategy.py b/strategy.py index b98be3c..92e0ad2 100644 --- a/strategy.py +++ b/strategy.py @@ -63,9 +63,11 @@ class Strategy: # if however there's no enemy to avoid, chase food or jizz randomly around else: + def edible(cell): return (cell.is_food) or (cell.mass <= sorted(c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75) and not (cell.is_virus) + if self.target_cell != None: self.target = tuple(self.target_cell.pos) - if self.target_cell not in c.world.cells.values(): + if self.target_cell not in c.world.cells.values() or not edible(self.target_cell): self.target_cell = None self.has_target = False print("target_cell does not exist any more") @@ -74,8 +76,7 @@ class Strategy: print("Reached random destination") if not self.has_target: - def eatable(cell): return (cell.is_food) or (cell.mass <= sorted(c.player.own_cells, key = lambda x: x.mass)[0].mass * 0.75) and not (cell.is_virus) - food = list(filter(eatable, c.world.cells.values())) + food = list(filter(edible, c.world.cells.values())) def dist(cell): return math.sqrt((cell.pos[0]-c.player.center[0])**2 + (cell.pos[1]-c.player.center[1])**2) food = sorted(food, key = dist) -- cgit v1.2.3