Maze Generator (Depth-First Search Algorithm)
This is a maze generator that uses the depth-first search algorithm.
Note: Not recommended for making satisfying graphics, the red square will teleport sometimes
EDIT: there is a improved (harder) version at: https://seashellrundownparameters-3.hackinggo306.repl.co/
__ It's harder because it generates cross roads at the very start so you have more choices to make __
Every time the square moves to a new space, it adds it to an array called 'past'. When the square hits a dead end, then it goes to the latest place in 'past' and then deletes it from the array.
If the square hits a dead end but the previous move was already deleted from 'past', then it will teleport to another location from 'past'.
I know it sounds kinda confusing.
Nice! How are you using dfs? What are your "boundaries" that tells the algorithm to change direction?
The red square moves 2 grids at a time, and since the dimensions are in a square, it is easy to check in advance if a certain move will pass the edge. The dimensions are always odd and so are the coordinates of the red square.
For moving right, you can check if the x-position of the square plus 2 is greater or equal to the edge size, if it is, then the move is illegal.