Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if require("component").isAvailable("generator")
- then
- generator=require("component").generator
- end
- withg=(generator~=nil)
- slots=16
- slotstocheck=2
- robot=require("robot")
- coords={x=0,y=0,z=0,side=1}
- extcoords={x=0,y=0,z=0,side=1}
- sx={0,1,0,-1}
- sy={1,0,-1,0}
- --1,2,3,4
- --tl -- coords.side = (coords.side + 3)%4
- --tr -- coords.side = (coords.side + 1)%4
- --ta -- coords.side = (coords.side + 2)%4
- --all -- if coords.side == 0 then coords.side =4 end
- function go() while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end
- function godown() while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end
- function goup() while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end
- function check() return robot.count(slots-(slotstocheck-1)) > 0 end
- function turnLeft() robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end
- function turnRight() robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end
- function tosurf()
- extcoords.x=coords.x
- extcoords.y=coords.y
- extcoords.z=coords.z
- extcoords.side=coords.side
- while coords.z ~= 0 do goup() end
- while coords.side ~= 3 do turnRight() end
- while coords.y ~= 0 do go() end
- turnRight();
- while coords.x ~= 0 do go() end
- turnLeft();
- end
- function back()
- while coords.z ~= extcoords.z do godown() end
- while coords.side~= 1 do turnRight() end
- while coords.y ~= extcoords.y do go() end
- turnRight();
- while coords.x ~= extcoords.x do go() end
- while coords.side ~= extcoords.side do turnRight() end
- end
- function clearinv()
- alreadyhave=false
- for invcounter=1,slots do
- robot.select(invcounter)
- if withg then
- suc,error=generator.insert()
- if (error=="selected slot does not contain fuel" or alreadyhave) then robot.drop() else alreadyhave=true end
- else
- robot.drop()
- end
- end
- robot.select(1)
- sort()
- end
- function sort()
- curs=1
- for q=1,slots do
- if robot.count(q) > 0 then robot.select(q);robot.transferTo(curs);curs=curs+1 end
- end
- robot.select(1)
- end
- function prevent()
- if check() then
- tosurf()
- clearinv()
- back()
- end
- end
- function digrow(n)
- prevent()
- robot.swingUp()
- prevent()
- robot.swingDown()
- for k=1,n do
- prevent()
- go()
- prevent()
- robot.swingUp()
- prevent()
- robot.swingDown()
- end
- end
- function digdim(x,y)
- godown()
- godown()
- for n=1,y do
- if tl then turnLeft() else turnRight() end
- digrow(ex)
- if tl then turnRight() else turnLeft() end
- tl = not tl
- if n==y then print("ok") else go() end
- end
- turnRight();
- turnRight();
- tl= not tl
- end
- x,y,z=...
- tl=false
- x=x+0
- y=y+0
- z=z+0
- ex=x-1
- fullz=(z-z%3)/3
- print("Fullz = " .. fullz)
- for i=1,fullz do
- digdim(x,y)
- godown()
- end
- if fullz*3==z then elseif fullz*3+1==z then goup();goup();digdim(tl,x,y) else goup();digdim(tl,x,y) end
- tosurf()
- clearinv()
Add Comment
Please, Sign In to add comment