grid-path-finder

1.0.10 • Public • Published

grid-path-finder

NPM module for path-finding on a grid by Ruaidhri MacKenzie.

An NPM module that finds the shortest path between two nodes on a grid. Exposes a function which accepts two positions and a grid. The positions are objects with x and y properties. The grid is a 2d array with values of 0 (vacant node) or 1 (wall node).

npm install grid-path-finder

Example

const pathFinder = require('grid-path-finder');
 
const startPos = {x: 0, y: 0};
const endPos = {x: 5, y: 0};
const grid = [
  [0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
  [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
  [0, 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, 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, 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]
];
const path = pathFinder(startPos, endPos, grid);

Readme

Keywords

Package Sidebar

Install

npm i grid-path-finder

Weekly Downloads

2

Version

1.0.10

License

MIT

Unpacked Size

5.32 kB

Total Files

4

Last publish

Collaborators

  • fankadore