Maze generation: Difference between revisions
Content added Content deleted
(Added Uiua solution) |
m (→{{header|Uiua}}: slightly nicer algorithm) |
||
Line 9,679: | Line 9,679: | ||
Vis ← 2 |
Vis ← 2 |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Neighbours ← +⊙¤[[¯1 0] [1 0] [0 1] [0 ¯1]] # Gives N4 |
Neighbours ← +⊙¤[[¯1 0] [1 0] [0 1] [0 ¯1]] # Gives N4 |
||
Shuffle ← ⊏⍏[⍥⚂]⧻. |
Shuffle ← ⊏⍏[⍥⚂]⧻. |
||
IsVisited ← ¬⊡⊂Vis |
IsVisited ← ¬⊡⊂Vis |
||
⚫ | |||
OnlyInBounds ← ▽≡IsVisited ⊙¤,, # (finds the boundary 1's) |
OnlyInBounds ← ▽≡IsVisited ⊙¤,, # (finds the boundary 1's) |
||
# (here, maze) -> (maze') |
# (here, maze) -> (maze') |
||
Walk ← |2 ( |
Walk ← |2 ( |
||
MarkAsVisited |
|||
# Mark as visited. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
≡⊟¤⟜(Shuffle OnlyInBounds Neighbours) |
≡⊟¤⟜(Shuffle OnlyInBounds Neighbours) |
||
# Update maze for each in turn. |
# Update maze for each in turn. For each, if it |
||
# still isn't visited, break the wall, recurse into it. |
|||
∧( |
|||
∧(⟨◌|Walk ⊡1 ⟜BreakWall⟩IsVisited◌°⊟,,) |
|||
# Is it visited? (check again due to recursion) |
|||
IsVisited◌°⊟,, |
|||
# Yes: Break NS/EW wall based on x == next x, recurse. |
|||
⚫ | |||
) |
|||
) |
) |
||