The A-Star 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 overestimates.
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 a List of steps from start
to end.
Example usage.
import AStar exposing (..)
type World =
...your custom code...
movesFrom : World -> Position -> Set Position
movesFrom world (x,y) =
...your custom code...
findPath
straightLineCost
(movesFrom currentWorld)
( 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.
An alternative costing algorithm, which calculates pythagorean distance.
A position is just a pair of (x,y) coordinates.