Skip to content

SanjoSolutions/a-star

 
 

Repository files navigation

javascript-astarf (fork of bgrins/javascript-astar)

About

An implementation of the A* search/pathfinding algorithm in JavaScript. Supports diagonal movement and weighted nodes.

See a demo at http://www.briangrinstead.com/files/astar/

This is a improved and modernized fork of bgrins/javascript-astar.

How to use

Get started

  1. Npm install (link)

    npm install javascript-astarf
  2. Minimal example

    // Module import
    import { AStar, Grid } from "javascript-astarf"
    
    // 0 = wall, 1 = walkable
    const grid = new Grid([
        [1, 0],
        [1, 1],
    ])
    
    // Search for path
    const result = AStar.search(grid, [0, 0], [1, 1])
    // result.length == 2
    // result[0] == { x: 1, y: 0, weight: 1 }
    // result[1] == { x: 1, y: 1, weight: 1 }

Examples

Se the astar-examples.test.js file for further examples on how to use this library

Weights

Se the astar-examples.test.js file for example

  • A weight of 0 denotes a wall.
  • A weight cannot be negative.
  • A weight cannot be between 0 and 1 (exclusive).
  • A weight can contain decimal values (greater than 1).

Development

Setup

  1. Install node 22+
  2. npm install
  3. npm run test

Open demo page

Simply open the web/index.html file in your browser.

Lint code

Run lint.ps1 on windows

About

A* search/pathfinding algorithm in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 56.9%
  • CSS 31.4%
  • HTML 11.2%
  • Other 0.5%