A* scanning extra nodes?

Started by
22 comments, last by polyfrag 8 years, 11 months ago
Try logging every node that's checked. Especially the node that's not supposed to be checked according to the website you mentioned.

Yours definitely looks like Manhattan heuristic, but the one from the website looks more like Euclidean distance, because not every node within a rectangle formed by the goal and start has an equal chance of being checked. So it might be a matter of the order in which you expand your search or use of diagonal moves. Try using something other than Manhattan distance.

[edit] Seems like you don't allow diagonal moves, which would explain why yours makes the square shape. It would approach the goal quicker if you allowed diagonals.
Advertisement

I give up. I have been working on this for almost a week and I'm no where close to solving this..... I don't know what to do.....

Also, sometimes it's best to just toss it on the backlog. Your current implementation works, it has a bug, but it's not gamebreaking. Log it, give it a priority, and return to it after a while. I've come back to a problem at a later time with a fresh perspective and sometimes that can help if I've been blocked and pulling my hair out.

This if statement is never true....


if (OpenList.SingleOrDefault(node => node.Position == Neighbor.Position).G_Vaule + G_Score < CurrentNode.G_Vaule)

Off top of my head I think the check should be

if (OpenList.SingleOrDefault(node => node.Position == Neighbor.Position).G_Vaule + G_Score > CurrentNode.G_Vaule)

I need to check my a* code when I get home tonight but don't you want to subst the value in the open list if the old path for the location is more costly than the one you have. Given that the nodes hold the route back your test is saying replace the cheaper one with the more costly?

EDIT: Just done some digging and am sure you always want the cheapest version of a node for a given location while your condition will swap out a cheaper for a more expensive node. Not run your code but thing you should start there

It's only counting the distance to the goal, and not the distance traversed. What is G_score and H_score measured in?


                            Neighbor.Parent = CurrentNode;
                            Neighbor.G_Vaule = CurrentNode.G_Vaule + G_Score;
                            Neighbor.H_Value = GetHeuristicCost(Neighbor);
                            OpenList.Add(Neighbor);


        const int G_Score = 10;
        const int Diagonal_G_Score = 14;

The heuristic H_score might be 100 times bigger.

[edit] Nevermind.

The F_score is basically = distance to goal + distance from start, and since it's Manhattan, any cell within the square formed by the start and goal might be picked. Any path taken to get 3 squares right and 2 squares up is equally valid.

There are several equally-low F_score squares in the open list, so it's just a matter of whether you choose the ones farthest to the back, or the front. Yours chooses the ones closest to the back (i.e., the ones that are the oldest). Which makes it closer to breadth first search, then depth first search.

This is actually pretty important. If you use a min binary heap, nodes pushed to the top that are equal or less will stay and the top and thus be the first popped.

This topic is closed to new replies.

Advertisement