Maze generation: Difference between revisions
→{{header|J}}
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.
<lang j>maze=:4 :0
Line 14:
unvisited=. 0,0,~|:0,0,~1$~y,x
path=.,:here=. ?x,y
while.
unvisited=.0 (<
neighbors=. here+"1 (,-)=0 1
neighbors=. neighbors #~ (<"1 neighbors+1) {unvisited
if.#neighbors do.
next=. ({~ ?@#) neighbors
if.{.next=here
do. horiz=.1 (<-:here+next-0
else.verti=. 1 (<-:here+next-
path=.path,here=.next
else.
Line 29:
end.
end.
)
display=:3 :0
size=.
text=. (}:1 3$~2*1+{:size)#"1":size$<' '
'hdoor vdoor'=. 2 4
)</lang>
Line 43:
<lang j> display 12 maze 16
+ +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| |
+ +
|
+
|
+ +---+ +---+---+ +
| |
| | |
+ + + +---+---+ +---+ +---+ + +---
| | |
+ + +---+---+
+ +---+---+---+---+ + +
| |
+ + +---+ + + + +---+---+ +---+---+---+
| |
+ + + +
| | | |
+ +---+ + +
|
+---+ + +
| |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+</lang>
|