'Astar can't get the optimal solution

As shown in the figure, based on the connotation of Astar, the point closer to the end point will be preferred, so the optimal path cannot be obtained. [1]: https://i.stack.imgur.com/SbKSE.png



Solution 1:[1]

It looks like you are connecting diagonal edges with the same length as horizontal/vertical edges, in which case this is a correct solution.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BlueRaja - Danny Pflughoeft