I am creating a Maze game in java and wants to add a smarty ghost (like Pacman) that move towards user location to catch him. For smarty ghost I chose A* PathFinding Algorithm and found below links for implementing this algorithm :
https://code.google.com/p/a-star/source/browse/trunk/java/PathFinder.java?r=8
https://code.google.com/p/a-star/source/browse/trunk/java/AStar.java?r=8
But the code is not completely working properly , I mean the code only seems to find paths going from top left to bottom right, not for example left - right - left - left down .
for e.g :
if
source = (0,0)
Destination = (8,8) // works perfectly..
if
source = (8,8)
Destination = (0,0) // doesn't work :(
Please help me to correct this code or give useful link for implementing this.
I think the issue is in this part of the code:
This code is returning a list of neighbours for the current node, however it only tries down and right directions. Try adding corresponding code for any other directions you wish to follow, e.g.