Darmyn
Help understanding some code
I am following along with a tutorial on YouTube for AStar. There is one portion of the code that does not make sense. I will do my best to highlight the code and explain why it does not make sense.
First, we take a look at the node class. From my understanding of this code (I am not fluent in CS) it seems like g and h cost are left uninitialized.
https://github.com/SebLague/Pathfinding/blob/master/Episode%2003%20-%20astar/Assets/Scripts/Node.cs
Knowing that gCost and hCost are never initialized, I assume that it is initialized later on. But I can not seem to find where this happens.
In the main pathfinding function for AStar implementation, the code magically used the gCost value in an evaluation (Line 46). But how could it exist? Furthermore, let's consider it was magically initialized to some arbitrary number, that doesn't represent a valid gCost in the aStar algorithm. Realistically the gCost would not be known until a neighbour observed it... https://github.com/SebLague/Pathfinding/blob/master/Episode%2003%20-%20astar/Assets/Scripts/Pathfinding.cs
13 replies