the astar library is working fine
Was my fault, when i see the Demo, in a visual way it seems to be wrong because it work in a different way when finds a path under or over a diagonal wall, but it seems to be only an ilussion because of the way the map is draw, sorry for the time, thanks(log in to comment)
Comments
whoops, the secong to last line of the hack should look like this:
n = self._handleNode(cl.x+1,cl.y-1,curnode,dl.x,dl.y)
meaning that cl.y should -= 1 not += 1
Sorry about that
n = self._handleNode(cl.x+1,cl.y-1,curnode,dl.x,dl.y)
meaning that cl.y should -= 1 not += 1
Sorry about that
I think this is neater:
def getAdjacentNodes(self, curnode, dest):
"""MUST BE IMPLEMENTED"""
result = []
cl = curnode.location
dl = dest
for xm in range(-1,2):
for ym in range(-1,2):
if xm == ym == 0: continue
n = self._handleNode(cl.x + xm,cl.y + ym,curnode,dl.x,dl.y)
if n: result.append(n)
return result
Or, the slightly-faster:
for xm in (-1, 0, 1):
for ym in range(-1, 0, 1):
Clearly that second line shouldn't have range in it :)
RB[0] on
2006/09/06 01:05:
But if you want to move diagonally here is a hack that will count diagonal movements as just as expensive as normal movements:Line 154 of AStar
change the following code block to this:
n = self._handleNode(cl.x+1,cl.y,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x-1,cl.y,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x,cl.y+1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x,cl.y-1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x+1,cl.y+1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x-1,cl.y+1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x-1,cl.y-1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x+1,cl.y+1,curnode,dl.x,dl.y)
if n: result.append(n)
Instead of this:
n = self._handleNode(cl.x+1,cl.y,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x-1,cl.y,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x,cl.y+1,curnode,dl.x,dl.y)
if n: result.append(n)
n = self._handleNode(cl.x,cl.y-1,curnode,dl.x,dl.y)
if n: result.append(n)
Then AStar will return diagonal nodes too, instead of just regular ones.