Page 1 of 1

Maze Generator

Posted: Sat May 10, 2003 8:22 pm
by Num3
Hi all...

I'm writing a maze generator, but it's not what i expected... :?

Can anyone help ???

here's what i've done...

(I'm using an array for now, but final version will use a memory buffer for ops :o )

Code: Select all


***** SCRAP ****

SEE BELOW  :P 


Posted: Sun May 11, 2003 11:59 am
by Num3
Well i was making a mistake on the previous code :lol:

Here's a working maze generator for PB :P

Code: Select all

;Maze Generator
;By Num3 - 2003
;Part of Wizards Dungeon Game

x  = Val(InputRequester("X", "X Size:", "32"))
y  = Val(InputRequester("Y", "Y Size:", "32"))

total  = (x  * y )


Dim maze(x, y)

xx  = Int(Random(x)/2)*2
yy  = Int(Random(y)/2)*2

For a  = 1 To total  * 2
  
  rnd  = Random(3)
  
  Select rnd
      
    Case 0 ;right
      If xx  + 2  < x And maze(xx  + 2, yy)=0 And maze(xx , yy)=0
        maze(xx  + 2, yy)=1
        maze(xx  + 1, yy)=1
        xx  + 2
      Else
        xx  = Int(Random(x)/2)*2
        yy  = Int(Random(y)/2)*2
      EndIf
      
    Case 1 ;left
      If xx  - 2  > 0 And maze(xx  - 2, yy)=0 And maze(xx , yy)=0
        maze(xx  - 2, yy)=1
        maze(xx  - 1, yy)=1
        xx  - 2
      Else
        xx  = Int(Random(x)/2)*2
        yy  = Int(Random(y)/2)*2
      EndIf
      
    Case 2 ;up
      If yy  + 2  < y And maze(xx, yy  + 2)=0 And maze(xx , yy)=0
        maze(xx , yy  + 2)=1
        maze(xx , yy  + 1)=1
        yy  + 2
      Else
        xx  = Int(Random(x)/2)*2
        yy  = Int(Random(y)/2)*2
      EndIf
      
    Case 3 ;down
      If yy  - 2  > 0 And maze(xx, yy  - 2)=0 And maze(xx , yy)=0
        maze(xx , yy  - 2)=1
        maze(xx , yy  - 1)=1
        yy  - 2
      Else
        xx  = Int(Random(x)/2)*2
        yy  = Int(Random(y)/2)*2
      EndIf
      
  EndSelect
  
Next

;Draw the container
For a  = 1 To x
  maze( a, 1)=1
  maze( a, y  - 1)=1
Next

For a  = 1 To y
  maze(1,  a)=1
  maze(x  - 1 , a)=1
Next

CreateImage(0,  x, y)
StartDrawing(ImageOutput())
For a  = 1 To x
  For b  = 1 To y
    If maze(a, b)=1
      Plot(a,  b , RGB(255, 255, 255))
    EndIf
  Next
Next
StopDrawing()

SaveImage(0,  "d:\temp\maze00.bmp")

Posted: Mon May 12, 2003 7:20 pm
by TronDoc
It looks like you've got a good start!
I think there's some old GW-BASIC code
out there somewhere that would help you
with things like making sure there's only
once possible solution. MAZE.BAS??
(but you probably already knew that! :D )
http://members.tripod.com/~baec/download.htm

Joe