Demo online: https://dimonsmart.github.io/Demo/
MazeGenerator is a C# library designed to create complex mazes programmatically. This project also includes a console application demo that showcases how mazes are generated and visualized dynamically.
- Dynamic Maze Generation: Generate mazes with customizable dimensions and complexity.
- Visualization: Console application for visualizing maze generation and pathfinding processes.
- Extensible Architecture: Easily extendable to integrate different types of maze algorithms and visualization methods.
- Pathfinding Support: Includes pathfinding capabilities to find routes through the mazes.
- .NET 6 SDK or later
Clone the repository and navigate to the project directory:
git clone https://github.com/DimonSmart/MazeGenerator.git
cd MazeGenerator
To see the MazeGenerator in action:
- Open the solution in Visual Studio or any compatible IDE.
- Set MazeGeneratorConsoleDemo as the startup project.
- Build and run the application to visualize the maze generation and pathfinding.
IMaze
: Interface defining the basic structure and functionality of a maze.Maze
: Represents the maze structure with methods for wall creation and query.Cell
: Basic unit in a maze implementing the ICell interface.MazeBuilder<TCell>
: Generic builder class for constructing mazes with specific characteristics and algorithms.MazeWaveGenerator<TCell>
: Generic wave generator class for pathfinding using wave propagation in the maze.MazePathBuilder
: Builds a path using the generated wave data.IMazePlotter
: Interface for plotting elements like walls and passages within the maze, synchronously or asynchronously.
Add a reference to the MazeGenerator project in your application. Use these classes to generate and work with mazes:
This example demonstrates how to generate a maze without any visualization. The MazeBuilder is invoked without a plotter, so the maze is created silently.
var maze = new Maze<Cell>(31, 21);
var random = new Random(0); // use a seed for repeatable mazes
new MazeBuilder<Cell>(maze, null, random).Build();
In this example, the maze generation progress is visualized in the console. A MazeConsolePlotter instance is passed to the MazeBuilder to display the building process.
var maze = new Maze<Cell>(31, 21);
var mazePlotter = new MazeConsolePlotter();
var random = new Random(0); // seed for repeatable results
new MazeBuilder<Cell>(maze, new MazeBuildOptions(0.50, 0.0), random).Build(mazePlotter);
This example showcases the full process:
- Maze generation with visualization.
- Wave propagation for pathfinding from a start point to a target.
- Path building based on the generated wave.
var maze = new Maze<Cell>(31, 21);
var mazePlotter = new MazeConsolePlotter();
var random = new Random(0); // deterministic maze
new MazeBuilder<Cell>(maze, new MazeBuildOptions(0.50, 0.0), random).Build(mazePlotter);
var wave = new MazeWaveGenerator<Cell>(maze, mazePlotter).GenerateWave(1, 1, 29, 19);
var pathBuilder = new MazePathBuilder(wave, mazePlotter);
pathBuilder.BuildPath();
Contributions are welcome! Please fork the repository and submit pull requests with your enhancements.