summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-24 02:33:36 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-24 02:33:36 +0200
commitf99e10cff97afdc3e6ef07db22cf5f7fd442e067 (patch)
tree51594e90655eb7f6b6cc589351d4919d89d975d1
parente17f82c366fdbcce75c0033f28c26f522677da64 (diff)
WIP
-rw-r--r--pathfinding.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/pathfinding.py b/pathfinding.py
index 13ee774..beec89a 100644
--- a/pathfinding.py
+++ b/pathfinding.py
@@ -16,8 +16,6 @@ class Node:
def move_cost(self,other):
# assert other in siblings(self,grid). otherwise this makes no sense
- # assert that siblings are only in horizontal or vertical directions. otherwise
- # someone must replace the number "1" by appropriate distances
return distance(self, other) + (self.value + other.value)/2
def siblings(point,grid):
@@ -82,24 +80,30 @@ class PathfindingTesterStrategy:
self.path = None
def build_grid(self):
- grid = [[None for x in range(int(2*grid_radius//grid_density+1))] for x in range(int(2*grid_radius//grid_density+1))]
+ grid = [[0 for x in range(int(2*grid_radius//grid_density+1))] for x in range(int(2*grid_radius//grid_density+1))]
interesting_cells = list(filter(lambda c : not (c.is_food or c in self.c.player.own_cells), self.c.player.world.cells.values()))
- for x in range(-grid_radius,grid_radius+1,grid_density):
- gridx = (x+grid_radius) // grid_density
- for y in range(-grid_radius,grid_radius+1,grid_density):
- gridy = (y+grid_radius) // grid_density
- val = 0
+ for cell in interesting_cells:
+ for x in range(-grid_radius,grid_radius+1,grid_density):
+ gridx = (x+grid_radius) // grid_density
+ for y in range(-grid_radius,grid_radius+1,grid_density):
+ gridy = (y+grid_radius) // grid_density
- 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:
- val += 100000000
+ grid[gridx][gridy] += 100000000
+
+ for x in range(-grid_radius,grid_radius+1,grid_density):
+ gridx = (x+grid_radius) // grid_density
+ for y in range(-grid_radius,grid_radius+1,grid_density):
+ gridy = (y+grid_radius) // grid_density
if (gridx in [0,len(grid)-1] or gridy in [0, len(grid[gridx])-1]):
val = None
+ else:
+ val = grid[gridx][gridy]
grid[gridx][gridy] = Node(val, (self.c.player.center[0]+x,self.c.player.center[1]+y), (gridx, gridy))