The A* pathfinding algorithm.
A path is a List of Positions.
Find a path between the start and end Positions. You must
supply a cost function and a move function.
The cost function must estimate the distance between any two positions. It doesn't really matter how accurate this estimate is, as long as it never underestimates.
The move function takes a Position and returns a Set of possible
places you can move to in one step.
If this function returns Nothing, there is no path between the two
points. Otherwise it returns Just an Array of steps from start
to end.
Example usage.
import AStar exposing (..)
findPath horizontalCost movesFrom ( 0, 0 ) ( 2, 0 )
--> Just [ ( 1, 0 ), ( 2, 0 ) ]A simple costing algorithm. Think of it as the number of moves a rook/castle would have to make on a chessboard. Even if your piece can move diagonally it will still work! A* only requires that the cost function never underestimates.
An alternative costing algorithm, which calculates pythagorean distance.
A position is just a pair of (x,y) coordinates.