Maze generation: Difference between revisions

m (→‎{{header|J}}: Example maze is not solvable, but the solution is already marked "buggy")
Line 5:
=={{header|J}}==
 
This algorithm allows almost no parallelism. So, while it might be "simple", it will not be necessarily efficient to implement on future (highly parallel) systems.
FIXME: buggy (this particular example is not solvable), not enough walls
 
FromAnyways, based on the picolisp implementation, except without any relevant grid support:
 
<lang j>maze=:4 :0
Line 14:
unvisited=. 0,0,~|:0,0,~1$~y,x
path=.,:here=. ?x,y
while.#path1 e.,unvisited do.
unvisited=.0 (<1+here+1)} unvisited
neighbors=. here+"1 (,-)=0 1 ,:1 0
neighbors=. neighbors #~ (<"1 neighbors+1) {unvisited
if.#neighbors do.
next=. ({~ ?@#) neighbors
if.{.next=here
do. horiz=.1 (<-:here+next-0 31)} horiz
else.verti=. 1 (<-:here+next-31 0)} verti end.
path=.path,here=.next
else.
Line 29:
end.
end.
(horiz,.1{.~-x);1 0,verti
)
 
display=:3 :0
size=. 2+$>{.&$&>/y
text=. (}:1 3$~2*1+{:size)#"1":size$<' '
'hdoor vdoor'=. 2 4 &*L:0&.>&.> (#&,{@;&i./@$)&.> y
2 4}._2 _4}.' ' (30 8+L:1;0 hdoor)}2; '0 '3;(2 1-~$text);(1 4&+&.> hdoor),,vdoor+L:0&.>"0/2 51;2 62;2 73)} text
)</lang>
 
Line 43:
<lang j> display 12 maze 16
+ +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| | | | | |
+ + + ---+---+ +---+---+ +--- + +---+---+ +---+ +---+---+ +
| | | | | | | | | | | | |
+ + ---+---+ + + ---+---+ + + + ---+---+ + ---+---+ + +
| | | | | | | | | | | | |
+ +---+ +---+---+ +--- +--- +--- + +---+---+ + + +---+ + +
| | | | | | | | | | | | | |
+---+ + ---+---+---+ +--- +---+---+ + + + +---+ ---+---+---+
| | | | | | | | | | | | |
+ + + +---+---+ +---+ +---+ + +---+ +---+ +---+--- + +
| | | | | | | | | | | |
+ + +---+---+ ---+---+ ---+---+ +---+---+ + +---+---+---+---+ + +
| | | | | | | | | | | | |
+ +---+---+---+---+ + +--- + +--- + +---+---+--- + + +---+---+ +
| | | | | | | | | | | |
+ + +---+ + + + +---+---+ +---+---+---+ ---+ + + + + ---+
| | | | | | | | | | | | | | |
+ + + + ---+ + + ---+ + +---+ +---+---+---+---+---+ +
| | | | | | | | | | | | | |
+ +---+ + +--- + +---+ +---+---+ + + +---+---+ + + +---+
| | | | | | | | | | | | | | | |
+---+ + +--- + +---+ +---+---+ + +---+ +---+---+---+ + +
| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+</lang>
 
6,962

edits