Skip to content
/ maze Public

Maze creation with recursive backtracking in Elixir

Notifications You must be signed in to change notification settings

derek121/maze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maze

Create a maze using a recursize 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.

Example

Maze.Common.create_grid(20, 20)
|> Maze.RecursiveBacktracking.MazeRB.carve_passages_from({0,0})
|> Maze.Display.format()
|> IO.puts()
┌───┬┬──┬─────┬─────┐
┝──┐││╷┌┘┌─┐╶┐╵┌╴┌┬╴│
│╷╶┘│╵││╶┥╷└┐└─┥┌┘╵┌┥
│┝──┘╶┥└╴│└┐└┐┌┘│╶┬┘│
│┝─┬─┐└──┿╴┝┐└┥┌┴┐│╷│
│╵╷│╷└───┘┌┥└╴│╵╷│╵││
┝─┥╵┝───┬─┘│┌─┴┐│┝─┘│
│╶┴┬┘╷┌╴└┬╴││┌╴┝┘┝─┐│
│╷╶┥┌┘┝─┐╵┌┘│└┐╵┌┘╷││
│┝╴││┌┘╷└┐│╶┥╷└─┥╶┥││
┝┘┌┘│╵┌┴┐└┿╴│┝─┐└╴│└┥
│┌┘┌┴─┥╶┴┐╵┌┴┘╷┝──┴┐│
││╶┿─┐╵╷╶┴─┴╴┌┥│╶─┐││
│└┐╵╷┝─┴┐╷┌──┥│└┬╴│││
┝╴└┬┘│╶┐└┘│╷╷╵└┐╵┌┘││
│┌╴│╶┴┐┝──┴┥│┌─┴─┘┌┘│
││╶┴─┐││╶┬╴│││╶┬──┘╷│
│└───┥│└╴│┌┥└┴╴┝─┐┌┥│
│┌──┐││┌─┥│╵┌──┘╷╵│││
│└─╴│╵└┘╷╵│╶┴─╴┌┴─┘╵│
└───┴───┴─┴────┴────┘

About

Maze creation with recursive backtracking in Elixir

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages