fast-astar
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/fast-astar package

1.0.6 • Public • Published

fast-astar

fast-astar is an implementation of a* algorithm using javascript. Small and fast.

Use

Install fast-astar using npm or introduce Grid.js and Astar.js on the page

Install:

npm install fast-astar --save

Install:

import {Grid,Astar} from "fast-astar";
 
// Create a grid
let grid = new Grid({
        col:11,                  // col
        row:7,                   // row
        render:function(){       // Optional, this method is triggered when the grid point changes
            // console.log(this);
        }
    });
 
// Add obstacles to the grid
[[5,2],[5,3],[5,4]].forEach(item => {
    grid.set(item,'value',1);    // Values greater than 0 are obstacles
});
 
// Pass the grid as a parameter to the Astar object
let astar = new Astar(grid),
    path = astar.search(
        [2,3],                   // start
        [8,3],                   // end
        {                        // option
            rightAngle:false,    // default:false,Allow diagonal
            optimalResult:true   // default:true,In a few cases, the speed is slightly slower
        }
    );
 
console.log('Result',path);      // [[2,3],[3,2],[4,1],[5,1],[6,1],[7,2],[8,3]]

Demo

Related

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.6
    3,270
    • latest

Version History

Package Sidebar

Install

npm i fast-astar

Weekly Downloads

3,277

Version

1.0.6

License

MIT

Unpacked Size

7.27 kB

Total Files

6

Last publish

Collaborators

  • sbfkcel