Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Request for Project: Always revert back to previous selected slot after changing it
- robot = require("robot")
- local component = require("component")
- local g = component.generator
- x=14
- z=16
- CounterTrees = 0
- function hugoCutTree()
- CounterTrees = CounterTrees + 1
- robot.swing()
- while not robot.forward() do robot.swing() end
- robot.swingDown()
- PlaceDownSafe(1)
- local counter = 0
- while robot.detectUp() do
- robot.swingUp()
- if robot.up() then counter = counter + 1 end
- end
- while counter > 0 do
- robot.swingDown()
- if robot.down() then counter = counter - 1 end
- end
- PlaceDownSafe(1)
- end
- function PlaceDownSafe( Min )
- if robot.count( 16 ) > Min then
- robot.placeDown()
- return true
- else
- return false
- end
- end
- function TreeTile()
- while robot.detect() == true do robot.swing() end
- robot.swing()
- robot.forward()
- robot.suckDown()
- end
- function CobbleTile()
- if robot.detect() then hugoCutTree() else robot.forward(); PlaceDownSafe(1) end
- robot.suckDown()
- end
- function Tile()
- if TileSwitch == true then
- TreeTile()
- TileSwitch = false
- else
- CobbleTile()
- TileSwitch = true
- end
- end
- while true do
- --print("Let me chop chop trees!")
- --os.pullEvent("char")
- --print("CHOP CHOP nom nom nom....")
- TileSwitch = false
- statsCountTrees = {}
- robot.turnLeft()
- robot.turnLeft()
- robot.select(1)
- robot.suck(64)
- g.insert(64)
- robot.turnLeft()
- robot.turnLeft()
- robot.up()
- robot.turnLeft()
- robot.select(16) -- Careful!
- Tile()
- --TODO: Reful me, feed me, master! (CHECK)
- for i=1,z do
- for j=1,x do Tile() end
- if i < z then
- if i%2 == 0 then robot.turnLeft() else robot.turnRight() end
- Tile()
- if i%2 == 0 then robot.turnLeft() else robot.turnRight() end
- else
- Tile()
- if i%2 == 1 then robot.turnLeft() else robot.turnRight() end
- for j=1,z-1 do Tile() end
- end
- end
- robot.down()
- robot.turnLeft()
- robot.turnLeft()
- for i=1,15 do
- robot.select(i)
- robot.dropDown()
- end
- robot.select(16)
- term.clear()
- print("Finished, Master, chopped ", CounterTrees, " trees :)")
- statsCountTrees[table.maxn(statsCountTrees)+1] = CounterTrees
- CounterTrees = 0
- do
- local sum = 0
- local avg = 0
- for i,v in ipairs(statsCountTrees) do sum = sum + v end
- avg = sum / table.maxn(statsCountTrees)
- print("Statistics for you:")
- print("Total: ",sum)
- print("Average: ",avg)
- print("Fuel: ",robot.getFuelLevel())
- end
- --print("")
- --print("Press anything to pause me in next 10sec...")
- --os.timer(10)
- --local event, param = os.pullEvent()
- --if param < "timer" then
- --print("Paused!!! Press anything to continue...")
- --os.pullEvent()
- --end
- end
Advertisement
Add Comment
Please, Sign In to add comment