PathfindingJS is a JavaScript library that implements different algorithms to find the shortest path in a grid map between two nodes.
You can install the library using Yarn:
yarn add demyanovs/pathfinding-js
Or using npm:
npm install demyanovs/pathfinding-js
PathfindingJS is available as a JavaScript module for both the browser and Node.js.
- A*
- BFS (Breadth-First Search)
- GBFS (Greedy Best-First Search)
- Dijkstra
import {AStar, GridMap} from "../../src/index.js";
const grid = new GridMap(10, 20);
const walls = [[6, 1], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [7, 7], [7, 4], [7, 8], [7, 9], [12, 3], [12, 4], [14, 0], [14, 1], [14, 2], [14, 3], [14, 7]];
walls.forEach((wall) => {
grid.setIsPassable(wall[0], wall[1], false);
});
const map = new AStar(grid);
const start = [3, 3];
const end = [18, 6];
const path = map.findPath(start, end);
console.log(path);
All examples are available in the examples folder.
To run the tests, use the following command:
yarn test
Or with npm:
npm test
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.