summaryrefslogtreecommitdiff
path: root/pathfinding.py
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-21 17:10:15 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-21 17:10:15 +0200
commitf55bb646dce93b36139bbaa7b1bccda10eda7f96 (patch)
tree707de75db041b4a2ca1d86e79c038573ab60e837 /pathfinding.py
parentc4104a5cd33275c0ae79530e182c4538c9d3f2f3 (diff)
refactor
Diffstat (limited to 'pathfinding.py')
-rw-r--r--pathfinding.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/pathfinding.py b/pathfinding.py
index 2b6a7aa..ed5a247 100644
--- a/pathfinding.py
+++ b/pathfinding.py
@@ -81,10 +81,7 @@ class PathfindingTesterStrategy:
self.c = c
self.path = None
- def plan_path(self):
- goalx = int((marker[0][0] - self.c.player.center[0] + grid_radius)/grid_density)
- goaly = int((marker[0][1] - self.c.player.center[1] + grid_radius)/grid_density)
-
+ def build_grid(self):
grid = []
interesting_cells = list(filter(lambda c : not (c.is_food or c in self.c.player.own_cells), self.c.player.world.cells.values()))
@@ -103,6 +100,14 @@ class PathfindingTesterStrategy:
gridline.append(Node(None if (x in [-grid_radius,grid_radius] or y in [-grid_radius,grid_radius]) else val, (self.c.player.center[0]+x,self.c.player.center[1]+y), (int((x+grid_radius)/grid_density), int((y+grid_radius)/grid_density))))
grid.append(gridline)
+ return grid
+
+ def plan_path(self):
+ goalx = int((marker[0][0] - self.c.player.center[0] + grid_radius)/grid_density)
+ goaly = int((marker[0][1] - self.c.player.center[1] + grid_radius)/grid_density)
+
+ grid = self.build_grid()
+
path = aStar(grid[int(grid_radius/grid_density)][int(grid_radius/grid_density)], grid[goalx][goaly], grid)
return path