From f9e8d80441902561f3e7d1f1e46588543f7e5535 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 18 Aug 2015 17:49:05 +0200 Subject: performance optimisation. lol :D --- pathfinding.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pathfinding.py b/pathfinding.py index 11d698f..662ecfe 100644 --- a/pathfinding.py +++ b/pathfinding.py @@ -85,12 +85,15 @@ class PathfindingTesterStrategy: goaly = int((marker[0][1] - self.c.player.center[1] + grid_radius)/grid_density) grid = [] + + interesting_cells = list(filter(lambda c : not c.is_food, self.c.player.world.cells.values())) + for x in range(-grid_radius,grid_radius+1,grid_density): gridline = [] for y in range(-grid_radius,grid_radius+1,grid_density): val = 0 - for cell in self.c.player.world.cells.values(): + for cell in interesting_cells: relpos = (cell.pos.x - (x+self.c.player.center.x), cell.pos.y - (y+self.c.player.center.y)) dist_sq = relpos[0]**2 + relpos[1]**2 if dist_sq < cell.size**2 *3: -- cgit v1.2.3