gpt4 book ai didi

algorithm - 迷宫算法栈溢出

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:22:34 25 4
gpt4 key购买 nike

我正在尝试使用递归除法 (here) 为我的游戏创建一个简单的迷宫生成器,但我遇到了堆栈溢出异常。 (TBH,我真的很困惑......)这是代码(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)

我真的不知道我做错了什么。好吧,在此先感谢...

最佳答案

代码看起来不错。问题可能出在 Random.RandomRange 上。这可能有用:http://answers.unity3d.com/questions/549908/script-not-working-5.html

关于algorithm - 迷宫算法栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27789257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com