Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Xeda112358 on February 23, 2013, 04:07:51 pm

Title: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 23, 2013, 04:07:51 pm
I started working on a maze generating thingy after seeing KermM's  BASIC algorithm (http://www.cemetech.net/programs/index.php?mode=file&id=536) (using the DCS7 AnsStack command). I have coded this in Grammer and I am still working on optimising it more. If you want to edit the size of the path (2 pixels wide, 3 pixels wide, et cetera), open the source and change the value for →S. 2 makes a 1-pixel wide path, 6 makes a 5 pixel wide path, for example. On my actual calc, I have an actual game started, but I haven't been able to transfer my programs.

Here is the code:
Code: [Select]
:.0:Return
:Full
:3→S
:Fix 16
:96/S
:*64/S→A
:Send(+A,"VYπ→θ+A→Z
:π86EC→W
:π9340→V
:Lbl "BTR→T
:Lbl "pxl-Test(NEIGHBORS→U
:Fill(0→N→X→Y
:ClrDrawZ
:Disp W
:ClrDraw
:64/S→A
:96/S→B
:Horizontal A
:Vertical B
:Line(S*B-1,S*A-1,S,,0,V
:Pxl-On(A-1,B-1
:!Repeat N
:int(Z+N,X
:int(θ+N,Y
:Pxl-On(Y,X
:Line(1+S*X,1+S*Y,S-1,,0,V
:If 15=prgmU
:prgmT
:!Repeat and A
:e^(randInt(0,4
:End
:→A=2
:+X-A=1→X*S
:+1+A=1
:-A=2→B
:Y+A=4
:-A=8→Y*S
:+1+A=8
:-A=4→A
:Line(B,A,S-1,,0,V
:IS>(N
:Disp V:DispGraph:Disp W
:End
:Stop
:.BTR
:Repeat 15≠prgmU
:N-1→N
:If θ'
:Stop
:(+Z→X
:(θ+N→Y
:End
:End
:.pxl-Test(NEIGHBORS
:pxl-Test(Y-1,X
:+Ans+pxl-Test(Y+1,X
:+Ans+pxl-Test(Y,X+1
:+Ans+pxl-Test(Y,X-1→A
:End

That creates a maze that is guaranteed to have a path from the upper left corner to the lower right of the screen.
Title: Re: Random Maze Generation (Grammer)
Post by: Sorunome on February 23, 2013, 04:59:27 pm
Wow, that is pretty awesome, great job xeda! :D
Title: Re: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 23, 2013, 09:26:14 pm
I have a program on my calculator where you try to navigate through the maze. I inflated the pixels to 4x4 so you can only see a portion of the maze, and that should make it more challenging. Unfortunately, I cannot send anything from my calculator to my computer, so I will have to find time to type it into either WabbitEmu or SourceCoder later.
Title: Re: Random Maze Generation (Grammer)
Post by: DJ Omnimaga on February 23, 2013, 09:49:24 pm
For some reasons I kinda thought this would happen after I saw Kerm's program. :P

By the way, this could be handy to have such program in Axe or ASM (so that it can be launched from BASIC programs without an extra APP installed) for use in games, if for example someone was making an RPG with random dungeons. :P
Title: Re: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 24, 2013, 07:47:42 am
This is actually a type of algorithm that would be much better in Axe or Assembly, so I was thining of porting it later today. Luckily all three languages are similar enough that porting won't b too difficult.
Title: Re: Random Maze Generation (Grammer)
Post by: TIfanx1999 on February 24, 2013, 10:18:20 am
Cool stuff Xeda! ^^
Title: Re: Random Maze Generation (Grammer)
Post by: Sorunome on February 24, 2013, 03:58:32 pm
This is actually a type of algorithm that would be much better in Axe or Assembly, so I was thining of porting it later today. Luckily all three languages are similar enough that porting won't b too difficult.
Assembly being similar to axe? O.O
I never felt that way when trying, and failing, to learn asm.
Title: Re: Random Maze Generation (Grammer)
Post by: DJ Omnimaga on February 25, 2013, 12:52:15 am
It's just the higher level commands that look similar (eg Pxl-On, Pxl-test, etc). Otherwise Axe is pretty low level. ASM syntax looks weird compared to such language in general, which, I think, is what turns some people away, along with the way ASM in 28 days teaches it.
Title: Re: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 26, 2013, 06:52:10 am
I finally have the program all typed up and everything :) By changing the starting values:
S = Size of square
A is the height   (max=32)
B is the width    (max=48)

The larger the playing field, the longer it takes to create the maze and it takes so much longer to get through it o.o I am also working on another algorithm (slower, probably), that will hopefully make more complicated mazes.
Title: Re: Random Maze Generation (Grammer)
Post by: blue_bear_94 on February 26, 2013, 08:37:15 am
Why not make the character something other than a black square?
Title: Re: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 26, 2013, 08:40:34 am
You can change the size of the of the squares, so it was just easier than scaling a sprite to fit the size of the path. I did have a version that used a built in sprite when the path size was 5 pixels wide, but I got rid of it :/
Title: Re: Random Maze Generation (Grammer)
Post by: Sorunome on February 26, 2013, 05:31:34 pm
yeah, a different sprite for the character would be cool, but it is already awesome, your maze program O.O
Title: Re: Random Maze Generation (Grammer)
Post by: Xeda112358 on February 26, 2013, 05:39:52 pm
Earlier I tried making the sprite grayscale, but it was pretty laggy when the screen scrolled. I know how to fix it, but it would be a bit of a pain to implement it XD