Maze generation: Difference between revisions
m
→{{header|Uiua}}: slightly nicer algorithm
(Added Uiua solution) |
m (→{{header|Uiua}}: slightly nicer algorithm) |
||
Line 9,679:
Vis ← 2
# Both are ([here, next], maze) -> (maze')▼
▲BreakNS ← ⍜⊡(0◌)⊂Ver⊂⊃(/↥≡(⊡0)|⊡0_1)
▲BreakEW ← ⍜⊡(0◌)⊂Hor⊂⊃(⊡0_0|/↥≡(⊡1))
Neighbours ← +⊙¤[[¯1 0] [1 0] [0 1] [0 ¯1]] # Gives N4
Shuffle ← ⊏⍏[⍥⚂]⧻.
IsVisited ← ¬⊡⊂Vis
MarkAsVisited ← ⟜(⍜(⊡|1◌)⊂Vis)▼
OnlyInBounds ← ▽≡IsVisited ⊙¤,, # (finds the boundary 1's)
# (here, maze) -> (maze')
Walk ← |2 (
MarkAsVisited
▲ ⟜(⍜(⊡|1◌)⊂Vis)
▲ # Find neighbours. (here, maze) -> ([[here, next] x(up to)4], maze)
≡⊟¤⟜(Shuffle OnlyInBounds Neighbours)
# Update maze for each in turn. For each, if it
# still isn't visited, break the wall, recurse into it.
∧(⟨◌|Walk ⊡1 ⟜BreakWall⟩IsVisited◌°⊟,,)
▲ ⟨◌|Walk ⊡1 ⟜(⟨BreakNS|BreakEW⟩=°⊟≡⊢.)⟩
)
|