LostMiner

Untitled

Oct 28th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------Tunneling Automaton------
  2.  
  3. ----Variables----
  4.  
  5. t = turtle
  6. orientation = 1
  7.  
  8. ----Basic Digging and Control Operations----
  9.  
  10. --Orientation change, 1 is forward by initialization--
  11. function OCL()
  12.     if orientation == 4 then
  13.         orientation = 0
  14.     else
  15.         orientation = orientation + 1
  16.     end
  17. end
  18. function OCR()
  19.     if orientation == 1 then
  20.         orientation = 4
  21.     else
  22.         orientation = orientation - 1
  23.     end
  24. end
  25.  
  26. --Turning Left and Right--
  27. function TLE()
  28.     t.turnLeft()
  29.     OCL()
  30. end
  31. function TRI()
  32.     t.turnRight()
  33.     OCR()
  34. end
  35.  
  36. --Reorienting efficiently--
  37. function REO()
  38.     if orientation == 2 then
  39.         TLE()
  40.     elseif orientation == 3 then
  41.         TLE()
  42.         TLE()
  43.     elseif orientation == 4 then
  44.         TRI()
  45.     end
  46. end
  47.  
  48. --Digging in Basic Directions--
  49. function DUP()
  50.     t.digUp()
  51. end
  52. function DDO()
  53.     t.digDown()
  54. end
  55. function DFO()
  56.     t.digForward()
  57. end
  58.  
  59. --Moving in Basic Directions--
  60. function MUP()
  61.     t.up()
  62. end
  63. function MDO()
  64.     t.down()
  65. end
  66. function MFO()
  67.     t.forward()
  68. end
  69.  
  70. --Digging Left and Right--
  71. function DRI()
  72.     TRI()
  73.     DFO()
  74. end
  75. function DLE()
  76.     TLE()
  77.     DFO()
  78. end
  79.  
  80. --Moving Left and Right--
  81. function MRI()
  82.     TRI()
  83.     DFO()
  84. end
  85. function MLE()
  86.     TLE()
  87.     DFO()
  88. end
  89.  
  90. --Digging and Moving Efficiently--
  91. function DMU()
  92.     if t.detectUp() then
  93.         DUP()
  94.         MUP()
  95.     else
  96.         MUP()
  97.     end
  98. end
  99. function DMD()
  100.     if t.detectDown() then
  101.         DDO()
  102.         MDO()
  103.     else
  104.         MDO()
  105.     end
  106. end
  107. function DMF()
  108.     if t.detect() then
  109.         DFO()
  110.         MFO()
  111.     else
  112.         MFO()
  113.     end
  114. end
  115. function DMR()
  116.     TRI()
  117.     if t.detect() then
  118.         DFO()
  119.         MFO()
  120.     else
  121.         MFO()
  122.     end
  123. end
  124. function DML()
  125.     TLE()
  126.     if t.detect() then
  127.         DFO()
  128.         MFO()
  129.     else
  130.         MFO()
  131.     end
  132. end
  133.  
  134. --Input Distance--
  135. function dis()
  136.     print("Input Distance:")
  137.     num = io.read()
  138.     num = tonumber(num)
  139.     return num
  140. end
  141.  
  142. --Refuel based on distance--
  143. function fuel(distance)
  144.     t.refuel()
  145. end
  146.  
  147. ----Advanced Mining Operations----
  148.  
  149. function tunnel(distance)
  150.     if not t.getFuelLevel() >= distance then
  151.         fuel(distance-t.getFuelLevel())
  152.     end
  153.     while distance > 0 do
  154.         DMF()
  155.         DUP()
  156.         distance = distance - 1
  157.     end
  158. end
  159.  
  160. function hole(distance)
  161.     if not (t.getFuelLevel() >= distance) then
  162.         fuel(distance-t.getFuelLevel())
  163.     end
  164.     while distance > 0 do
  165.         DMD()
  166.         distance = distance - 1
  167.     end
  168. end
  169.  
  170. ----Main Loop----
  171. function main()
  172.     hole(dis())
  173. end
  174. --Run--
  175. main()
Add Comment
Please, Sign In to add comment