I have recently made a random maze generation program, using the depth first search method, ( http://www.mazeworks.com/mazegen/mazetut/index.htm ) and it runs quite nicely, without a hitch, but is ungodly slow. Would anybody mind posting any Maze generation program you may have or anything, /me wansta know how to make mine better. Thanks Homies.
Mine? I didn't make one. The one you sent me didn't work though.
Edit: Oh I thought you linked to yours. Oops...
Edit: Oh I thought you linked to yours. Oops...
Just a minute... let me post the code I used in my project...
here it is (note, I removed some stuff that I used only because I needed it for my 3d maze game. Also, if you wanted to, you could change this so it only uses the graph screen and no matrix, I needed that because I needed this to work for my matrix engine and also so I could convert it to string easily.)
Code:
If something doesn't work its because I accidentally deleted to much
IIRC, it starts out, and then chooses random directions and tries random directions for the inputed number of attemps (more = more winding passages). If it doesn't go forward in those attemps, it backtracks one and tries again. It will then continue backtracking until it reaches the beginning and can't go anywhere. It produces pretty good mazes actually =D (No idea if this is what you used, I pretty much made it up myself  although someone has probably thought of it before =D )
here it is (note, I removed some stuff that I used only because I needed it for my 3d maze game. Also, if you wanted to, you could change this so it only uses the graph screen and no matrix, I needed that because I needed this to work for my matrix engine and also so I could convert it to string easily.)
Code:
:ClrHome
:ClrDraw
:GridOff
:AxesOff
:0→Xmin
:94→Xmax
:1→XScl
:0→Ymin
:62→YMax
:1→YScl
:Input "ATTEMPTS:",A
:Repeat H>9 and H<51
:Input "HEIGHT:",H
:End
:Repeat L>9 and L<96
:Input "LENGTH:",Str0
:If not(length(Str0)<2:Then
:sub(Str0,1,2)→Y1
:Else
:"9→Y1
:End
:Y1→L
:DelVar Y1
:End
:{H,L→dim([J]
:Fill 1,[J]
:For(X,1,L
:Line(X,61,X,62H
:End
:randInt(2,L1→X
:randInt(2,H1→Z
:PxlOff(Z,X
:0→[J](Z,X
:DelVar PDelVar RDelVar L2DelVar SDelVar TDelVar U
:100→dim(L2
:Repeat R
:Text(55,2,P," ",T,"",S," ",U,"
:DelVar L1
:4→dim(L1
:If X>3:Then
:If [J](Z,X2:1→L1(1:End
:If Z>3:Then
:If [J](Z2,X:1→L1(2:End
:If X<L2:Then
:If [J](Z,X+2:1→L1(3:End
:If Z<H2:Then
:If [J](Z+2,X:1→L1(4:End
:cumSum(L1
:If Ans(4) or P:Then
:DelVar V
:Repeat V>A or L1(D
:V+1→V
:randInt(1,4→D
:End
:If L1(D:DelVar V
:If V>A and P:Then
:L2(P→D
:0→L2(P
:P1→P
:X+2(D=1→X
:Z+2(D=2→Z
:X2(D=3→X
:Z2(D=4→Z
:DelVar D
:End
:If D=1 and X>3:Then
:P+1→P
:1→L2(P
:PxlOff(Z,X1
:PxlOff(Z,X2
:0→[J](Z,X1
:X2→X
:0→[J](Z,X
:End
:If D=2 and Z>3:Then
:P+1→P
:2→L2(P
:PxlOff(Z1,X
:PxlOff(Z2,X
:0→[J](Z1,X
:Z2→Z
:0→[J](Z,X
:End
:If D=3 and X<L2:Then
:P+1→P
:3→L2(P
:PxlOff(Z,X+1
:PxlOff(Z,X+2
:0→[J](Z,X+1
:X+2→X
:0→[J](Z,X
:End
:If D=4 and Z<H2:Then
:P+1→P
:4→L2(P
:PxlOff(Z+1,X
:PxlOff(Z+2,X
:0→[J](Z+1,X
:Z+2→Z
:0→[J](Z,X
:End
:If P>U:Then
:P→U
:X→S
:Z→T
:End
:Else
:1→R
:End
:End
:ClrDraw
If something doesn't work its because I accidentally deleted to much
IIRC, it starts out, and then chooses random directions and tries random directions for the inputed number of attemps (more = more winding passages). If it doesn't go forward in those attemps, it backtracks one and tries again. It will then continue backtracking until it reaches the beginning and can't go anywhere. It produces pretty good mazes actually =D (No idea if this is what you used, I pretty much made it up myself  although someone has probably thought of it before =D )
It seems like a version of the DFS method, but with a selectable whentostartbacktracking rate. I usually keep mine at if after 8 loops it doesnt find a way, it starts backtracking, and checking each square 8 times.
EDIT: Harq, that code wont stop asking me for the length. lol.
EDIT: Harq, that code wont stop asking me for the length. lol.
Pseudoprogrammer wrote:
EDIT: Harq, that code wont stop asking me for the length. 0x5.
Be sure you entered the if correctly, 9 < L < 96

Harq
 Calculator Deity (Posts: 1857)
 09 Mar 2007 11:51:59 pm
 Last edited by Harq on 09 Mar 2007 11:57:51 pm; edited 2 times in total
See this code?
Code:
I have no earthly idea what it does anymore besides bounds checking
Anyways, just enter 10 and 10 for both and tell me what happens...
EDIT: Nevermind, I have it, let me comment it for you =P
Code:
:Repeat H>9 and H<51
:Input "HEIGHT:",H ;straight forward, gets the height
:End
:Repeat L>9 and L<96 ;if to make sure the length is between 10 and 95
:Input "LENGTH:",Str0
:If not(length(Str0)<2 ;Then if the value from the last line is 2 digits
:sub(Str0,1,2)→Y1 ;store it to Y1 so I can work with it =P
:Else ;otherwise
:"9→Y1 ;store 9 to Y1 which is then stored to L which makes it false.
:End
:Y1→L
:DelVar Y1 ;clears Y1
:End ;loops back to length repeat
:{H,L→dim([J]
:Fill 1,[J]
:For(X,1,L
:Line(X,61,X,62H
:End
I have no earthly idea what it does anymore besides bounds checking
Anyways, just enter 10 and 10 for both and tell me what happens...
EDIT: Nevermind, I have it, let me comment it for you =P
Pseudoprogrammer wrote:
It just keeps saying input length.
o.O There is nothing wrong with that code, I went back and commented it for you!
Code:
:ClrHome
:ClrDraw
:GridOff
:AxesOff
:0→Xmin
:94→Xmax
:1→XScl
:0→Ymin
:62→YMax
:1→YScl
:Input "ATTEMPTS:",A
:Repeat H>9 and H<51
:Â¦ Input "HEIGHT:",H
:End
:Repeat L>9 and L<96
:Â¦ Input "LENGTH:",Str0
:Â¦ If not(length(Str0)<2:Then
:Â¦ Â¦ sub(Str0,1,2)→Y1
:Â¦ Â¦ Else
:Â¦ Â¦ "9→Y1
:Â¦ End
:Â¦ Y1→L
:Â¦ DelVar Y1
:End
:{H,L→dim([J]
:Fill 1,[J]
:For(X,1,L
:Â¦ Line(X,61,X,62H
:End
:randInt(2,L1→X
:randInt(2,H1→Z
:PxlOff(Z,X
:0→[J](Z,X
:DelVar PDelVar RDelVar L2DelVar SDelVar TDelVar U
:100→dim(L2
:Repeat R
:Â¦ Text(55,2,P," ",T,"",S," ",U,"
:Â¦ DelVar L1
:Â¦ 4→dim(L1
:Â¦ If X>3:Then
:Â¦ Â¦ If [J](Z,X2:1?L1(1:End
:Â¦ If Z>3:Then
:Â¦ Â¦ If [J](Z2,X:1?L1(2:End
:Â¦ If X<L2:Then
:Â¦ Â¦ If [J](Z,X+2:1?L1(3:End
:Â¦ If Z<H2:Then
:Â¦ Â¦ If [J](Z+2,X:1?L1(4:End
:Â¦ cumSum(L1
:Â¦ If Ans(4) or P:Then
:Â¦ Â¦ DelVar V
:Â¦ Â¦ Repeat V>A or L1(D
:Â¦ Â¦ Â¦ V+1→V
:Â¦ Â¦ Â¦ randInt(1,4→D
:Â¦ Â¦ End
:Â¦ Â¦ If L1(D:DelVar V
:Â¦ Â¦ If V>A and P:Then
:Â¦ Â¦ Â¦ L2(P→D
:Â¦ Â¦ Â¦ 0→L2(P
:Â¦ Â¦ Â¦ P1→P
:Â¦ Â¦ Â¦ X+2(D=1→X
:Â¦ Â¦ Â¦ Z+2(D=2→Z
:Â¦ Â¦ Â¦ X2(D=3→X
:Â¦ Â¦ Â¦ Z2(D=4?Z
:Â¦ Â¦ Â¦ DelVar D
:Â¦ Â¦ End
:Â¦ Â¦ If D=1 and X>3:Then
:Â¦ Â¦ Â¦ P+1→P
:Â¦ Â¦ Â¦ 1→L2(P
:Â¦ Â¦ Â¦ PxlOff(Z,X1
:Â¦ Â¦ Â¦ PxlOff(Z,X2
:Â¦ Â¦ Â¦ 0→[J](Z,X1
:Â¦ Â¦ Â¦ X2→X
:Â¦ Â¦ Â¦ 0→[J](Z,X
:Â¦ Â¦ End
:Â¦ Â¦ If D=2 and Z>3:Then
:Â¦ Â¦ Â¦ P+1→P
:Â¦ Â¦ Â¦ 2→L2(P
:Â¦ Â¦ Â¦ PxlOff(Z1,X
:Â¦ Â¦ Â¦ PxlOff(Z2,X
:Â¦ Â¦ Â¦ 0→[J](Z1,X
:Â¦ Â¦ Â¦ Z2→Z
:Â¦ Â¦ Â¦ 0→[J](Z,X
:Â¦ Â¦ End
:Â¦ Â¦ If D=3 and X<L2:Then
:Â¦ Â¦ Â¦ P+1→P
:Â¦ Â¦ Â¦ 3→L2(P
:Â¦ Â¦ Â¦ PxlOff(Z,X+1
:Â¦ Â¦ Â¦ PxlOff(Z,X+2
:Â¦ Â¦ Â¦ 0→[J](Z,X+1
:Â¦ Â¦ Â¦ X+2→X
:Â¦ Â¦ Â¦ 0→[J](Z,X
:Â¦ Â¦ End
:Â¦ Â¦ If D=4 and Z<H2:Then
:Â¦ Â¦ Â¦ P+1→P
:Â¦ Â¦ Â¦ 4→L2(P
:Â¦ Â¦ Â¦ PxlOff(Z+1,X
:Â¦ Â¦ Â¦ PxlOff(Z+2,X
:Â¦ Â¦ Â¦ 0?[J](Z+1,X
:Â¦ Â¦ Â¦ Z+2→Z
:Â¦ Â¦ Â¦ 0→[J](Z,X
:Â¦ Â¦ End
:Â¦ Â¦ If P>U:Then
:Â¦ Â¦ Â¦ P→U
:Â¦ Â¦ Â¦ X→S
:Â¦ Â¦ Â¦ Z→T
:Â¦ Â¦ End
:Â¦ Â¦ Else
:Â¦ Â¦ 1→R
:Â¦ End
:End
I repeat... the code in that area is fine
I can't double check it because I have lost my calc, and doubt I will find it, but it looks fine and that is what I entered...
I can't double check it because I have lost my calc, and doubt I will find it, but it looks fine and that is what I entered...
I would be interested to know how this can be adapted to old style RPG's like Rogue or Nethack. The basic idea is that you have several solution paths and remove all other cells, then place rooms so that they are adjacent to the path.
The light at the end of the tunnel is an oncoming dragon.
Give a man a fire, he'll be warm for a day; set fire to him, he'll be warm for the rest of his life.
Read the Smart Questions FAQ  they helped me!
Give a man a fire, he'll be warm for a day; set fire to him, he'll be warm for the rest of his life.
Read the Smart Questions FAQ  they helped me!
Harq wrote:
Just a minute... let me post the code I used in my project...
here it is (note, I removed some stuff that I used only because I needed it for my 3d maze game. Also, if you wanted to, you could change this so it only uses the graph screen and no matrix, I needed that because I needed this to work for my matrix engine and also so I could convert it to string easily.)
Code:
If something doesn't work its because I accidentally deleted to much
IIRC, it starts out, and then chooses random directions and tries random directions for the inputed number of attemps (more = more winding passages). If it doesn't go forward in those attemps, it backtracks one and tries again. It will then continue backtracking until it reaches the beginning and can't go anywhere. It produces pretty good mazes actually =D (No idea if this is what you used, I pretty much made it up myself  although someone has probably thought of it before =D )
here it is (note, I removed some stuff that I used only because I needed it for my 3d maze game. Also, if you wanted to, you could change this so it only uses the graph screen and no matrix, I needed that because I needed this to work for my matrix engine and also so I could convert it to string easily.)
Code:
:ClrHome
:ClrDraw
:GridOff
:AxesOff
:0→Xmin
:94→Xmax
:1→XScl
:0→Ymin
:62→YMax
:1→YScl
:Input "ATTEMPTS:",A
:Repeat H>9 and H<51
:Input "HEIGHT:",H
:End
:Repeat L>9 and L<96
:Input "LENGTH:",Str0
:If not(length(Str0)<2:Then
:sub(Str0,1,2)→Y1
:Else
:"9→Y1
:End
:Y1→L
:DelVar Y1
:End
:{H,L→dim([J]
:Fill 1,[J]
:For(X,1,L
:Line(X,61,X,62H
:End
:randInt(2,L1→X
:randInt(2,H1→Z
:PxlOff(Z,X
:0→[J](Z,X
:DelVar PDelVar RDelVar L2DelVar SDelVar TDelVar U
:100→dim(L2
:Repeat R
:Text(55,2,P," ",T,"",S," ",U,"
:DelVar L1
:4→dim(L1
:If X>3:Then
:If [J](Z,X2:1→L1(1:End
:If Z>3:Then
:If [J](Z2,X:1→L1(2:End
:If X<L2:Then
:If [J](Z,X+2:1→L1(3:End
:If Z<H2:Then
:If [J](Z+2,X:1→L1(4:End
:cumSum(L1
:If Ans(4) or P:Then
:DelVar V
:Repeat V>A or L1(D
:V+1→V
:randInt(1,4→D
:End
:If L1(D:DelVar V
:If V>A and P:Then
:L2(P→D
:0→L2(P
:P1→P
:X+2(D=1→X
:Z+2(D=2→Z
:X2(D=3→X
:Z2(D=4→Z
:DelVar D
:End
:If D=1 and X>3:Then
:P+1→P
:1→L2(P
:PxlOff(Z,X1
:PxlOff(Z,X2
:0→[J](Z,X1
:X2→X
:0→[J](Z,X
:End
:If D=2 and Z>3:Then
:P+1→P
:2→L2(P
:PxlOff(Z1,X
:PxlOff(Z2,X
:0→[J](Z1,X
:Z2→Z
:0→[J](Z,X
:End
:If D=3 and X<L2:Then
:P+1→P
:3→L2(P
:PxlOff(Z,X+1
:PxlOff(Z,X+2
:0→[J](Z,X+1
:X+2→X
:0→[J](Z,X
:End
:If D=4 and Z<H2:Then
:P+1→P
:4→L2(P
:PxlOff(Z+1,X
:PxlOff(Z+2,X
:0→[J](Z+1,X
:Z+2→Z
:0→[J](Z,X
:End
:If P>U:Then
:P→U
:X→S
:Z→T
:End
:Else
:1→R
:End
:End
:ClrDraw
If something doesn't work its because I accidentally deleted to much
IIRC, it starts out, and then chooses random directions and tries random directions for the inputed number of attemps (more = more winding passages). If it doesn't go forward in those attemps, it backtracks one and tries again. It will then continue backtracking until it reaches the beginning and can't go anywhere. It produces pretty good mazes actually =D (No idea if this is what you used, I pretty much made it up myself  although someone has probably thought of it before =D )
On the line :{H,L→dim([J] I get a syntax error at the [J] part. any help?
Epic necropost. Yes that is called a depth first search. But a more optimized version of that would check to see all squares around the current location, and pick a random one from that, instead of just picking random squares. I made a maze generator back in novemember that generates 16x16 mazes in <2 seconds.
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 likeminded coders and tech and calculator enthusiasts via the sitewide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
» 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
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