Maze algorithm stack overflow

654 Views Asked by At

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...

1

There are 1 best solutions below

0
Mary On

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