1

I'm trying to create a simple maze generator for my game, using the Recursive Division Method ( here ) But I'm getting stack overflow exceptions. (TBH, I'm really confused...) Here's the code (Boo Script):

 def slice_v(x as int, y as int, w as int, h as int):
     d = Random.RandomRange(x, w)

     for i in range(y, h):
         maze[i, d] = Wall.VWall

     rem = Random.RandomRange(y, h)
     maze[rem, d] = 0

     Generate(x, y, d, h)
     Generate(d, y, w-d, h)

 def slice_h(x as int, y as int, w as int, h as int):
     d = Random.RandomRange(y, w)

     for i in range(x, w):
         maze[d, i] = Wall.HWall

     rem = Random.RandomRange(x, w)
     maze[d, rem] = 0

     Generate(x, y, w, d)
     Generate(x, d, w, h-d)

 def Generate(x as int, y as int, w as int, h as int):
     if w < 2 or h < 2: return

     if w > h:
         slice_v(x, y, w, h)
     elif w < h:
         slice_h(x, y, w, h)
     elif w == h:
         i = Random.RandomRange(0, 1)
         if i == 1:
             slice_v(x, y, w, h)
         else:
             slice_h(x, y, w, h)

I don't really know what am I doing wrong. Well, thanks in advance...

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
dcubix
  • 187
  • 2
  • 10
  • This is the first time I see boo language(thanks for that :) ) but as wiki page says one of the neighbors, are you sure you are choosing one of the neighbors? – Lrrr Jan 06 '15 at 06:24
  • Oh you're welcome haha :D Well, i'm using the Recursive Division Method. This is what it says on the wiki: " Begin with the maze's space with no walls. Call this a chamber. Divide the chamber with a randomly positioned wall (or multiple walls) where each wall contains a randomly positioned passage opening within it. Then recursively repeat the process on the subchambers until all chambers are minimum sized. " English is not my native language, so I'm having some problems undersanding... – dcubix Jan 06 '15 at 15:01
  • @dubix did you see this on wiki page? "As given above this algorithm involves deep recursion which may cause stack overflow issues on some computer architectures." – Lrrr Jan 07 '15 at 10:21

1 Answers1

0

The code looks ok. The problem may be with Random.RandomRange . This may be useful: http://answers.unity3d.com/questions/549908/script-not-working-5.html

Mary
  • 153
  • 2
  • 2
  • 9