https://github.com/exposedcat/exit-from-maze
Algorithm finding an exit from the given maze
https://github.com/exposedcat/exit-from-maze
Last synced: 15 days ago
JSON representation
Algorithm finding an exit from the given maze
- Host: GitHub
- URL: https://github.com/exposedcat/exit-from-maze
- Owner: ExposedCat
- Created: 2021-06-22T20:52:36.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-22T21:15:45.000Z (over 4 years ago)
- Last Synced: 2025-03-12T04:41:25.157Z (10 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Exit from maze
Algorithm finding an exit from the given maze.
## Usage
```js
import { escapeMaze } from './index.js'
/*
0 - start position
# - wall
+ - way
*/
const maze = [
['#','#','#','#','#','#','#','#','#'],
['#','+','+','+','#','+','+','+','#'],
['#','+','#','+','#','+','#','+','#'],
['+','+','#','+','0','+','#','+','#'],
['#','#','#','+','#','#','#','#','#'],
['#','#','+','+','#','#','#','#','#'],
['#','#','+','#','#','#','#','#','#'],
['#','#','#','#','#','#','#','#','#'],
]
const exitPath = escapeMaze(maze)
// ['left', 'top', 'top', 'left', 'left', 'bottom', 'bottom', 'left']
```
Algorithm is adapted for situations with multiple exits (shows the nearest).
There must only be one start point (otherwise the first point will be used).
Exit code `1` means that start point is not specified.
Exit code `2` means that the maze has no exit.
## Contributing
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.
## License
[GNU General Public License v3.0](https://choosealicense.com/licenses/gpl-3.0/)