A* PathFinding Not Consistent

Posted by RedShft on Game Development See other posts from Game Development or by RedShft
Published on 2012-04-02T06:32:04Z Indexed on 2012/04/02 11:44 UTC
Read the original article Hit count: 171

Filed under:
|
|

I just started trying to implement a basic A* algorithm in my 2D tile based game. All of the nodes are tiles on the map, represented by a struct. I believe I understand A* on paper, as I've gone through some pseudo code, but I'm running into problems with the actual implementation. I've double and tripled checked my node graph, and it is correct, so I believe the issue to be with my algorithm.

This issue is, that with the enemy still, and the player moving around, the path finding function will write "No Path" an astounding amount of times and only every so often write "Path Found". Which seems like its inconsistent.

This is the node struct for reference:

struct Node
{
bool walkable;      //Whether this node is blocked or open
vect2 position;     //The tile's position on the map in pixels
int xIndex, yIndex; //The index values of the tile in the array
Node*[4] connections; //An array of pointers to nodes this current node connects to
Node* parent;
int gScore;
int hScore;
int fScore;
}

Here is the rest: http://pastebin.com/cCHfqKTY

This is my first attempt at A* so any help would be greatly appreciated.

© Game Development or respective owner

Related posts about ai

Related posts about path-finding