12 lines
457 B
Plaintext
12 lines
457 B
Plaintext
MazeGraph[m_, n_] :=
|
|
Block[{$RecursionLimit = Infinity, grid = GridGraph[{m, n}],
|
|
unvisitedQ}, unvisitedQ[_] := True;
|
|
Graph[Range[m n], Reap[{unvisitedQ[#] = False;
|
|
Do[
|
|
If[unvisitedQ[neighbor],
|
|
Sow[# <-> neighbor]; #0@neighbor], {neighbor,
|
|
RandomSample@AdjacencyList[grid, #]}]} &@
|
|
RandomChoice@VertexList@grid][[2, 1]],
|
|
GraphLayout -> {"GridEmbedding", "Dimension" -> {m, n}}]];
|
|
maze = MazeGraph[13, 21]
|