1.0.5 • Published 5 years ago

easy-astar v1.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

easy-astar

An a* search path library.!

Usage

// require js file
const easyAStar = require("easy-astar").easyAStar;

// your custom data, 0 means road, 1 means wall.
const map = [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]

// find path 0,0 to 9,9
const startPos = {x:0,y:0};
const endPos = {x:9,y:9};
const result = easyAStar((x, y)=>{
    if (map[x] && map[x][y] === 0) {
        return true; // 0 means road
    } else {
        return false; // 1 means wall
    }
}, startPos, endPos);
console.log(result);

TypeScript support

yes

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago