Giter Club home page Giter Club logo

maze-generation-algorithms's Introduction

maze-generation-algorithms

Collection of maze generation and solving algorithms.

Table of Contents

Introduction

A software that generates and solves different kind of mazes with variable height and width. There are a lot of supporting features. Also, the generated mazes can be saved/loaded as an image.

How it works

Demonstration videos on youtube.

The generation algorithms:

  • Aldous-Broder [1]
  • Binary tree [2]
  • Kruskal's [3]
  • Prim's [4]
  • Recursive backtracking [5]
  • Recursive division [6]

The solving algorithms:

  • Dead-end filling [7]
  • Dijkstra's [8]
  • Wall follower [9]


Figure 1. Sample mazes.

The references have clear explanation about how the algorithms work, I won't go into details. Also, my code is fully commented, so it's good reference too.

File structure

The folder structure can be seen below.

.
├── common
│   ├── file_system
│   ├── main
│   └── maze_generator
├── design
├── LICENSE
├── makefile
├── mazes
│   ├── aldous_broder
│   ├── binary_tree
│   ├── kruskal
│   ├── prim
│   ├── recursive_backtracking
│   └── recursive_division
├── output
├── README.md
└── solver

Details about the important folders and files:

  • common:
    • main: Main() function, with a demonstration software.
    • file_system: Saves/loads the maze as an image.
    • maze_generator: Base class for every other class.
  • design: Pictures needed by this readme.
  • makefile: Generates the target.
  • mazes: Every maze generation algorithm (and class) in their own sub folder.
  • output: Pictures generated by the software.
  • solver: The solver algorithms.

Maze generators

A maze is represented by a vector<vector<uint32_t>>, where 0 is a hole or passage, 1 is a wall and 2 is solution.

Every algorithm has its own class and a common base class, called maze_generator.

Each class has the following public member function:

Function Purpose
constructor Creates the 2D vector with the given height and width.
get_cell Returns the value of the cell.
set_cell Manually changes the value of a cell (turns it into a wall (1) or a hole(0).
get_maze Returns the maze as a 2D vector.
set_maze Manually overwrites the whole maze.
reshape Changes the height and width of the maze.
get_height Returns the height of the maze.
get_width Returns the width of the maze.
generate Does the actual generation.

The first six member functions are inherited from the base class, the last is different for every algorithm.

Maze solvers

The solving algorithms are way simpler, than the generators. There are only one class (solver) and every algorithm is a single member function.

How to use it

If you are only interested in reusing the classes/algorithms, then read the previous chapter and the comments inside the code.

If you would like to use the actual software: Make sure, that you have gcc, which support c++14 and OpenCV. I have the following, but older/newer versions might be good too:

gcc version 5.4.0
GNU Make 4.1
OpenCV 4.0.0

If you have everything, then clone the repository, get into the root folder and build:

make

If it worked, then run:

./maze_generator

Enjoy!

There is also

make clean

and

make clean_output

First one is the normal clean, the second one cleans the output folder.

References

[1] Jamis Buck (The Buckblog) - Aldous-Broder algorithm
[2] Jamis Buck (The Buckblog) - Binary tree algorithm
[3] Jamis Buck (The Buckblog) - Kruskal's algorithm
[4] Jamis Buck (The Buckblog) - Prim's algorithm
[5] Jamis Buck (The Buckblog) - Recursive backtracking algorithm
[6] Jamis Buck (The Buckblog) - Recursive division algorithm
[7] Wikipedia - Dead-end filling algorithm
[8] Wikipedia - Dijkstra's algorithm
[9] Wikipedia - Wall follower algorithm

maze-generation-algorithms's People

Contributors

ferenc-nemeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.