This is a simple maze generator written in Rust. It uses the recursive backtracker algorithm to generate mazes.
┌ ┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┬---┐
│ x x x │ x x │ x x │ │
├---┼---┼ ┼---┼---┼---┼---┼---┼ ┼ ┼---┼ ┼ ┼ ┼ ┼---┤
│ │ x x x x x x x │ x x │ x │ x │ │ │
├ ┼---┼---┼---┼---┼---┼---┼---┼---┼---┼ ┼ ┼ ┼---┼---┼ ┤
│ x x x x │ x x │ x x x │ x │ x │ x │ x x x │
├ ┼---┼---┼ ┼ ┼ ┼ ┼---┼ ┼---┼ ┼ ┼ ┼ ┼---┼ ┤
│ x │ │ x x │ x │ x │ │ x │ x x │ x │ x x │ │ x │
├ ┼ ┼ ┼---┼---┼ ┼ ┼ ┼ ┼ ┼---┼ ┼---┼---┼ ┼ ┤
│ x │ │ │ x │ x x │ x x │ x x │ │ x │
├ ┼ ┼ ┼---┼---┼ ┼---┼ ┼---┼---┼ ┼---┼ ┼---┼---┼ ┤
│ x │ │ │ x x x │ x x │ │ x x x │
├ ┼---┼---┼---┼ ┼---┼---┼---┼ ┼ ┼---┼ ┼---┼ ┼---┼---┤
│ x x x x x x │ │ x │ │ │ x x x │
├---┼---┼---┼---┼---┼ ┼---┼---┼ ┼ ┼ ┼ ┼ ┼---┼---┼ ┤
│ │ x x x │ x x │ │ x │ │ │ │ x │
├ ┼ ┼---┼ ┼---┼---┼ ┼ ┼---┼ ┼ ┼ ┼---┼ ┼---┼ ┤
│ │ x x x x │ x x x │ │ x │
└---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴---┴ ┘
To install the CLI, first clone this repository:
git clone [email protected]:wilswer/maze_gen.rs.git
and move into the directory maze_gen.rs
then install the CLI with cargo
:
cargo install --path .
To get a list of all available options, run the CLI with the --help
flag:
maze_gen --help
To generate a maze, run the CLI with the desired width and height:
maze_gen -x 20 -y 20
To generate a maze with a solution, run the CLI with the --solution
flag:
maze_gen -x 20 -y 20 --solution
To generate a maze with a solution and save it to a file (do not include extension), run the CLI with the
--solution
and --output
flags:
maze_gen -x 20 -y 20 --solution --output maze
This will generate a text file maze.txt
and an SVG file maze.svg
in the current directory.
Example SVG output without solution:
Example SVG output with solution marked in red: