A* problem whit path

hello everyone, I have a problem with the A * algorithm (astar). It 'the first time you try to implement. From how I’m doing, the algorithm does not always find the shortest path. The figure I am attaching, the algorithm should follow the green line instead follows the blue line and then to your destination takes nodes that do not serve. Someone can help me?
I use this line code to take the node with value “F” min in the open list

 Node currentNode = openList.OrderByDescending(minValue => minValue.F).Last();

I mean other than being a slower method of finding the minimum value (you’re sorting before grabbing, a for loop would be faster), overall that single line of code has nothing wrong with it. It gives you the node with the smallest F.

So, your problem may be related to something else. What does your entire algorithm look like? And what does your graph look like? Do you have edge weights (sometimes graphs add weight to nodes that are near walls to generate a path where AI doesn’t hug walls)?

Furthermore, is there a reason you’re avoiding using any 3rd party A* algorithms?

I for one use the Aron Granberg solution:
http://arongranberg.com/astar/

It’s a very competent solution that is speedy. Why reinvent the wheel when one already exists…

1 Like