Labyrinthian is a .NET Standard 2.1 C# library for generating mazes step-by-step. It provides a versatile toolkit for maze enthusiasts, game developers, and educators, allowing you to effortlessly create mazes with various algorithms and export them in SVG format.
This library is lightweight and comes with no external dependencies.
You can play around with a Blazor demo here.
- Aldous Broder
- Binary tree
- Depth-first search
- Edge-based Prim's algorithm
- Growing tree
- Hunt and Kill
- Kruskal's algorithm
- Origin Shift (invented by CaptainLuma)
- Prim's algorithm
- Recursive backtracker (with customizable cell selection method)
- Recursive division
- Sidewinder
- Wilson's algorithm
- Delta
- Sigma
- Orthogonal
- Theta
- Upsilon
- Download the Unity package here
- In Unity, go to 'Assets > Import package > Custom package'
- Select the downloaded package
- Click 'Import'
- Open Package Manager Console window: 'View > Other Windows > Package Manager Console'
- Navigate to the directory in which the .csproj file exists
- Run this command to install the main package:
NuGet\Install-Package Labyrinthian
- If you need SVG-export features, also run this command:
NuGet\Install-Package Labyrinthian.Svg
Run this command to install the main package:
dotnet add package Labyrinthian
If you need SVG-export features, also run this command:
dotnet add package Labyrinthian.Svg
This code snippet demonstrates the creation, generation, and export of an orthogonal maze as an SVG file:
using Labyrinthian;
using Labyrinthian.Svg;
// Create an orthogonal maze 30x20
Maze maze = new OrthogonalMaze(30, 20);
// Generate it using Prim's algorithm
MazeGenerator generator = new PrimGeneration(maze);
generator.Generate();
// Create a maze exporter
MazeSvgExporter exporter = new(maze)
{
Walls.AsOnePath()
};
// Use a FileStream for exporting.
// You can also use any Stream or TextWriter(e.g. StreamWriter) or XmlWriter
using var fs = File.Create(@"d:\orthogonal-maze.svg");
using var svgWriter = new SvgWriter(fs);
// Export a maze
exporter.Export(svgWriter);
Possible output:
More examples here.
This project is licensed under the MIT License. See the LICENSE file for details.