Advertisement
DomMOW

RxRxR Room

Dec 31st, 2020 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. lengthMax = 4
  2. widthMax = 4
  3. heightMax = 5
  4. turn = 1
  5. turnLast = turn
  6. lengthCurrent = lengthMax
  7. placeTorch = 10
  8. width = widthMax
  9. finishWalk = widthMax
  10. heightMax = heightMax - 3
  11. height = heightMax
  12. ending = false
  13. kill = false
  14.  
  15. function left()
  16.   turtle.turnLeft()
  17. end
  18.  
  19. function right()
  20.   turtle.turnRight()
  21. end
  22.  
  23. function moveForward()
  24.   while turtle.detect() do
  25.     turtle.dig()
  26.   end
  27.   moved = false
  28.   while not(moved) do
  29.     moved = turtle.forward()
  30.   end
  31. end
  32.  
  33. function digForward()
  34.   while turtle.detect() do
  35.     turtle.dig()
  36.   end
  37. end
  38.  
  39. function digBelow()
  40.   while turtle.detectDown() do
  41.     turtle.digDown()
  42.   end
  43. end
  44.  
  45. function digAbove()
  46.   while turtle.detectUp() do
  47.     turtle.digUp()
  48.   end
  49. end
  50.  
  51. function moveUp()
  52.   turtle.digUp()
  53.   moved = false
  54.   while not(moved) do
  55.     turtle.up()
  56.     moved = turtle.up()
  57.   end
  58. end
  59.  
  60. function goDown()
  61.   turtle.down()
  62. end
  63.  
  64. function goUp()
  65.   turtle.up()
  66. end
  67.  
  68. function moveDown()
  69.   turtle.digDown()
  70.   moved = false
  71.   while not(moved) do
  72.     moved = turtle.down()
  73.   end
  74. end
  75.  
  76. function upBreak()
  77.   digAbove()
  78.   goUp()
  79.   digAbove()
  80. end
  81.  
  82. function leftDig()
  83.   turtle.turnLeft()
  84.   moveForward()
  85.   digAbove()
  86.   digBelow()
  87.   while height > 0 do
  88.     upBreak()
  89.     height = height - 1
  90.   end
  91.   height = heightMax
  92.   while height > 0 do
  93.     moveDown()
  94.     height = height - 1
  95.   end
  96.   height = heightMax
  97.   turtle.turnLeft()
  98. end
  99.  
  100. function rightDig()
  101.   turtle.turnRight()
  102.   moveForward()
  103.   digAbove()
  104.   digBelow()
  105.   while height > 0 do
  106.     upBreak()
  107.     height = height - 1
  108.   end
  109.   height = heightMax
  110.   while height > 0 do
  111.     moveDown()
  112.     height = height - 1
  113.   end
  114.   height = heightMax
  115.   turtle.turnRight()
  116. end
  117.  
  118. function leftWalk()
  119.   turtle.turnLeft()
  120.   moveForward()
  121.   digAbove()
  122.   digBelow()
  123.   while height > 0 do
  124.     upBreak()
  125.     height = height - 1
  126.   end
  127.   height = heightMax
  128.   while height > 0 do
  129.     moveDown()
  130.     height = height - 1
  131.   end
  132.   height = heightMax
  133. end
  134.    
  135. function rightWalk()
  136.   turtle.turnRight()
  137.   moveForward()
  138.   digAbove()
  139.   digBelow()
  140.   while height > 0 do
  141.     upBreak()
  142.     height = height - 1
  143.   end
  144.   height = heightMax
  145.   while height > 0 do
  146.     moveDown()
  147.     height = height - 1
  148.   end
  149.   height = heightMax
  150. end
  151.  
  152. while true do
  153.   if lengthCurrent > 0 and ending == false then
  154.     moveForward()
  155.     digAbove()
  156.     digBelow()
  157.     while height > 0 do
  158.       upBreak()
  159.       height = height - 1
  160.     end
  161.     height = heightMax
  162.     while height > 0 do
  163.       moveDown()
  164.       height = height - 1
  165.     end
  166.     height = heightMax
  167.     placeTorch = placeTorch - 1
  168.     lengthCurrent = lengthCurrent - 1
  169.     if placeTorch <= 0 then
  170.       placeTorch = 10
  171.       turtle.placeDown()
  172.     end
  173.   end
  174.   if lengthCurrent <= 0 and turn == 1 and width > 0 then
  175.     width = width - 1
  176.     if width > 0 then
  177.       rightDig()
  178.       lengthCurrent = lengthMax
  179.       turn = 2
  180.       print("Turned Right")
  181.     end
  182.   end
  183.   if lengthCurrent <= 0 and turn == 2 and width > 0 then
  184.     width = width - 1
  185.     if width > 0 then
  186.       leftDig()
  187.       lengthCurrent = lengthMax
  188.       turn = 1
  189.       print("Turned Left")
  190.     end
  191.   end
  192.   if width <= 0 then
  193.     turnLast = turn
  194.     turn = 3
  195.     ending = true
  196.   end
  197.   if width <= 0 and turn == 3 and ending == true then
  198.     print("Final Walk Home")
  199.     if turnLast == 1 then
  200.       lengthCurrent = lengthMax
  201.       left()
  202.       finishWalk = finishWalk - 1
  203.       while finishWalk > 0 do
  204.         moveForward()
  205.         finishWalk = finishWalk - 1
  206.       end
  207.       while lengthCurrent > 0 do
  208.         moveForward()
  209.         lengthCurrent = lengthCurrent - 1
  210.       end
  211.     end
  212.     if turnLast == 2 then
  213.       right()
  214.       finishWalk = finishWalk - 1
  215.       while finishWalk > 0 do
  216.         moveForward()
  217.         finishWalk = finishWalk - 1
  218.       end
  219.       right()
  220.     end
  221.     kill = true
  222.     turn = 4
  223.   end
  224.   if kill == true then
  225.     print("Killing the Program")
  226.     error()
  227.   end
  228. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement