about project

For an assesment, I had to make a perfect maze generator using a algorithm. A perfect maze is a maze where you would be able to reach every place, has no loops, and has only one correct way to the exit. in this "game" you can create mazes of 10x10 to 250x250 big. you can also watch how the maze is generated if you want

View project at Github

System

the algorithm I desided to use for this project, was the backtracking algorithm. This is probably to most well known algorithm for mazes. This algorithm picks a random neighbour cell of the current cell and will remove the wall between the two, creating a path. When all neighbour cells are already exposed, the algorithm goes back the path it came till it finds a neighbour cell that is not yet visited and exposed.

code

The code shown here marks the current cell as visited, so it wont create any loops. when done that, it removes the wall between the current cell and his neighbour cells. After that it says to get a new random unvisited neighbour. when it finds one, it will continue, if not, it will go back the path it followd to it's current location, looking for other unvisited cells. When it finds an unvisited cell somewhere else, it will continue creating a path from that location.