maze2d: add attention shifting mechanism

This commit is contained in:
Starbeamrainbowlabs 2020-05-03 14:27:18 +01:00
parent 0554e37fcc
commit aa4ce5591d
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -82,6 +82,9 @@ function M.generate_maze(seed, width, height, path_length, path_width)
-- print("right | cx: "..cx..", target: "..cx+path_length..", value: '"..world[cy][cx + path_length].."', path_length: "..path_length) -- print("right | cx: "..cx..", target: "..cx+path_length..", value: '"..world[cy][cx + path_length].."', path_length: "..path_length)
end end
-- print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode) -- print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
local shift_attention = math.random(0, 9)
if #directions > 0 then if #directions > 0 then
-- we still have somewhere that we can go -- we still have somewhere that we can go
--print("This node is not a dead end yet.") --print("This node is not a dead end yet.")
@ -126,21 +129,22 @@ function M.generate_maze(seed, width, height, path_length, path_width)
end end
-- print("Now at ("..cx..", "..cy..")") -- print("Now at ("..cx..", "..cy..")")
table.insert(nodes, { x = cx, y = cy }) -- If the number of directions we could travel in was 1, then we've just travelled in the last remaining direction possible
if #directions > 1 then
table.insert(nodes, { x = cx, y = cy })
end
else else
--print("The node at " .. curnode .. " is a dead end.") --print("The node at " .. curnode .. " is a dead end.")
table.remove(nodes, curnode) table.remove(nodes, curnode)
end
if #directions == 0 or shift_attention <= 1 then
if #nodes > 0 then if #nodes > 0 then
--print("performing teleport."); --print("performing teleport.");
curnode = math.random(1, #nodes) curnode = math.random(1, #nodes)
--print("New node: " .. curnode)
-- print("Nodes table: ")
-- print_r(nodes)
cx = nodes[curnode]["x"] cx = nodes[curnode]["x"]
cy = nodes[curnode]["y"] cy = nodes[curnode]["y"]
else
--print("Maze generation complete, no teleportation necessary.")
end end
end end