1.0.4 • Published 3 years ago

path-astar v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

path-astar

A*(a-star) pathfinding in TypeScript

Installation

 npm i path-astar
 import PathAstar from "path-astar";

npm.io

Usage

var maps=[
        [0,0,1],
        [0,1,1],
        [0,0,0],
        [0,1,0]
    ];

var astar=new PathAstar(maps);

astar.setStart(1,0)
     .setEnd(2,3)
     .track(function (paths) {
         console.log(paths);
     },function(){
         // fail
     });
var maps=[
        [0,0,0],
        [0,0,0],
        [0,0,0],
        [0,0,0]
    ];

var astar=new PathAstar(maps);
var wallsNum=4;

astar.randomAll(wallsNum);

// console.log(astar.startNode);
// console.log(astar.endNode);
// astar.obstacleList.forEach(function (index) {
//     var coord = astar.index2Coord(index);
// });
astar.track(function (paths) {
         console.log(paths);
     },function(){
         // fail
     });

METHODS

constructor(maps:Array<Array<0|1>>);

setStart(x:number,y:number):PathAstar;

setEnd(x:number,y:number):PathAstar;

randomAll(wallsNum:number):PathAstar;

track(
    success:(paths:{x:number,y:number}[])=>void,
    fail?:()=>void
):PathAstar;

coord2Index(x:number, y:number):number;
index2Coord(index:number):{x:number,y:number};
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago