maze2d: add attention shifting mechanism
This commit is contained in:
parent
0554e37fcc
commit
aa4ce5591d
1 changed files with 11 additions and 7 deletions
16
maze.lua
16
maze.lua
|
@ -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)
|
||||
end
|
||||
-- print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
|
||||
|
||||
local shift_attention = math.random(0, 9)
|
||||
|
||||
if #directions > 0 then
|
||||
-- we still have somewhere that we can go
|
||||
--print("This node is not a dead end yet.")
|
||||
|
@ -127,20 +130,21 @@ function M.generate_maze(seed, width, height, path_length, path_width)
|
|||
|
||||
-- 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
|
||||
--print("The node at " .. curnode .. " is a dead end.")
|
||||
table.remove(nodes, curnode)
|
||||
end
|
||||
|
||||
if #directions == 0 or shift_attention <= 1 then
|
||||
if #nodes > 0 then
|
||||
--print("performing teleport.");
|
||||
curnode = math.random(1, #nodes)
|
||||
--print("New node: " .. curnode)
|
||||
-- print("Nodes table: ")
|
||||
-- print_r(nodes)
|
||||
cx = nodes[curnode]["x"]
|
||||
cy = nodes[curnode]["y"]
|
||||
else
|
||||
--print("Maze generation complete, no teleportation necessary.")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue