jawira / nice-maze-generator
Create a maze using ascii art
v2.0.0
2026-09-12 15:54 UTC
Requires
- php: ^8.2
Requires (Dev)
- ext-mbstring: *
- friendsofphp/php-cs-fixer: ^3.95
- jawira/annotation-updater: ^1.0
- jawira/skeleton: ^2.33
- phpunit/phpunit: ^11.5
- vimeo/psalm: ^6.16
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Create mazes using ASCII art.
How to install
composer require jawira/nice-maze-generator
Usage
Create a maze
Instantiate the Maze class to generate a random maze.
Since this class implements \Stringable, you can directly print the $maze object.
<?php
use Jawira\NiceMazeGenerator\Maze;
$maze = new Maze(5, 20); // 5 rows and 20 columns
echo $maze;
This is the output from the previous code:
╭───────┬─────┬─────────────┬─────┬─────╮
│ │ │ │ │ │
├─────╮ ╵ ╭─╮ │ ╶─────╮ ╶─╮ ╰───╮ ╵ ╷ ╶─┤
│ │ │ │ │ │ │ │ │ │
├───╴ ├───╯ │ ├─────┬─┴─╮ ├───╮ ╰───┤ ╷ │
│ │ │ │ │ │ │ │ │ │ │
│ ╶─┬─╯ ╷ ╷ │ │ ╭─╴ │ ╷ │ │ ╷ ╰───╮ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ ╷ ╵ ╶─┤ ╰─╯ ╵ │ ╶─╯ │ ╵ │ │ ╶───╯ ╰─╯ │
│ │ │ │ │ │ │ │
╰─┴─────┴───────┴─────┴───┴─┴───────────╯
Access the maze array
You can access the array version of the maze via the maze property.
<?php
use Jawira\NiceMazeGenerator\Maze;
$maze = new Maze(4, 15);
foreach ($maze->maze as $row) {
foreach ($row as $char) {
echo $char;
}
echo PHP_EOL;
}
Use a Seed
Use the seed parameter to reproduce a maze.
<?php
use Jawira\NiceMazeGenerator\Maze;
$maze = new Maze(6, 18, 123); // always generates the same maze
echo $maze;
Contributing
- If you like this project, ⭐ star it on GitLab.
- Issues are welcome.
License
This library is licensed under the MIT license.