This repository aims to represent Maze generation algorithms.
Rules:
- Given a current cell as a parameter.
- Mark the current cell as visited.
- While the current cell has any unvisited neighbour cells.
- Choose one of the unvisited neighbours.
- Remove the wall between the current cell and the chosen cell.
- Invoke the routine recursively for a chosen cell.
- Create a list of all walls, and create a set for each cell, each containing just that one cell.
- For each wall, in some random order.
- If the cells divided by this wall belong to distinct sets:
- Remove the current wall.
- Join the sets of the formerly divided cells.
- For each cell, randomly remove the left or top wall.
- Start with a grid full of walls.
- Pick a cell, mark it as part of the maze. Add the walls of the cell to the wall list.
- While there are walls in the list:
- Pick a random wall from the list. If only one of the two cells that the wall divides is visited, then:
- Make the wall a passage and mark the unvisited cell as part of the maze.
- Add the neighboring walls of the cell to the wall list.
- Remove the wall from the list.
- Pick a random wall from the list. If only one of the two cells that the wall divides is visited, then:
Maze generation algorithms are widely used in games, but they are also a great way to improve programmimg skills in a fun way.
To run this program you will need Python and to install the libraries Pygame and Numpy.
You can install these using pip
on terminal:
-
Pygame
pip install pygame
-
Numpy
pip install numpy
(If pip didn't work try pip3
)
After running the program, select the type of algorithm, the size of the maze and click on Generate!
.
After the maze has been generated, you can click on PLAY
to start. Try to get to the black dot in shortest time possible!
Bugs? Ideas? Questions? Contact-me: [email protected]