Maze generation: Difference between revisions

m
(Mathematica)
Line 2,101:
RandomSample@{# + {0, 1}, # - {0, 1}, # + {1, 0}, # - {1,
0}}}]} &@RandomChoice@unvisited; maze];
maze = MazeGraphics[1321, 2113]</lang>
{{Out}}
[[File:MathematicaMazeGraphics.png]]
Line 2,109:
<lang mathematica>MazeGraph[m_, n_] :=
Block[{$RecursionLimit = Infinity, grid = GridGraph[{m, n}],
visited = {}},
Graph[Range[m edges = {}}n], Reap[{AppendTo[visited, #];
Do[If[FreeQ[visited, neighbor],
AppendTo If[edgesFreeQ[visited, # <-> neighbor]; #0@neighbor], {neighbor,
Sow[# <-> neighbor]; #0@neighbor], {neighbor,
RandomSample@AdjacencyList[grid, #]}]} &@
RandomChoice@VertexList@grid;][[2, 1]],
Graph[Range[m n], edges,
GraphLayout -> {"GridEmbedding", "Dimension" -> {m, n}}]];
maze = MazeGraph[13, 21]</lang>