This library generates complex mazes and finds a path through them. It is useful for learning and game development.
$ dotnet add package DimonSmart.MazeGeneratorDemo online: https://dimonsmart.github.io/Demo/
MazeGenerator is a lightweight C# library for generating, visualizing, and solving mazes. The repo ships with a single CLI sample that walks through three small scenarios so you can verify the workflow without extra plumbing.
MazeBuildOptions (WallShortness, Emptiness).MazeWaveGenerator + MazePathBuilder produces the shortest path.IMazePlotter, IWavePlotter, or IPathPlotter to render progress in any UI.net6.0, net7.0, net8.0, net9.0, and net10.0.Run the text-mode sample (it plays all three scenarios back-to-back):
git clone https://github.com/DimonSmart/MazeGenerator.git
cd MazeGenerator
dotnet run --project QuickStartDemo --framework net8.0
You will see:
MazeBuildOptions and a custom IMazePlotter implementation.S, E, and *).The source lives in QuickStartDemo/Program.cs.
Install the package
dotnet add package DimonSmart.MazeGenerator
Define a cell type (implements ICell, has a public parameterless constructor):
public sealed class TutorialCell : ICell
{
private bool _isWall;
public bool IsWall() => _isWall;
public void MakeWall() => _isWall = true;
}
Generate a maze, compute a wave, and reconstruct the path:
var maze = new Maze<TutorialCell>(31, 21);
var options = new MazeBuildOptions(WallShortness: 0.15, Emptiness: 0.05);
new MazeBuilder<TutorialCell>(maze, options).Build();
var start = new Point(1, 1);
var end = new Point(maze.Width - 2, maze.Height - 2);
var wave = new MazeWaveGenerator<TutorialCell>(maze).GenerateWave(start.X, start.Y, end.X, end.Y);
var path = new MazePathBuilder(wave).BuildPath();
Render however you like – iterate over maze to print ASCII (see the QuickStart demo) or handle plotter callbacks:
var plotter = new MyConsolePlotter();
await new MazeBuilder<TutorialCell>(maze).BuildAsync(plotter);
await new MazeWaveGenerator<TutorialCell>(maze, plotter).GenerateWaveAsync(start.X, start.Y, end.X, end.Y);
await new MazePathBuilder(wave, plotter).BuildPathAsync();
MazeBuildOptions cheatsheet:
WallShortness – probability of interrupting long straight walls (higher value → twistier mazes).Emptiness – probability of skipping a wall entirely (higher value → more open space).dotnet run --project QuickStartDemo --framework net10.0 to validate the latest runtime.Maze<TCell> – holds the grid and exposes boundary validation.MazeBuilder<TCell> – carves the maze; accepts optional IMazePlotter callbacks and cancellation tokens.MazeWaveGenerator<TCell> – propagates a Lee-style wave until it hits the target or exhausts the grid.MazePathBuilder – walks the wave back to produce a MazePath with ordered PathCell instances.IMazePlotter, IWavePlotter, IPathPlotter) – override sync or async methods depending on how you want to render progress.net6.0; net7.0; net8.0; net9.0; net10.0.net6.0, net8.0, and net10.0 to ensure downstream apps compile cleanly across LTS and the latest SDK.DimonSmart.MazeGenerator.Tests (xUnit, net8.0) checks border generation plus wave/path reconstruction so regressions are caught automatically.dotnet build MazeGenerator.sln succeeds on .NET SDK 10.0.101 (checked on 2025-12-10).Issues and pull requests are welcome. Please include a short description of the scenario you verified (QuickStart example number, custom UI, etc.) so regressions stay easy to triage.