Skip to content

An implementation of the Eller's Algorithm for generating infinite mazes

License

Notifications You must be signed in to change notification settings

39555/ellers-maze

Repository files navigation

Eller's Maze

About

This is my implementation of Eller's Algorithm for generating infinite mazes as described by Jamis Buck. This library generates a bitset where each bit represents a cell, with 'true' indicating a wall and 'false' indicating a non-wall. An example prints the maze in the terminal.

ellersmaze.mov

Usage

The library provides a class with a one function:

ellrs::maze maze{width};
auto rand_bool =
    [bool_dist = std::uniform_int_distribution<int>{0, 1},
     rand = std::default_random_engine{std::random_device{}()}]() mutable {
        return bool_dist(rand);
    };// you can pass your own random bool generator
while(true) {
    auto  [ vtype, vertical ]   = maze.getline(rand);
    auto  [ htype, horizontal ] = maze.getline(rand);

    assert(vtype == ellrs::line_kind::vertical);
    assert(htype == ellrs::line_kind::horizontal);
}

You must start generation with a vertical line, but while using a result horizontal line must be first:

                           |   |   |   |
                        _1_|_2_|_3_|_4_|
    print a horisontal ~^  ^~  and then print a vertical wall.

Also you can use your own random bool generator to generate a more interested result:

bool randomBool() {
   return rand() > (RAND_MAX / 2);
}
maze.getline(&randomBool);

Thanks

  • Thank you Jamis Buck for the algorithm description.