1.0.2 • Published 3 years ago

pathfinder-maze-class v1.0.2

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

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:

  1. 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.
  2. A 1 is a valid space to move.
  3. An x ends the maze and outputs the victory message above.
  4. If there is no x or Pathfinder has more than one 1 it could move to, it will tell you it got stuck.