Maze Generator

Just starting out? Need help? Post your questions and find answers here.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Maze Generator

Post 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 

Last edited by Num3 on Sun May 11, 2003 12:07 pm, edited 2 times in total.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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")
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post 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
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Post Reply