summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpitfireX <timm.weber@me.com>2015-08-12 01:59:48 +0200
committerSpitfireX <timm.weber@me.com>2015-08-12 01:59:48 +0200
commitd0f7aa9e680df92e16a31c139bab76d4ee23b208 (patch)
treed9c4c3d199be62dfaa81077cece9dc50a35cfad2
parent4f6736ac0d40b38b73ba5edbece6c9474dd352d1 (diff)
A minor target locking fix.
Cell could stay locked onto an "edible" cell even after it has become inedible.
-rw-r--r--strategy.py7
1 files 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)