Note: Trekker is currently in a prerelease state and is therefore subject to frequent (sometimes undocumented) breaking changes.
npm i trekker -S
Trekker can be used on both the client- and server-side:
import Trekker from 'trekker';
const grid = [
[ 1, 1, 1 ],
[ 1, 0, 1 ],
[ 1, 1, 1 ],
];
const path = new Trekker(grid);
.search(0, 0, 0, 2);
The goal of the public API is to be chainable in any configuration. A notable exception to this, however, is Trekker.search
which will terminate the chain as it returns a solution path instead of the Trekker object.
- x1 (Number) — x position of the starting position
- y1 (Number) — y position of the starting position
- x2 (Number) — x position of the end position
- y2 (Number) — y position of the end position
Returns an Array
of Node
s representing the solution path. If no path is found, an empty Array
is returned.
- mode (Number) — A value representing the diagonal mode to use. The following options are available from
Trekker.DIAGONAL_MODE
:NEVER
— Disable diagonal movement (default)ALWAYS
— Allow diagonal movement regardless of obstaclesONE_OBSTACLE
— Allow diagonal movement with at most one obstacleNO_OBSTACLES
— Allow diagonal movement only when there are no obstacles
Returns a Trekker
object for chaining.
- fn(current, neighbour): Boolean (Function) — A custom function to use for additional consideration when processing a neighbour tile
Returns a Trekker
object for chaining.
Returns a String
representing a solution path. An example output from the Usage section would be:
'[1,0],[2,0]'
Note: This is primarly a utility for testing.
- Customize acceptable tiles per instance
- Performance optimizations