Make 3d mazes more 'branchy'

This commit is contained in:
Starbeamrainbowlabs 2020-04-30 01:59:23 +01:00
parent 6b39c130b6
commit f3a1874ab0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -93,12 +93,16 @@ function M.generate_maze(seed, width, height, depth)
directions = directions .. "r"
end
-- If this is 1 or less, then we will switch our attention to another candidate node after moving
local shift_attention = math.random(0, 3)
--print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
if #directions > 0 then
-- we still have somewhere that we can go
local curdirnum = math.random(1, #directions)
local curdir = string.sub(directions, curdirnum, curdirnum)
if curdir == "+" then
world[cz + 1][cy][cx] = " "
world[cz + 2][cy][cx] = " "
@ -128,6 +132,9 @@ function M.generate_maze(seed, width, height, depth)
table.insert(nodes, { x = cx, y = cy, z = cz })
else
table.remove(nodes, curnode)
end
if #directions == 0 or shift_attention <= 1 then
if #nodes > 0 then
curnode = math.random(1, #nodes)