We'll lay out the basic structure of the A* search, looking for the point of the current search border likeliest to be closest to the destination, checking to see if any of them offer a faster route to known spaces, and whether or not we have reached our target.
We'll start by laying out the generic skeleton of an A* implementation.
In addition to a start position, a goal position, a progress function, and a heuristic function, A* needs to create two things internally to do its job—a list of spaces currently on the border of its search, and the known costs to reach them, and a list of the spaces that the search has determined which are in the best path to any given known space using the following code:
return function(start, goal, neighbors, h) local costs = {[start] = 0} local parents = {} end