Maze generation: Difference between revisions
m
→{{header|Uiua}}
(Added POV-Ray solution) |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 25:
V hor = [[‘+--’] * w [+] [String(‘+’)]] * (h + 1)
F walk(Int x, Int y) ->
@vis[y][x] = 1
V d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, y - 1)]
Line 7,279:
=={{header|POV-Ray}}==
This POV-Ray solution uses an iterative rather than recursive approach because POV-Ray has a small stack for recursion (about 100 levels) and so the program would crash on even quite small mazes. With the iterative approach it works on very large mazes.
<syntaxhighlight lang="pov">
#version 3.7;
Line 7,289 ⟶ 7,290:
#declare Cols = 17;
#declare Seed = seed(2); // A seed
#declare Wall = prism {
0, 0.8, 7,
<0, -0.5>, <0.05, -0.45>, <0.05, 0.45>, <0, 0.5>,
<-0.05, 0.45>, <-0.05, -0.45>, <0, -0.5>
texture {
pigment {
Line 7,348 ⟶ 7,350:
#local Col = floor(rand(Seed)*(Cols-1) + 0.5); // Random start column
#local Top = -1;
Push(Stack, Top, Row, Col, Row, Col)
Line 7,377 ⟶ 7,378:
Push(Stack, Top, Row, Col, Row, Col-1)
#end
#end
Line 7,441 ⟶ 7,438:
light_source {
<-0.1*Cols, Rows, 0.5*Rows>, colour rgb <1, 1, 1>
area_light
x, y, 3, 3
Line 7,467 ⟶ 7,464:
</syntaxhighlight>
{{out}}
[[File:Povray maze solution 640px.png|640px|frame|none|alt=POV-Ray maze with red brick walls|POV-Ray solution with 15 rows and 17 columns]]
=={{header|Processing}}==
Line 10,065 ⟶ 10,062:
=={{header|Uiua}}==
{{works with|Uiua|0.
{{trans|Python}}
Inspired by the Python algorithm, so will produce
NOTE: this code is extended in [https://rosettacode.org/wiki/Maze_solving#Uiua the Maze Solving page] so please update
that page if you change this code.
<syntaxhighlight lang="Uiua">
# Build and solve a maze.
H ← 8▼
# Experimental!
GetWall ← -:⊡1:÷2/-.
# ([here, next], maze) -> (maze')
BreakWall ←
Shuffle ← ⊏⍏[⍥⚂]⧻.
# (pos maze) -> T if it's already a star.
IsVisited ←
MarkAsVisited ← ⟜(
# (pos) -> (bool)
InBounds ← ▽⊸≡(↧⊃(/↧≥1_1|/↧< +1 × 2 H_W))
# (here, maze) -> (maze')
Walk ← |2 (
MarkAsVisited
# (here, maze) -> ([[here, next] x(up to)4], maze)
≡⊟¤⟜(Shuffle
# Update maze for each in turn. For each, if it
# still isn't visited, break the wall, recurse into it.
∧(
)
# Generate a maze.
↘¯1☇1↯(+1H)⊟⊂/⊂↯W"+-" @+⊂/⊂↯W"| " @| # Build a filled maze.
Walk 1_1 # Walk around breaking walls.
)
Maze
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ "+-+-+-+-+-+-+-+-+-+-+"
"|.|.|. .|. . . . . .|"
"+ + + + + +-+-+ +-+ +"
"|.|. .|. . .|. .|. .|"
"+ + +-+-+-+-+ +-+ +-+"
"|.|.|. . . .|.|. . .|"
"+ + + +-+-+ + +-+-+ +"
"|.|.|. .|. .|. .|. .|"
"+ +-+-+ + +-+-+ + +-+"
"|. . .|.|. . . .|. .|"
"+-+-+ + +-+-+-+-+-+ +"
"|. . . .|. . . . . .|"
"+-+-+-+-+-+-+-+-+-+-+"
╯
</pre>
=={{header|Wren}}==
|