Class engine.Astar
Pathfinding using A*
Methods
engine.Astar:init (map, actor)
Initializes Astar for a map and an actor
engine.Astar:heuristicCloserPath (sx, sy, cx, cy, tx, ty)
The default heuristic for A*, tries to come close to the straight path
engine.Astar:heuristicDistance (sx, sy, cx, cy, tx, ty)
A simple heuristic for A*, using distance
engine.Astar:toSingle (x, y)
Converts x & y into a single value
engine.Astar:toDouble (c)
Converts a single value back into x & y
engine.Astar:createPath (came_from, cur)
Create Path
engine.Astar:calc (sx, sy, tx, ty, use_has_seen[, heuristic=`heuristicCloserPath`][, add_check=true], forbid_diagonals)
Compute path from sx/sy to tx/ty
Methods
- engine.Astar:init (map, actor)
-
Initializes Astar for a map and an actor
Parameters:
- engine.Astar:heuristicCloserPath (sx, sy, cx, cy, tx, ty)
-
The default heuristic for A*, tries to come close to the straight path
Parameters:
- sx int
- sy int
- cx int
- cy int
- tx int
- ty int
- engine.Astar:heuristicDistance (sx, sy, cx, cy, tx, ty)
-
A simple heuristic for A*, using distance
Parameters:
- sx int
- sy int
- cx int
- cy int
- tx int
- ty int
- engine.Astar:toSingle (x, y)
-
Converts x & y into a single value
Parameters:
- x int
- y int
See also:
- engine.Astar:toDouble (c)
-
Converts a single value back into x & y
Parameters:
- c int
See also:
- engine.Astar:createPath (came_from, cur)
-
Create Path
Parameters:
- came_from
- cur
- engine.Astar:calc (sx, sy, tx, ty, use_has_seen[, heuristic=`heuristicCloserPath`][, add_check=true], forbid_diagonals)
-
Compute path from sx/sy to tx/ty
Parameters:
- sx int x of the start coord
- sy int y of the start coord
- tx int x of the end coord
- ty int y of the end coord
- use_has_seen boolean if true the astar wont consider non-has_seen grids
- heuristic func The heuristic to use (default `heuristicCloserPath`)
- add_check func a function that checks each x/y coordinate and returns true if the coord is valid (default true)
- forbid_diagonals optional boolean if they can't move diagonally
Returns:
-
nil if no path is found
Or
-
list of nodes in the form { {x=...,y=...}, {x=...,y=...}, ..., {x=tx,y=ty}}