Skip to content

Labyrinthian is a dependency-free .NET Standard 2.1 C# library that empowers game developers and enthusiasts with versatile maze generation capabilities

License

Notifications You must be signed in to change notification settings

romandykyi/Labyrinthian

Repository files navigation

Labyrinthian

labyrinthian-l

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.

Mazes, that were generated using Labyrinthian.Svg

gradient-maze theta-maze lines-maze

Supported Maze Generation Algorithms

  • 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

Supported Maze Types

  • Delta
  • Sigma
  • Orthogonal
  • Theta
  • Upsilon

Installation

Unity

  1. Download the Unity package here
  2. In Unity, go to 'Assets > Import package > Custom package'
  3. Select the downloaded package
  4. Click 'Import'

Visual Studio

  1. Open Package Manager Console window: 'View > Other Windows > Package Manager Console'
  2. Navigate to the directory in which the .csproj file exists
  3. Run this command to install the main package:
NuGet\Install-Package Labyrinthian
  1. If you need SVG-export features, also run this command:
NuGet\Install-Package Labyrinthian.Svg

.NET CLI

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

Example

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:

orthogonal-maze

More examples here.

License

This project is licensed under the MIT License. See the LICENSE file for details.