Advertisement
Guest User

fulldig.lua

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. -- For Clearing Space to the left and to the left, 3 dimenstions
  2. -- @BertMoTron
  3. -- place the robot facing forward
  4.  
  5. -- number of steps
  6. local nOne = 0
  7. local nTwo = 0
  8. local nThr = 0
  9. local nTwoLess = 0
  10. -- check for arguments
  11.  
  12. args = {...}
  13.  
  14. if args[1] ~= nil then
  15.   -- make sure it's a number
  16.   local oneArg = tonumber(args[1])
  17.   if oneArg then
  18.     nOne = oneArg
  19.   end
  20. end
  21.  
  22. if args[2] ~= nil then
  23.  -- make sure it's a number
  24.     local twoArg = tonumber(args[2])
  25.   if twoArg then
  26.     nTwo = twoArg
  27.     nTwoLess = (twoArg - 1)
  28.   end
  29. end
  30.  
  31. if args[3] ~= nil then
  32.   local thrArg = tonumber(args[3])
  33.   if thrArg then
  34.     nThr = thrArg
  35.   end
  36. end
  37.  
  38. local robot = require("robot")
  39. local computer = require("computer")
  40.  
  41.  
  42. local FUEL_SLOT=1
  43. local FILL_SLOT=16
  44.  
  45. function rS()
  46.    os.sleep(0.3)
  47. end
  48.  
  49. function rF()
  50.   return robot.forward()
  51. end
  52.  
  53. function rB()
  54.   return robot.back()
  55. end
  56.  
  57. function rL()
  58.   return robot.turnLeft()
  59. end
  60.  
  61. function rR()
  62.   return robot.turnRight()
  63. end
  64.  
  65. function rUp()
  66.   return robot.up()
  67. end
  68.  
  69. function rDown()
  70.   return robot.down()
  71. end
  72.  
  73.  
  74.  
  75. function errorM()
  76.   print("ERROR!!! ERROR!!!! WILL ROBINSON!!!")
  77. end
  78.  
  79. function tF()
  80.   if rF() == false then
  81.     return errorM()
  82.   end
  83.   print("move Forward!!!!!!!!!!")
  84. end
  85.  
  86. function tB()
  87.   if rB() == false then
  88.      return errorM()
  89.   end
  90. end  
  91.  
  92. function tL()
  93.   if rL() == false then
  94.     return errorM()
  95.   end
  96. end
  97.  
  98. function tR()
  99.   if rR() == false then
  100.     return errorM()
  101.   end
  102. end
  103.  
  104. function tUp()
  105.   if rUp() == false then
  106.     return errorM()
  107.   end
  108. end
  109.  
  110. function tDown()
  111.   if rDown() == false then
  112.     return errorM()
  113.   end
  114. end
  115. -- Refuel
  116. function rFuel()
  117.   print("Fuelvl: " ..computer.energy())
  118.   if computer.energy() <= 500 then
  119.     computer.shutdown()
  120.   elseif computer.energy() <= 10000 and robot.space(FUEL_SLOT) < 63 then
  121.     os.execute("fuel.lua " ..FUEL_SLOT.. " 1")
  122.     print("Fuelvl: " ..computer.energy())
  123.     rS()
  124.   end
  125. end
  126.  
  127. function dirDig(direction)
  128.   if direction == -1 then
  129.     return robot.swingDown()
  130.   elseif direction == 1 then
  131.     return robot.swingUp()
  132.   else
  133.     return robot.swing()
  134.   end
  135. end
  136.  
  137. function dirDtect(direction)
  138.   if direction == -1 then
  139.     return robot.detectDown()
  140.   elseif direction == 1 then
  141.     return robot.detectUp()
  142.   else
  143.     return robot.detect()
  144.   end
  145. end
  146.  
  147. -- are you sand/gdetectravel or is there sand/gravel above you
  148. function tDig(direction)
  149.   local d = 0
  150.   if dirDtect(direction) == true then
  151.     while dirDtect(direction) and d < 16 do
  152.       d = d + 1
  153.       print("tDig" ..d)
  154.       dirDig(direction)
  155.     end
  156.   end
  157. end
  158.  
  159.    
  160. function chop()
  161.   rFuel()
  162.   tDig(0)
  163.   tDig(-1)
  164.   tDig(1)
  165. end
  166.  
  167. -- startUp()
  168. -- rFurnance
  169.  
  170. function cutLine()
  171.  if nOne > 1 then
  172.     for i=2, nOne do
  173.       rS()
  174.       print("cutLine" ..i)
  175.       rS()
  176.       chop()
  177.       rS()
  178.       tF()
  179.       rS()
  180.     end
  181.  end
  182. end
  183.  
  184.  
  185. function cutLineLeft()
  186.   for i=1, nTwo do
  187.     rS()
  188.     cutLine()
  189.     rS()
  190.      -- turn left, right or not to turn
  191.     if i <= nTwoLess and i % 2 == 0 then
  192.         tR()
  193.         chop()
  194.         tF()
  195.         tR()
  196.     elseif i <= nTwoLess and i % 2 == 1 then
  197.         tL()
  198.         chop()
  199.         tF()
  200.         tL()
  201.     end
  202.   end
  203.   if nTwo % 2 == 1 then
  204.     tL()
  205.     tL()
  206.     cutLine()
  207.     print("cutLineLeft: " ..nTwo)
  208.   end
  209. end
  210.  
  211.  
  212. function reCut()
  213.   if nTwoLess >= 1 then
  214.     for i=1, nTwoLess do
  215.       rS()
  216.       print("going back" ..nTwo.. ".")
  217.       rS()
  218.       chop()
  219.       rS()
  220.       tF()
  221.       rS()
  222.     end
  223.   end
  224. end
  225.  
  226. --main
  227. function full_Cut_Left()
  228.   for i=1, nThr do
  229.     cutLineLeft()
  230.     tL()
  231.     rS()
  232.     reCut()
  233.     rS()
  234.     tL()
  235.     tDig(1)
  236.     if i <= (nThr - 1) then
  237.       rS()
  238.       rUp()
  239.       rS()
  240.       tDig(1)
  241.       rS()
  242.       rUp()
  243.       rS()
  244.       tDig(1)
  245.       rS()
  246.       rUp()
  247.       rS()
  248.     end
  249.   end
  250.   if nThr >= 2 then
  251.     for i=2, nThr do
  252.       rS()
  253.       tDig(-1)
  254.       rS()
  255.       rDown()
  256.       rS()
  257.       tDig(-1)
  258.       rS()
  259.       rDown()
  260.       rS()
  261.       tDig(-1)
  262.       rS()
  263.       rDown()
  264.       rS()
  265.     end
  266.   end
  267. end
  268.  
  269.  
  270. --Start up
  271. full_Cut_Left()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement