starting point on the grid
destination point on the grid
size of the grid
used to determine if the tile at the given coordinates are passible
weight function to the A* algorithm. If null, assumes all will be equal weight. Returned value must be greater than or equal to 1.
heuristic function to the A* algorithm. Gives an estimation of how many steps away the goal is from the given point to speed up the search. If null, assumes "taxicab distance"; the number of steps based solely on distance without diagonal movement. If you want to disable this entirely, pass p => 0.
A list of waypoints to reach the destination, or null if impossible. The waypoints are returned in reverse order, starting from the goal and working back to the start.
So to get to the goal from the starting point, follow the returned array in backwards.
The waypoints will not necessarily include every step but also may not only list turns, but if you follow them you will get get to the destination.
The current implementation uses more memory than it really has to; it will eat like 8 MB of scratch space RAM on a 512x512 grid.
It doesn't consider wraparound possible so it might ask you to go all the way around the world unnecessarily.
Added May 2, 2020.
Implements the A* path finding algorithm on a grid.