Knossos is a Rust library and CLI for generating mazes with some basic routines for rendering and saving mazes to files.
In Greek mythology, King Minos dwelt in a palace at Knossos. He hired the Athenian architect, mathematician, and inventor Daedalus to design his palace and so cleverly was it constructed that no one who entered could find their way back out without a guide. In other versions of this same story it was not the palace itself which was designed in this way but the labyrinth within the palace which was built to house the half-man/half-bull the Minotaur. In order to keep Daedalus from telling the secrets of the palace, Minos locked him and his son Icarus in a high tower at Knossos and kept them prisoner. Daedalus fashioned wings made of wax and bird's feathers for himself and his son, however, and escaped their prison but Icarus, flying too close to the sun, melted his wings and fell to his death.
Source: https://www.worldhistory.org/knossos
Knossos currently supports only one type of mazes: orthogonal, which is a standard maze layout of rectangular passages.
The library supports the following generation algorithms:
Knossos supports the following output types:
ASCII Using the ASCII output, you can simply print a maze to the console or write it to a file to see what it looks like
Game map If you're interested in writing your own game with pseudo 3D graphics or just testing your implementation of the ray casting algorithm, you can convert a maze into a game map. Currently, this formatter supports one configuration option: it's a span
value describing any passage — distance between two opposite walls.
Image Using the Image output, you can render a maze to PNG or JPG (just use the corresponding filename extension). This type of output is highly customizable: it allows you to specify custom margin, wall and passage width, and even background and foreground colors
Run the following Cargo command in your project directory:
no_test
cargo add knossos
Or add the following line to your Cargo.toml
:
no_test
[dependencies]
knossos = "0.2.0"
Knossos is designed to be super easy and convenient to use. Here are some usage examples of how to generate, display and save mazes:
```rust,no_run use knossos::maze::*;
let maze = OrthogonalMazeBuilder::new().build(); ```
```rust,no_run use knossos::maze::*;
let maze = OrthogonalMazeBuilder::new() .height(10) .width(10) .algorithm(Box::new(GrowingTree::new(Method::Random))) .build(); ```
```rust,no_run use knossos::maze::*;
let maze = OrthogonalMazeBuilder::new().build(); println!("{}", &maze); ```
```rust,no_run use knossos::maze::*;
let maze = OrthogonalMazeBuilder::new().build();
// Save as ascii maze.save("output/maze.txt", Ascii).unwrap(); // Save as a game map maze.save("output/mazegamemap.txt", GameMap::new().span(3)).unwrap(); // Save as a PNG image maze.save("output/maze.png", Image::new().wall(10).passage(30)).unwrap(); ```
You can find more examples in src/example.rs
```bash cargo +nightly bench Finished bench [optimized] target(s) in 0.51s Running unittests src/lib.rs (target/release/deps/knossos-43150be123983d04)
running 22 tests test maze::builder::tests::build ... ignored test maze::errors::saveerror::tests::display ... ignored test maze::errors::transiterror::tests::display ... ignored test maze::formatters::ascii::tests::formatdefault ... ignored test maze::formatters::ascii::tests::formatehanced ... ignored test maze::formatters::gamemap::tests::format ... ignored test maze::formatters::gamemap::tests::newcalldefaultparams ... ignored test maze::formatters::gamemap::tests::passagechange ... ignored test maze::formatters::gamemap::tests::spanchange ... ignored test maze::formatters::gamemap::tests::wallchange ... ignored test maze::formatters::image::tests::format ... ignored test maze::formatters::image::tests::newcalldefaultparams ... ignored test maze::formatters::image::tests::paramschange ... ignored test maze::maze::tests::displayorthogonalmaze ... ignored test maze::maze::tests::invalidmaze ... ignored test maze::maze::tests::validmaze ... ignored test utils::arena::tests::connectonenonenode ... ignored test utils::arena::tests::connectthreenodes ... ignored test utils::arena::tests::connecttwonodes ... ignored test utils::arena::tests::connecttwononenode ... ignored test utils::arena::tests::unconnectednodes ... ignored test utils::color::tests::display_color ... ignored
test result: ok. 0 passed; 0 failed; 22 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running unittests src/main.rs (target/release/deps/knossos-c42e4506ba8fe599)
running 1 test test tests::verify_cli ... ignored
test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running benches/algorithms.rs (target/release/deps/algorithms-99993a694f1f462a)
running 26 tests test algorithms::aldousbroder::generate100x100 ... bench: 25,114,116 ns/iter (+/- 8,976,086) test algorithms::aldousbroder::generate10x10 ... bench: 82,836 ns/iter (+/- 7,641) test algorithms::binarytree::generate100x100 ... bench: 518,780 ns/iter (+/- 4,661) test algorithms::binarytree::generate10x10 ... bench: 5,278 ns/iter (+/- 44) test algorithms::eller::generate100x100 ... bench: 2,924,531 ns/iter (+/- 1,151,159) test algorithms::eller::generate10x10 ... bench: 26,874 ns/iter (+/- 922) test algorithms::growingtreemethodmiddle::generate100x100 ... bench: 2,060,609 ns/iter (+/- 46,684) test algorithms::growingtreemethodmiddle::generate10x10 ... bench: 20,162 ns/iter (+/- 154) test algorithms::growingtreemethodnewest::generate100x100 ... bench: 1,834,971 ns/iter (+/- 18,044) test algorithms::growingtreemethodnewest::generate10x10 ... bench: 19,742 ns/iter (+/- 5,935) test algorithms::growingtreemethodoldest::generate100x100 ... bench: 2,059,533 ns/iter (+/- 118,326) test algorithms::growingtreemethodoldest::generate10x10 ... bench: 20,145 ns/iter (+/- 1,032) test algorithms::growingtreemethodrandom::generate100x100 ... bench: 2,553,812 ns/iter (+/- 390,277) test algorithms::growingtreemethodrandom::generate10x10 ... bench: 24,224 ns/iter (+/- 6,544) test algorithms::huntandkill::generate100x100 ... bench: 1,060,523 ns/iter (+/- 83,817) test algorithms::huntandkill::generate10x10 ... bench: 9,249 ns/iter (+/- 301) test algorithms::kruskal::generate100x100 ... bench: 38,615,035 ns/iter (+/- 23,011,185) test algorithms::kruskal::generate10x10 ... bench: 19,223 ns/iter (+/- 909) test algorithms::prim::generate100x100 ... bench: 5,987,027 ns/iter (+/- 2,530,387) test algorithms::prim::generate10x10 ... bench: 21,962 ns/iter (+/- 8,735) test algorithms::recursivebacktracking::generate100x100 ... bench: 1,199,184 ns/iter (+/- 146,586) test algorithms::recursivebacktracking::generate10x10 ... bench: 11,472 ns/iter (+/- 2,661) test algorithms::recursivedivision::generate100x100 ... bench: 349,725 ns/iter (+/- 19,278) test algorithms::recursivedivision::generate10x10 ... bench: 3,511 ns/iter (+/- 57) test algorithms::sidewinder::generate100x100 ... bench: 254,377 ns/iter (+/- 24,068) test algorithms::sidewinder::generate10x10 ... bench: 2,526 ns/iter (+/- 17)
test result: ok. 0 passed; 0 failed; 0 ignored; 26 measured; 0 filtered out; finished in 71.73s
Running benches/formatters.rs (target/release/deps/formatters-1b577342650eb048)
running 8 tests test formatters::asciidefault::format100x100 ... bench: 1,457,895 ns/iter (+/- 6,362) test formatters::asciidefault::format10x10 ... bench: 85,277 ns/iter (+/- 19,651) test formatters::asciienhanced::format100x100 ... bench: 1,344,412 ns/iter (+/- 5,683) test formatters::asciienhanced::format10x10 ... bench: 83,734 ns/iter (+/- 1,928) test formatters::gamemap::format100x100 ... bench: 7,905,384 ns/iter (+/- 104,229) test formatters::gamemap::format10x10 ... bench: 149,456 ns/iter (+/- 3,197) test formatters::image::format10x10 ... bench: 40,956,263 ns/iter (+/- 3,166,280) test formatters::image::format50x50 ... bench: 864,432,205 ns/iter (+/- 2,515,914)
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured; 0 filtered out; finished in 278.25s ```
A command-line interface for generating mazes in the terminal uses the library's public API.
```bash knossos generate -W 5 -H 5 ascii --output-type=enhanced --output-path=maze.txt +---+---+---+---+---+ | | | | + + + + + + | | | | | + +---+ +---+ + | | | | | +---+ + + + + | | | | | | + + + + + + | | | +---+---+---+---+---+
```
```bash knossos generate -W 5 -H 5 game-map --span 2 --output-path=maze.txt
```
bash
knossos generate -W 15 -H 15 image --output-path=maze.png
Debian package:
1. Download the latest binary
2. dpkg -i <binary-name>
will install it
Or from crates.io:
bash
cargo install knossos
Or from source:
bash
$ git clone git@github.com:unrenamed/knossos.git
$ cd knossos
$ cargo build --release
$ ./target/release/knossos --version
knossos 0.1.2
```bash knossos --help Rust library for generating and rendering mazes
Usage: knossos
Commands: generate Generates a maze help Print this message or the help of the given subcommand(s)
Options: -h, --help Print help -V, --version Print version ```
Using generate
command:
```bash
knossos generate -h
Generates a maze
Usage: knossos generate [OPTIONS]
Commands: ascii Save to a text file with an ASCII representation of a maze game-map Save to a text file as an ASCII game map for pseudo 3D games that use ray casting for modeling and rendering the map image Save to PNG or JPG file help Print this message or the help of the given subcommand(s)
Options:
-A, --algorithm
For more info, run
bash
knossos generate help