An AyStar implementation.
More...
Public Member Functions |
function | GetAuthor () |
function | GetName () |
function | GetShortName () |
function | GetDescription () |
function | GetVersion () |
function | GetDate () |
function | CreateInstance () |
function | GetCategory () |
constructor | AyStar (pf_instance, cost_callback, estimate_callback, neighbours_callback, check_direction_callback) |
function | InitializePath (sources, goals, ignored_tiles=[]) |
| Initialize a path search between sources and goals.
|
function | FindPath (iterations) |
| Try to find the path as indicated with InitializePath with the lowest cost.
|
Detailed Description
An AyStar implementation.
It solves graphs by finding the fastest route from one point to the other.
Constructor & Destructor Documentation
constructor AyStar::AyStar |
( |
pf_instance |
, |
|
|
cost_callback |
, |
|
|
estimate_callback |
, |
|
|
neighbours_callback |
, |
|
|
check_direction_callback |
|
|
) |
| |
|
inline |
- Parameters
-
pf_instance | An instance that'll be used as 'this' for all the callback functions. |
cost_callback | A function that returns the cost of a path. It should accept four parameters, old_path, new_tile, new_direction and cost_callback_param. old_path is an instance of AyStar.Path, and new_node is the new node that is added to that path. It should return the cost of the path including new_node. |
estimate_callback | A function that returns an estimate from a node to the goal node. It should accept four parameters, tile, direction, goal_nodes and estimate_callback_param. It should return an estimate to the cost from the lowest cost between node and any node out of goal_nodes. Note that this estimate is not allowed to be higher than the real cost between node and any of goal_nodes. A lower value is fine, however the closer it is to the real value, the better the performance. |
neighbours_callback | A function that returns all neighbouring nodes from a given node. It should accept three parameters, current_path, node and neighbours_callback_param. It should return an array containing all neighbouring nodes, which are an array in the form [tile, direction]. |
check_direction_callback | A function that returns either false or true. It should accept four parameters, tile, existing_direction, new_direction and check_direction_callback_param. It should check if both directions can go together on a single tile. |
Member Function Documentation
function AyStar::FindPath |
( |
iterations |
| ) |
|
Try to find the path as indicated with InitializePath with the lowest cost.
- Parameters
-
iterations | After how many iterations it should abort for a moment. This value should either be -1 for infinite, or > 0. Any other value aborts immediatly and will never find a path. |
- Returns
- A route if one was found, or false if the amount of iterations was reached, or null if no path was found. You can call this function over and over as long as it returns false, which is an indication it is not yet done looking for a route.
function AyStar::InitializePath |
( |
sources |
, |
|
|
goals |
, |
|
|
ignored_tiles |
= [] |
|
) |
| |
Initialize a path search between sources and goals.
- Parameters
-
sources | The source nodes. This can an array of either [tile, direction]-pairs or AyStar.Path-instances. |
goals | The target tiles. This can be an array of either tiles or [tile, next_tile]-pairs. |
ignored_tiles | An array of tiles that cannot occur in the final path. |
The documentation for this class was generated from the following files: