Jump to content
  • Advertisement
Sign in to follow this  
atcdevil

A* path reconstruction

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I implemented A* based on the wikipedia.org article. It states: "This path reconstruction from the stored closed nodes (see below) means it is not necessary to store the path-so-far within each node." But below that line there is no mention of how to reconstruct the path. So how do I reconstruct the path from the 'closed' priority queue without storing the path so far in each node?

Share this post


Link to post
Share on other sites
Advertisement
You "traverse in reverse". Whenever you create a node, store its parent node. When you find the node that's at the target position, go into a loop that backtracks the list of nodes (using 'node->parent') until it reaches the first node, adding each node to a list. Then just reverse the list so the path is in the correct order (or if you like you can just go backwards through the list whenever you're making things actually follow the path)

if (node->x == target_x && node->y == target_x) {
while (node != first_node) {
list[list_pos++] = node;
node = node->parent;
}

reverse(list);
}


Hope this helps!

Share this post


Link to post
Share on other sites
that does, thank you very much.

although that solution is sufficient. is it possible to reconstruct the path without even storing the parent?

Share this post


Link to post
Share on other sites
Not sure, but I would guess not. If you're trying to optimise for size, I think the best you can get away with is storing the parent as a reference to an array element rather than a pointer.

Edit: You could always try different things, like running the pathfinder in reverse, and restrict it to the nodes already created by the first run. Not sure what results that would produce, though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!