Maze Builder Docs 6.7.5
Loading...
Searching...
No Matches
Maze Builder Docs

Maze Builder

Create and customize mazes on multiple platforms and languages. An example of an output string generated from the command-line interface is shown here:

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| | | |
+-----+-----+ + +-----+-----+ + + + +
| | | | | | |
+ +-----+-----+ +-----+-----+ + + +-----+
| | | | | | |
+ + + + + + +-----+ +-----+ +
| | | | | | | |
+ + +-----+-----+ +-----+ +-----+-----+ +
| | | | | |
+ +-----+ + +-----+ +-----+ +-----+-----+
| | | | | |
+ +-----+-----+-----+ + +-----+-----+-----+ +
| | | | |
+-----+-----+-----+ + + + +-----+-----+ +
| | | | | | |
+-----+-----+ + + + + + + +-----+
| | | | | | | | |
+ +-----+-----+ + + +-----+ + + +
| | | |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Output Formats

The library provides multiple output formats like Wavefront object, PNG and JPEG images, JSON, and plain text or stdout.

Here's an example of the command-line program producing JSON output: mazebuildercli.exe -r 2 -c 5 -o 2x5.json

{
"rows": 2,
"columns": 5,
"seed": 2,
"algo": "dfs",
"distances": false,
"str": "+---+---+---+---+---+\n
| | |\n
+ +---+ +---+ +\n
| | |\n
+---+---+---+---+---+\n"
}

Examples

Command-Line Interface

The command-line interface example allows maze building functionality at the terminal.

Run the binary_tree algorithm with long arguments:

mazebuildercli.exe --rows=25 --columns=25 --seed=42 --algo=binary_tree --output=bt.obj

Run the dfs algorithm with short arguments:

mazebuildercli.exe -r 25 -c 25 -s 42 -a dfs -o dfs.obj

API

Use the C++ API in a modern C++ program:

#include <iostream>
void main() {
auto rows{10}, cols{10};
auto m = mazes::factory::create_q(rows, cols);
auto s = mazes::stringz::stringify(m);
std::cout << s << std::endl;
return 0;
}
This file includes all the headers in the maze builder library.

Web Interface - Voxels

Provided is a web interface in a voxel world that enables interactive maze generation.

Check out the this example in a live app!

The web app can be run locally with the provided secure_http_server.py script. Once the provided script is running, then open the browser to http://localhost:8000.

Http

The HTTP example allows for distributed maze building and sharing. The network endpoint is configurable with the included JSON input files.

Physics

The physics example is a full-fledged video game. Pick balls and bounce against maze walls, breaking and colliding, and navigating to exit cells.


CMake Configuration and Testing

CMake 3.2 or greater is required. The examples and tests require external dependencies which can be grabbed from the Internet:

  • box2d
  • catch2
  • SDL
  • SFML

Use the following CMake options to configure the project:

CMake Option Default Description
MAZE_BUILDER_EXAMPLES OFF Build with project examples enabled.
MAZE_BUILDER_COVERAGE OFF Build with code coverage using CppCheck.
MAZE_BUILDER_TESTS OFF Build with testing using Catch2.
MAZE_BUILDER_DOCS OFF Build the docs using doxygen.
MAZE_BUILDER_MEMCHECK OFF Build with Valgrind and Memcheck support.
CMAKE_TOOLCHAIN_FILE cmake Building with a specific toolchain. Useful for `Emscripten` builds.

Build Commands

Configure it: cmake -GNinja -S . -B build-examples -DMAZE_BUILDER_EXAMPLES:BOOL=ON

Build it: cmake --build build-examples --config Release

By default, both a shared-object library and static library are produced. The shared and static files have different naming conventions depending on the platform:

Platform static lib shared lib
Windows mazebuildercore_static.lib mazebuildercore_shared.dll
Linux libmazebuildercore_static.a libmazebuildercore_shared.so
MacOS

Testing

Configure the project for testing: cmake -S . -B build-tests -DMAZE_BUILDER_TESTS:BOOL=ON

Run the tests: ctest --test-dir build-tests/tests --verbose -C Debug


Configure for the Web

Configure examples for the browser using Emscripten and their toolchain file.

cmake -S . -B build-web -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${my/emsdk/repo}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake

Scripts

The Ruby script mazes.rb generates PNG images of mazes using algorithms and methods similar to the C++ library. It is a good place to start learning about the maze-generating algorithms. The Python script solver.py plays with the maze generation by loading PNG files and finding paths and networks.

Script dependencies:

  • gem install chunky_png
  • pip install numpy pillow networkx

More Learning Resources