So I'm currently working on Pathfinding for my game using A*, currently it makes the path but the path is very incorrect. I will crudely draw the path it creates:
Start Node
Second Node
Third Node
Fourth Node Sixth Node
Fifth Node Seventh Node
Eighth Node Tenth Node
Ninth Node Eleventh Node
End Node
After going through with the debugger I determined that at the fifth node, the Top Right, Right and Bottom Right Nodes all shared the exact same fCost. At this point I can only assume it has to do with the result of my getH
function. Here it is:
public int getH(int row, int col, Node goal)
{
return (int)Math.sqrt((goal.row - row) * (goal.row - row) + (goal.col - col) * (goal.col - col));
}
So my question is, what am I doing wrong here?
On smaller tests (less nodes) I don't run into this issue where it only uses diagonals. Also the functionality to go around obstacles is not implemented, so that's not what is happening.