Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 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. while
  31. end
  32. else
  33. print("Not enough Fuel !")
  34. end
  35. end
  36.  
  37. function turn(turndir) --turns the defined way
  38. if turndir == "right" then turtle.turnRight()
  39. else turtle.turnLeft() end
  40. end
  41.  
  42. function invturn(turndir) --turns the other way
  43. if turndir == "left" then turtle.turnRight()
  44. else turtle.turnLeft() end
  45. end
  46.  
  47. function moveNForward(n) --moves n blocks forward
  48. print("moving " ..n.. " blocks")
  49. if n~=nil then
  50. n = tonumber(n)
  51. for i = 0, n do
  52. turtle.forward()
  53. end
  54. else
  55. print("no input specified")
  56. end
  57. end
  58.  
  59. function reqMoves(n) --calculates the amount of moves and fuel required
  60. while n>0 do
  61. reqFuel = reqFuel+(n-1)*n
  62. n = (n-1)
  63. end
  64.  
  65. print(..reqFuel.." moves are required")
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement