Create a maze using a recursive backtracking algorithm. Inspired by http://weblog.jamisbuck.org/2010/12/27/maze-generation-recursive-backtracking
Overview of the algorithm, from that page:
- Choose a starting point in the field.
- Randomly choose a wall at that point and carve a passage through to the adjacent cell, but only if the adjacent cell has not been visited yet. This becomes the new current cell.
- If all adjacent cells have been visited, back up to the last cell that has uncarved walls and repeat.
- The algorithm ends when the process has backed all the way up to the starting point.
Maze.Common.create_grid(20, 20)
|> Maze.RecursiveBacktracking.MazeRB.carve_passages_from({0,0})
|> Maze.Display.format()
|> IO.puts()βββββ¬β¬βββ¬ββββββ¬ββββββ
βββββββ·ββββββΆββ΅ββ΄ββ¬β΄β
ββ·βΆβββ΅βββΆβ₯β·βββββ₯βββ΅ββ₯
ββββββΆβ₯ββ΄βββββββββΆβ¬ββ
ββββ¬ββββββΏβ΄ββββ₯ββ΄βββ·β
ββ΅β·ββ·βββββββ₯ββ΄ββ΅β·ββ΅ββ
βββ₯β΅βββββ¬ββββββ΄ββββββ
ββΆβ΄β¬ββ·ββ΄ββ¬β΄ββββ΄ββββββ
ββ·βΆβ₯ββββββ΅ββββββ΅βββ·ββ
βββ΄βββββ·ββββΆβ₯β·βββ₯βΆβ₯ββ
ββββββ΅ββ΄βββΏβ΄ββββββ΄βββ₯
βββββ΄ββ₯βΆβ΄ββ΅ββ΄ββ·ββββ΄ββ
βββΆβΏβββ΅β·βΆβ΄ββ΄β΄ββ₯ββΆββββ
ββββ΅β·βββ΄ββ·ββββ₯βββ¬β΄βββ
ββ΄ββ¬βββΆβββββ·β·β΅βββ΅ββββ
βββ΄ββΆβ΄βββββ΄β₯ββββ΄βββββ
βββΆβ΄βββββΆβ¬β΄ββββΆβ¬ββββ·β
ββββββ₯βββ΄βββ₯ββ΄β΄βββββ₯β
ββββββββββ₯ββ΅βββββ·β΅βββ
ββββ΄ββ΅βββ·β΅ββΆβ΄ββ΄ββ΄βββ΅β
βββββ΄ββββ΄ββ΄βββββ΄βββββ