1.0.2 • Published 3 years ago
pathfinder-maze-class v1.0.2
Pathfinder Maze Class
Javascript class which accepts a 2d maze array and solves the path through it.
To install, run npm install pathfinder-maze-class
Example Usage:
const Pathfinder = require('pathfinder-maze-class');
const MAZE = [
[0, 0, 0, 0, 0],
[1, 1, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 1, 'x'],
[0, 1, 1, 1, 0],
];
new Pathfinder(MAZE).perform();
This should output:
we found the door at 1,0! let's go!
We found the x! It took 11 moves to get there!
Notes:
- Mazes must have a 'door' on the left edge. Pathfinder will start on the first valid space from the top on this edge, or tell you it can't find the door.
- A
1
is a valid space to move. - An
x
ends the maze and outputs the victory message above. - If there is no
x
or Pathfinder has more than one1
it could move to, it will tell you it got stuck.