Alkerss

Robot TreeFarm + Charcoal

Aug 5th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. -- Request for Project: Always revert back to previous selected slot after changing it
  2. robot = require("robot")
  3. local component = require("component")
  4. local g = component.generator
  5. x=14
  6. z=16
  7. CounterTrees = 0
  8.  
  9. function hugoCutTree()
  10.   CounterTrees = CounterTrees + 1
  11.   robot.swing()
  12.   while not robot.forward() do robot.swing() end
  13.   robot.swingDown()
  14.   PlaceDownSafe(1)
  15.   local counter = 0
  16.   while robot.detectUp() do
  17.     robot.swingUp()
  18.     if robot.up() then counter = counter + 1 end
  19.   end
  20.   while counter > 0 do
  21.     robot.swingDown()
  22.     if robot.down() then counter = counter - 1 end
  23.   end
  24.   PlaceDownSafe(1)
  25. end
  26.  
  27. function PlaceDownSafe( Min )
  28.   if robot.count( 16 ) > Min then
  29.     robot.placeDown()
  30.     return true
  31.   else
  32.     return false
  33.   end
  34. end
  35.  
  36. function TreeTile()
  37.         while robot.detect() == true do robot.swing() end
  38.         robot.swing()
  39.     robot.forward()
  40.     robot.suckDown()
  41. end
  42. function CobbleTile()
  43.   if robot.detect() then hugoCutTree() else robot.forward(); PlaceDownSafe(1) end
  44.   robot.suckDown()
  45. end
  46.  
  47. function Tile()
  48.   if TileSwitch == true then
  49.     TreeTile()
  50.     TileSwitch = false
  51.   else
  52.     CobbleTile()
  53.     TileSwitch = true
  54.   end
  55. end
  56.  
  57. while true do
  58.   --print("Let me chop chop trees!")
  59.   --os.pullEvent("char")
  60.   --print("CHOP CHOP nom nom nom....")
  61.   TileSwitch = false
  62.   statsCountTrees = {}
  63.   robot.turnLeft()
  64.   robot.turnLeft()
  65.   robot.select(1)
  66.   robot.suck(64)
  67.   g.insert(64)
  68.   robot.turnLeft()
  69.   robot.turnLeft()
  70.   robot.up()
  71.   robot.turnLeft()
  72.   robot.select(16) -- Careful!
  73.   Tile()
  74.   --TODO: Reful me, feed me, master! (CHECK)
  75.  
  76.   for i=1,z do
  77.     for j=1,x do Tile() end
  78.  
  79.     if i < z then
  80.       if i%2 == 0 then robot.turnLeft() else robot.turnRight() end
  81.       Tile()
  82.       if i%2 == 0 then robot.turnLeft() else robot.turnRight() end
  83.     else
  84.       Tile()
  85.       if i%2 == 1 then robot.turnLeft() else robot.turnRight() end
  86.       for j=1,z-1 do Tile() end    
  87.     end
  88.   end
  89.  
  90.   robot.down()
  91.   robot.turnLeft()
  92.   robot.turnLeft()
  93.   for i=1,15 do
  94.     robot.select(i)
  95.     robot.dropDown()
  96.   end
  97.   robot.select(16)
  98.   term.clear()
  99.   print("Finished, Master, chopped ", CounterTrees, " trees :)")
  100.   statsCountTrees[table.maxn(statsCountTrees)+1] = CounterTrees
  101.   CounterTrees = 0
  102.   do
  103.     local sum = 0
  104.     local avg = 0
  105.     for i,v in ipairs(statsCountTrees) do sum = sum + v end
  106.     avg = sum / table.maxn(statsCountTrees)
  107.     print("Statistics for you:")
  108.     print("Total: ",sum)
  109.     print("Average: ",avg)
  110.     print("Fuel: ",robot.getFuelLevel())
  111.   end
  112.   --print("")
  113.  
  114.   --print("Press anything to pause me in next 10sec...")
  115.   --os.timer(10)
  116.   --local event, param = os.pullEvent()
  117.   --if param < "timer" then
  118.     --print("Paused!!! Press anything to continue...")
  119.     --os.pullEvent()
  120.   --end
  121. end
Advertisement
Add Comment
Please, Sign In to add comment