Skip to content

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@devlsh/astar

A* pathfinding for 2D grids with elevation support.


NPM Downloads GitHub Stars Build Status Software License


  • 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.

Installation

$ npm install @devlsh/astar

Usage

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);

Contributing

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.

License

@devlsh/astar is free and open-source software licensed under the MIT License.


devlsh.com  ·  GitHub: @devlsh  ·  X: @itsdevlsh

About

A* pathfinding for 2D grids with elevation support.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

12 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages