Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- blocks = {
- 'redwood'
- }
- x = 0
- y = 0
- z = 0
- xv = 1
- yv = 0
- todo = {{0,0,0}}
- nodes = {['0,0,0']=1}
- explored = {}
- function digForward()
- while not turtle.forward() do
- turtle.dig()
- end
- x = x+xv
- y = y +yv
- end
- function digDown()
- while not turtle.down() do
- turtle.digDown()
- end
- z = z - 1
- end
- function digUp()
- while not turtle.up() do
- turtle.digUp()
- end
- z = z + 1
- end
- function turnRight()
- turtle.turnRight()
- if xv == 1 then
- xv, yv = 0, 1
- elseif xv == -1 then
- xv, yv = 0, -1
- elseif yv == 1 then
- yv, xv = 0, -1
- elseif yv == -1 then
- yv, xv = 0, 1
- end
- end
- function check(name)
- local a = false
- for k, pat in pairs(blocks) do
- a = a or name:find(pat)
- end
- return a
- end
- function newBlock(a, block, x,y,z)
- if a and check(block.name) then
- local newPoint = string.format('%i,%i,%i',x,y,z)
- if nodes[newPoint] then
- print('n: '..nodes[newPoint])
- todo[nodes[newPoint]] = nil
- end
- table.insert(todo, {x,y,z})
- print(#todo)
- nodes[newPoint] = #todo
- end
- end
- function newNode()
- local point = string.format('%i,%i,%i',x,y,z)
- if nodes[point] then
- todo[nodes[point]] = nil
- end
- explored[point] = true
- for i = 1, 4 do
- turnRight()
- local a, block = turtle.inspect()
- newBlock(a, block, x+xv,y+yv,z)
- end
- local a, block = turtle.inspectUp()
- newBlock(a, block, x,y,z+1)
- local a, block = turtle.inspectDown()
- newBlock(a, block, x,y,z-1)
- --goto first node on todo list
- end
- function sign(n)
- return (n > 0) and 1 or -1
- end
- function goto(gx,gy,gz)
- --print(string.format('cords: %i, %i, %i', x, y, z))
- --print(string.format('goals: %i, %i, %i', gx, gy, gz))
- --print(string.format('velocity: %i, %i', xv, yv))
- --print('Todo: '..tostring(#todo))
- if gx ~= x then
- while sign(gx-x) ~= xv do
- turnRight()
- end
- while x ~= gx do
- digForward()
- --newNode()
- end
- elseif gy ~= y then
- while sign(gy-y) ~= yv do
- turnRight()
- end
- --while y ~= gy do
- digForward()
- --newNode()
- --end
- elseif z ~= gz then
- if gz > z then
- digUp()
- --newNode()
- else
- digDown()
- end
- else return end
- newNode()
- goto(gx,gy,gz)
- end
- newNode()
- while #todo > 0 do
- if not todo[#todo] then table.remove(todo, #todo) print "table error" end
- goto(unpack(todo[#todo]))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement