BorrowedTorch.Architecture
0.0.2
Prefix Reserved
dotnet add package BorrowedTorch.Architecture --version 0.0.2
NuGet\Install-Package BorrowedTorch.Architecture -Version 0.0.2
<PackageReference Include="BorrowedTorch.Architecture" Version="0.0.2" />
<PackageVersion Include="BorrowedTorch.Architecture" Version="0.0.2" />
<PackageReference Include="BorrowedTorch.Architecture" />
paket add BorrowedTorch.Architecture --version 0.0.2
#r "nuget: BorrowedTorch.Architecture, 0.0.2"
#:package BorrowedTorch.Architecture@0.0.2
#addin nuget:?package=BorrowedTorch.Architecture&version=0.0.2
#tool nuget:?package=BorrowedTorch.Architecture&version=0.0.2
BorrowedTorch.Architecture
Procedural level architecture for grid- and tile-based games. A floor is built in separate stages: a mask says which cells exist, a layout says how neighbouring cells connect, a generator carves passages into the layout, and a tiler turns the layout into a tile map. Every random choice comes from a BorrowedTorch.Randomness stream you pass in, so a world seed always rebuilds the same floor.
using BorrowedTorch.Architecture.Generators.Mazes;
using BorrowedTorch.Architecture.Model.Layout;
using BorrowedTorch.Architecture.Model.Masks;
using BorrowedTorch.Architecture.Model.Tiles;
using BorrowedTorch.Architecture.Primitives;
using BorrowedTorch.Randomness;
var world = new Rng(worldSeed);
// 1. Footprint: which cells exist. Random holes, pruned to one connected piece.
var holes = world.Fork("holes", floor);
var mask = Mask.KeepLargestComponent(Mask.FromPredicate(20, 13, _ => !holes.NextBool(0.2)));
// 2. Topology: how neighbouring cells connect. One perfect maze per connected piece.
var layout = new GridLayout(mask);
new RecursiveBacktracker().Carve(layout, world.Fork("maze", floor));
// 3. Geometry: 2 × 2 floor blocks between 1-tile walls.
var tiler = new ThickWallTiler(cellSize: 2, wallSize: 1);
Grid<Tile> tiles = tiler.Build(layout);
// Questions go to the layout, not the tiles.
var start = layout.ActiveCells().First();
Grid<int> distances = LayoutQueries.Distances(layout, start); // -1 = unreachable
var deadEnds = LayoutQueries.DeadEnds(layout).ToList();
Int2 spawn = tiler.GetTileOrigin(start); // top-left floor tile of a cell
A 9 × 5 footprint missing its bottom-right corner, carved and built with new ThickWallTiler(), one
passage turned into a door (# wall, . floor, + door, blank is void):
###################
#.#.....#.....#...#
#.###.###.###.#.#.#
#...#.......#...#.#
###.#.###########.#
#...#...#.+.......#
#.#######.###.#####
#.........#...#
###########.###
#.............#
###############
What is in it
All namespaces sit under BorrowedTorch.Architecture.
| Namespace | Types | Purpose |
|---|---|---|
Primitives |
Int2, Direction, DirectionMask |
Grid coordinates (+X east, +Y south) and the four cardinal directions: Offset, Opposite, Rotate…, ToMask |
Primitives |
Grid<T> |
Dense row-major 2D array with by-reference indexers |
Model.Masks |
Mask |
Footprints in cell space: Rect, FromPredicate, LabelComponents, KeepLargestComponent, KeepComponentContaining |
Model.Layout |
GridLayout, EdgeKind |
Cells and the edges between them: Wall, Open or Door |
Model.Layout |
LayoutQueries |
Distances (breadth-first), CountReachable, DeadEnds |
Generators.Mazes |
IMazeGenerator, RecursiveBacktracker |
Depth-first perfect maze with long, winding corridors |
Model.Tiles |
ITiler, ThickWallTiler, ThinWallTiler |
Layout to tile map, with walls as whole tiles or on tile edges |
Model.Tiles |
Tile, TileKind |
One tile: Void, Floor, Wall or Door, plus wall and door masks for thin-wall maps |
Two tilers
ThickWallTiler(cellSize, wallSize) |
ThinWallTiler |
|
|---|---|---|
| Map size | layout.Width * (CellSize + WallSize) + WallSize (same for height) |
Same as the layout |
| Walls | TileKind.Wall tiles |
Tile.Walls bits on floor tiles |
| Doors | A TileKind.Door tile across the wall; Tile.Doors holds the axis it connects |
Tile.Doors bits on both sides of the edge |
| Missing cells | TileKind.Void, sealed off by walls |
TileKind.Void |
| Cell to tile | GetTileOrigin(cell), the top-left tile of the cell's floor block |
Same coordinates |
Guarantees
- Deterministic. Generators draw only from the
Rngyou pass, and always visit directions in the same order (North, East, South, West). The same footprint, seed and start cell give the same maze. Give each system and floor its own fork (world.Fork("maze", floor)); fork keys are part of your save format. - Edges are symmetric. Each edge is stored once, so
GetEdge(a, East)andGetEdge(b, West)read the same value. Edges towards missing or out-of-bounds cells are always walls; opening one throws. - One perfect maze per island.
RecursiveBacktrackerbuilds a spanning tree in every 4-connected component of the footprint: exactly one path between any two of its cells, no loops. For a single connected maze, prune the mask first withMask.KeepLargestComponentorMask.KeepComponentContaining. - Carving only adds. Existing openings are kept; call
CloseAllEdges()before carving a fresh maze into a used layout. - The footprint is fixed.
GridLayoutcopies its mask, so later changes to the mask do not affect it. - No engine types. The only dependency is BorrowedTorch.Randomness; draw the tiles with anything.
- Pre-1.0. Until 1.0, the API and the maze a given seed produces may still change between versions.
Demo and tour
demo/BorrowedTorch.Architecture.Demo is a MonoGame window that draws the maze scene: step through seeds,
change size, hole density, thick or thin walls and cell and wall sizes, and click a cell to measure distances
from it. Its seeds match the tests, so the same seed is the same maze in both.
dotnet run --project demo/BorrowedTorch.Architecture.Demo
Docs/Borrowed Torch Architecture Tour.html walks through the layers and the decisions behind them, with
diagrams; open it in a browser.
Build
The package targets .NET 8 and .NET 10. Building it needs the .NET 10 SDK, since the source uses C# 14.
dotnet test
dotnet pack src/BorrowedTorch.Architecture -c Release -o artifacts
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- BorrowedTorch.Randomness (>= 1.4.0)
-
net8.0
- BorrowedTorch.Randomness (>= 1.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.