A* Pathfinding Java Not Working Properly
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
Solution 1:
I think the issue is in this part of the code:
protected List<Node> generateSuccessors(Node node){
List<Node> ret = new LinkedList<Node>();
int x = node.x;
int y = node.y;
if(y < map.length - 1 && map[y+1][x] == 1)
ret.add(new Node(x, y+1));
if(x < map[0].length - 1 && map[y][x+1] == 1)
ret.add(new Node(x+1, y));
return ret;
}
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.
if(y > 0 && map[y-1][x] == 1)
ret.add(new Node(x, y-1));
if(x > 0 && map[y][x-1] == 1)
ret.add(new Node(x-1, y));
Post a Comment for "A* Pathfinding Java Not Working Properly"