I built a DFS maze generator a while back. It actually uses a the DFS algorithm, as opposed to KermMartian's misnamed generator, which returns long-corridor mazes. Any help in optimizing would be greatly appreciated.

Code:
::"DFS mazemaker
::"FFFDC441D55FD111DFFDC401F7F7D411D5D5D515D57DC501DDFDC101FFFFFFFF
:If G
:Goto C
:1→R
:AxesOff
:ClrDraw
:Vertical Xmin+∆X
:Shade(Ymin+∆Y,Ymax-∆Y,Xmin+∆X,,Xmax-∆X
:Vertical Xmax-∆X
:2→E:92→C
:{0→L₁
:Lbl C
:0→G
:Lbl B
:If getKey
:Goto D
:Pxl-Off(E,C
:0→H
:augment(randIntNoRep(1,4),{2→L₃
:Repeat H=5 or pxl-Test(E+2((D=3)-(D=1)),C+2((D=2)-(D=4
:H+1→H
:L₃(ans→D
:End
:If H=5
:Goto A
:R+1→R
:augment({D},L₁→L₁
:Pxl-Off(E+(D=3)-(D=1),C+(D=2)-(D=4
:E+2((D+3)-(D=1→E
:C+2((D=2)-(D=4→C
:Goto B
:Lbl A
:If 1=dim(L₁
:Stop
:L₁(1→D
:C+2(ans=4)-2(Ans=2→C
:E+2(D=1)-2(D=3→E
:∆List(cumSum(L₁→L₁
:Goto B
:Lbl D
:1→G
:ClrHome
:Output(1,1,round(100(R/1380),2
:Output 1,6,"percent
Nice work with this, it looks quite optimized! You could remove some of those Lbls and Gotos with Repeat and While, but you make up for it with the exploitation of augment( and randIntNoRep. Smile What inspired you to write this? I hope you'll package it up with a readme and some screenshots and submit it to the Cemetech file archives. A note on my DFS generator: it uses a depth-first algorithm to explore the two-dimensional "tree" of the maze's space, descending as far as it can into the subdivisions of each subspace before backing out and subdividing the next subspace. You accurately described it as a recursive division algorithm on SAX; that recursive division is what makes its search method for un-divided spaces depth-first. Smile
Thanks, KermMartian. it wasn't very hard to replace them, and it runs much smoother now. Here's the updated

Code:
::"DFS mazemaker
::"FFDC441D55FD111DFFDC401F7F7D411D5D5D515D57DC501DDFDC101FFFFFFFF
:While not(G=π
:AxesOff
:ClrDraw
:Vertical Xmin+ΔX
:Shade(Ymin+ΔY,Ymax-ΔY,Xmin+ΔX,Xmax-ΔX
:Vertical Xmax-ΔX
:2→E:92→C
:{0→L₁
:π→G
:End
:Repeat 1=dim(L₁
:If getKey
:Return
:Pxl-Off(E,C
:0→H
:augment(randIntNoRep(1,4),{2→L₃
:Repeat H=5 or pxl-Test(E+2((D=3)-(D=1)),C+2((D=2)-(D=4
:H+1→H
:L₃(ans→D
:End
:While (H≠5) and (H≠π)
:augment({D},L₁→L₁
:Pxl-Off(E+(D=3)-(D=1),C+(D=2)-(D=4
:E+2((D+3)-(D=1→E
:C+2((D=2)-(D=4→C
:π→H
:End
:If H≠5
:end
:L₁(1→D
:C+2(ans=4)-2(Ans=2→C
:E+2(D=1)-2(D=3→E
:∆List(cumSum(L₁→L₁
:End
:Pause
:0→G
Nice work on this! Very cool. I have one quick question; I've not tested this out, but this section:


Code:
:Pxl-Off(E+(D=3)-(D=1),C+(D=2)-(D=4
:E+2((D+3)-(D=1→E
:C+2((D=2)-(D=4→C


Should D+3 be D=3? Just wondering. Thanks! Smile
Oops... Typo! yes, D+3 should be D=3
Hmm, I was just looking this over again, and I'm pretty sure the following will not work well:
Code:
:If H≠5
:End
:L₁(1→D
:C+2(ans=4)-2(Ans=2→C
:E+2(D=1)-2(D=3→E
:∆List(cumSum(L₁→L₁
:End
If H≠5, then that second End will not be attached to any loop. You should just make H≠5 be the escape condition of the enclosing loop.
Basically, if H=5, then it will run that last section of code. Otherwise, it'll go back to the start of the Repeat 1=dim(L1 loop. It's a shorter way of writing an If-Then statement. Alternatively, it could be

Code:
:If H=5
:Then
:L₁(1→D
:C+2(ans=4)-2(Ans=2→C
:E+2(D=1)-2(D=3→E
:∆List(cumSum(L₁→L₁
:End
:End

This takes up more precious memory, and it'll have to parse that code without doing anything until it gets to an End token if H≠5. Alternatively, it could just jump back to the Return, which it'll have to do anyways. I see your point, however. This technique wouldn't work with 68K BASIC, it's really exploiting a fault in the z80 processor.
So I was playing around with an unfinished maze in the graphscreen (that's how I got that lovely 16x16 icon,) and I noticed that I could 'trick' the program into thinking it had already been places. Not only that, but the surroundings-awareness section of my code only recognizes one in four pixels. This allows for infinite loops, provided that there are random blank spaces in the program. But then I went further. I created rooms.
if you do this:

Code:
000000000
00     00
00     00
00  0  00
000000000
where a 0 is an on pixel, then, if it's aligned so that the 'door' is one of the pixels that can be sensed, then the cursor will 'walk into' the room, then, since it's got no open pixels, it'll backtrack.
This immediately creates possibilities. if you use the Xlib command real(12, then you can get boxes all over the screen. Who knows how this development could prove useful?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement