From f99e10cff97afdc3e6ef07db22cf5f7fd442e067 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 24 Aug 2015 02:33:36 +0200 Subject: WIP --- pathfinding.py | 24 ++++++++++++++---------- 1 file 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)) -- cgit v1.2.3