Permalink
Browse files

Further A*star optimisations.

  • Loading branch information...
1 parent 538e102 commit 9bda49f4ce2f58f9514e0fef485fdb5cc562b711 @Aramgutang committed Jan 29, 2011
Showing with 10 additions and 8 deletions.
  1. +4 −2 lingua/__init__.py
  2. +0 −2 lingua/entities/player.py
  3. +3 −3 lingua/utils/aramstar.py
  4. +3 −1 requirements.txt
View
@@ -1,5 +1,6 @@
from operator import concat
+from numpy import array
import pygame
from pgu import algo, engine
@@ -15,9 +16,10 @@ def __init__(self, screen):
width, height = levels_image.get_size()
white = pygame.color.Color(255,255,255,255)
#black = pygame.color.Color(0,0,0,255)
- self.levels = [[levels_image.get_at((x,y)) == white \
+ self.levels = array([[levels_image.get_at((x,y)) == white \
for y in range(height)] \
- for x in range(width)]
+ for x in range(width)],
+ dtype=bool)
# Initialise player
self.player = Player(self.levels)
# Populate sprites
@@ -14,8 +14,6 @@ def __init__(self, levels):
self.path = []
def walk(self, target):
- if self.levels[target[0]][target[1]]:
- print 'On a path!'
self.path = aramstar(self.rect.midbottom, target, self.levels)
if not self.path:
self.path = getline(self.rect.midbottom, target)
@@ -8,7 +8,7 @@ def directions(dx, dy):
Returns the optimal order of directions to search in.
Comments assume (1,1) is North-East.
"""
- if abs(dx) < abs(dy/2.0):
+ if abs(dy*2) > abs(dx):
if dy > 0:
if dx > 0:
return [(0,-1),(-1,-1),(1,-1),(-1,0),(1,0),(-1,1),(1,1),(0,1)] #NNE
@@ -30,7 +30,7 @@ def directions(dx, dy):
return [(-1,1),(0,1),(-1,0),(1,1),(-1,-1),(1,0),(0,-1),(1,-1)] #SEE
else:
return [(1,1),(0,1),(1,0),(-1,1),(1,-1),(-1,0),(0,-1),(-1,-1)] #SWW
- elif abs(dy) < abs(dy/2.0):
+ elif abs(dy*2) > abs(dy):
if dy > 0:
if dx > 0:
return [(-1,0),(-1,-1),(-1,1),(0,-1),(0,1),(1,-1),(1,1),(1,0)] #EEN
@@ -54,7 +54,7 @@ def directions(dx, dy):
return [(1,1),(1,0),(0,1),(1,-1),(-1,1),(0,-1),(-1,0),(-1,-1)] #WSS
def traversable(levels, x, y,):
- return x >= 0 and x < len(levels) and y >= 0 and y < len(levels[0]) and levels[x][y]
+ return x >= 0 and x < levels.shape[0] and y >= 0 and y < levels.shape[1] and levels[x,y]
class Node(object):
def __init__(self, start, end, levels, length=0, parent=None):
View
@@ -1,2 +1,4 @@
pygame==1.9.1
-pgu==0.14
+pgu==0.14
+psyco==2.0.0
+numpy==1.5.1

0 comments on commit 9bda49f

Please sign in to comment.