- Home /
Maze Algorithm Problem
Hi, I'm trying to create a simple maze generator for my game, using the Recursive Division Method ( http://en.wikipedia.org/wiki/Maze_generation_algorithm ) But I'm getting stack overflow exceptions. (TBH, I'm really confused...) Here's the code (Boo):
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...
Comment