Advertisement
Guest User

miner.lua

a guest
Mar 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local computer = require("computer")
  2. local robot = require("robot")
  3.  
  4. function forward( _steps)
  5.   for i = 1, _steps, 1 do
  6.     robot.forward()
  7.   end
  8. end
  9.  
  10. function mineForward( _steps)
  11.   for i = 1, _steps, 1 do
  12.     if robot.detect() then
  13.       robot.swing()
  14.     end
  15.     robot.forward()
  16.   end
  17. end
  18.  
  19. function back( _steps)
  20.   for i = 1, _steps, 1 do
  21.     robot.back()
  22.   end
  23. end
  24.  
  25. function up( _steps)
  26.   for i = 1, _steps, 1 do
  27.     robot.up()
  28.   end
  29. end
  30.  
  31. function down( _steps)
  32.   for i = 1, _steps, 1 do
  33.     robot.down()
  34.   end
  35. end
  36.  
  37. function mineRow()
  38.   while robot.detect() do
  39.     robot.swing()
  40.     forward(1)
  41.   end
  42. end
  43.  
  44. function left()
  45.   robot.turnLeft()
  46. end
  47.  
  48. function right()
  49.   robot.turnRight()
  50. end
  51.  
  52. function turnAround()
  53.   robot.turnAround()
  54. end
  55.  
  56. function toBottom()
  57.   while robot.down() do
  58.   end
  59. end
  60.  
  61. function use()
  62.     robot.use()
  63. end
  64.  
  65. function energyIsFull()
  66.     if computer.energy() >= (computer.maxEnergy() - 5) then
  67.         return true
  68.     else
  69.         return false
  70.     end
  71. end
  72.  
  73. function loadEnergy()
  74.     right()
  75.     forward(2)
  76.     right()
  77.     forward(3)
  78.     left()
  79.     forward(1)
  80.     left()
  81.     up(1)
  82.     use()
  83.     down(1)
  84.     while not energyIsFull() do  
  85.     end
  86.     up(1)
  87.     use()
  88.     down(1)
  89.     left()
  90.     forward(1)
  91.     right()
  92.     forward(3)
  93.     left()
  94.     forward(2)
  95.     right()
  96. end  
  97.  
  98. function mineLevel()
  99.   x = 0
  100.   y = 0
  101.   while y < 16 do
  102.     mineForward(15)
  103.     if x == 0 then
  104.       right()
  105.       mineForward(1)
  106.       right()
  107.       x = 1
  108.     else
  109.       left()
  110.       mineForward(1)
  111.       left()
  112.       x = 0
  113.     end
  114.     y = y + 1
  115.   end
  116.   mineForward(15)
  117.   left()
  118.   forward(16)
  119.   left()
  120.   forward(15)
  121.   turnAround()
  122. end
  123.  
  124. -- Gehe zur Startposition
  125.  
  126. mineLevel()
  127. for i = 1, 7, 1 do
  128.   up(1)
  129.   mineLevel()
  130. end
  131. -- loadEnergy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement