maze3d: Add path variance support

This commit is contained in:
Starbeamrainbowlabs 2020-05-06 00:44:46 +01:00
parent 7a2eaeac82
commit 6efcb8428a
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 18 additions and 3 deletions

View File

@ -73,38 +73,48 @@ function M.generate_maze(seed, width, height, depth, path_length, path_width, pa
while #nodes > 0 do
-- io.write("Nodes left: " .. curnode .. "\r")
--print("Nodes left: " .. #nodes)
-- print("Currently at ("..cx..", "..cy..", "..cz.."), up: "..(cy-path_length)..", down: "..cy+path_length..", left: "..cx-path_length..", right: "..cx+path_length..", d++: "..cz+path_length..", d--: "..cz-path_length..", width: "..width..", height: "..height..", depth: "..depth)
local directions = "" -- the different directions we can move in
if cz - path_length > 0 and world[cz - path_length][cy][cx] == "#" then
directions = directions .. "-"
directions = directions .. "u"
-- print("d-- | cz: "..cz..", target: "..cz-path_length..", value: '"..world[cz - path_length][cy][cx].."', path_length: "..path_length)
end
if cz + path_length < depth-path_depth and world[cz + path_length][cy][cx] == "#" then
directions = directions .. "+"
-- print("d++ | cz: "..cz..", target: "..cz+path_length..", value: '"..world[cz + path_length][cy][cx].."', path_length: "..path_length)
end
if cy - path_length > 0 and world[cz][cy - path_length][cx] == "#" then
directions = directions .. "u"
-- print("up | cy: "..cy..", target: "..cy-path_length..", value: '"..world[cz][cy - path_length][cx].."', path_length: "..path_length)
end
if cy + path_length < height-path_width and world[cz][cy + path_length][cx] == "#" then
directions = directions .. "d"
-- print("down | cy: "..cy..", target: "..cy+path_length..", value: '"..world[cz][cy + path_length][cx].."', path_length: "..path_length)
end
if cx - path_length > 0 and world[cz][cy][cx - path_length] == "#" then
directions = directions .. "l"
-- print("left | cx: "..cx..", target: "..cx-path_length..", value: '"..world[cz][cy][cx - path_length].."', path_length: "..path_length)
end
if cx + path_length < width-path_width and world[cz][cy][cx + path_length] == "#" then
directions = directions .. "r"
-- print("right | cx: "..cx..", target: "..cx+path_length..", value: '"..world[cz][cy][cx + path_length].."', path_length: "..path_length)
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)
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)
print("chose '"..curdir.."'")
if curdir == "+" then
for iz = cz,cz+path_length+(path_depth-1) do
for ix = cx,cx+(path_width-1) do
for iy = cy,cy+(path_width-1) do
@ -116,7 +126,7 @@ function M.generate_maze(seed, width, height, depth, path_length, path_width, pa
-- world[cz + 2][cy][cx] = " "
cz = cz + path_length
elseif curdir == "-" then
for iz = cz,cz-path_length do
for iz = cz-path_length,cz do
for ix = cx,cx+(path_width-1) do
for iy = cy,cy+(path_width-1) do
world[iz][iy][ix] = " "
@ -172,7 +182,9 @@ function M.generate_maze(seed, width, height, depth, path_length, path_width, pa
cx = cx + path_length
end
table.insert(nodes, { x = cx, y = cy, z = cz })
if #directions > 1 then
table.insert(nodes, { x = cx, y = cy, z = cz })
end
else
table.remove(nodes, curnode)
end
@ -186,6 +198,9 @@ function M.generate_maze(seed, width, height, depth, path_length, path_width, pa
cz = nodes[curnode]["z"]
end
end
M.printspace(world, width, height, depth)
io.read("*l")
end
end_time = os.clock()