Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. --Main Program
  2. print("running Program !")
  3. CycleSquareRoom()
  4.  
  5.  
  6. --Functions
  7.  
  8. function CycleSquareRoom() --spirals through a n*n square room
  9. print("please define the length of your Square rooms sides")
  10. local sides = read()
  11. print("please define a turning direction [left or right]")
  12. local dir=read()
  13. print("turning" ..dir)
  14. local turns=sides-2
  15. local mov=sides-1
  16. local reqFuel = 0
  17.  
  18. reqMoves(mov)
  19.  
  20. if turtle.getFuelLevel()>reqFuel then
  21. while turns>0 and mov>1 do
  22. for i =0, turns do
  23. moveNForward(mov)
  24. turns = turns-1
  25. mov = mov-1
  26. turn(dir)
  27. print("turned " ..dir)
  28. end
  29. inturn(dir)
  30. end
  31. else
  32. print("Not enough Fuel !")
  33. end
  34. end
  35.  
  36. function turn(turndir) --turns the defined way
  37. if turndir == "right" then turtle.turnRight()
  38. else turtle.turnLeft() end
  39. end
  40.  
  41. function invturn(turndir) --turns the other way
  42. if turndir == "left" then turtle.turnRight()
  43. else turtle.turnLeft() end
  44. end
  45.  
  46. function moveNForward(n) --moves n blocks forward
  47. print("moving " ..n.. " blocks")
  48. if n~=nil then
  49. n = tonumber(n)
  50. for i = 0, n do
  51. turtle.forward()
  52. end
  53. else
  54. print("no input specified")
  55. end
  56. end
  57.  
  58. function reqMoves(n) --calculates the amount of moves and fuel required
  59. while n>0 do
  60. reqFuel = reqFuel+(n-1)*n
  61. n = (n-1)
  62. end
  63. print(reqFuel.." moves are required")
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement