A* pathfinding for 2D grids with elevation support.
- Interactive demo.
- A* pathfinding on 2D grids.
- Grids with numeric elevation values or configurable tile objects.
- Optional diagonal movement and corner-cutting prevention.
- Configurable maximum elevation change per move.
- Includes built-in Diagonal and Manhattan heuristics, fully customizable.
- Zero runtime dependencies.
$ npm install @devlsh/astar
Find a path from [0, 0] to [3, 3].
import { search, type Grid } from '@devlsh/astar'; /** * Numbers >= 0 specify elevation. * * 0 = ground * -1 = blocked/no tile * >= 1 = elevated tile */ const grid: Grid = [ [0, 0, 0, 0], [0, -1, -1, 1], [0, 0, 1, 1], [0, 0, 1, 2], ]; const path = search({ grid, // Coordinates are `[x, y]` vectors. from: [0, 0], to: [3, 3], // Maximum elevation change per move. stepHeight: 1, diagonal: true, cutCorners: false, }); /** * The path includes both endpoints. * If no path is found, the result is null. */ console.log(path);
Report bugs through issues or ask questions in Discussions. Report vulnerabilities privately as described in SECURITY.md.
For local development, pull requests, and other contributions, see the Contributing Guidelines.
@devlsh/astar is free and open-source software licensed under the MIT License.
devlsh.com · GitHub: @devlsh · X: @itsdevlsh