Maze generation: Difference between revisions
Content added Content deleted
(Added Uiua solution) |
|||
Line 9,666: | Line 9,666: | ||
=== rendered 10x20 maze === |
=== rendered 10x20 maze === |
||
[[File:TSMaze.png]] |
[[File:TSMaze.png]] |
||
=={{header|Uiua}}== |
|||
{{works with|Uiua|0.10.3}} |
|||
{{trans|Python}} |
|||
Inspired by the Python algorithm, so will produce identical output. |
|||
<syntaxhighlight lang="Uiua"> |
|||
H ← 8 |
|||
W ← 18 |
|||
Ver ← 0 |
|||
Hor ← 1 |
|||
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 |
|||
OnlyInBounds ← ▽≡IsVisited ⊙¤,, # (finds the boundary 1's) |
|||
# (here, maze) -> (maze') |
|||
Walk ← |2 ( |
|||
# Mark as visited. |
|||
⟜(⍜(⊡|1◌)⊂Vis) |
|||
# Find neighbours. (here, maze) -> ([[here, next] x(up to)4], maze) |
|||
≡⊟¤⟜(Shuffle OnlyInBounds Neighbours) |
|||
# Update maze for each in turn. |
|||
∧( |
|||
# Is it visited? (check again due to recursion) |
|||
IsVisited◌°⊟,, |
|||
# Yes: Break NS/EW wall based on x == next x, recurse. |
|||
⟨◌|Walk ⊡1 ⟜(⟨BreakNS|BreakEW⟩=°⊟≡⊢.)⟩ |
|||
) |
|||
) |
|||
⊂↯H⊂↯W0 1↯+1W1 # vis (added 1's help bounds checks) |
|||
⊂↯H⊂↯W1 1↯+1W 0 # ver |
|||
↯+1H⊂↯W1 0 # hor |
|||
⊂⊟ |
|||
# Stack: ([ver, hor, vis]) |
|||
Walk [0 0] |
|||
PP! ← ≡/⊂∵^! # Pretty print using switch. |
|||
≡(&p$"_\n_")⊃(PP!⟨"+ "|"+--"⟩⊡Ver|PP!⟨" "|"| "⟩⊡Hor) |
|||
</syntaxhighlight> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |