Advertisement
TheProdigy22

Untitled

Nov 30th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. local function vPath(width, height, depth)
  2. local dirs = {"forward", "left", "right", "up", "back"}
  3. local depthTravelled = 1
  4. local widthTravelled = 1
  5. local heightTravelled = 1
  6. local shiftRight = false
  7. local shiftLeft = false
  8. local goBack = false
  9. return function()
  10. --the turtle has been through every block
  11. if heightTravelled == height and widthTravelled == width and depthTravelled == depth then
  12. return nil
  13. end
  14.  
  15. --if either of these flags are true, the turtle is in the middle of shifting columns
  16. --that means the turtle will turn, then move forward along the depth axis
  17. --therefore, dt must be incremented by 1
  18. if shiftRight == true then
  19. depthTravelled = depthTravelled + 1
  20. shiftRight = false
  21. return dirs[3]
  22. elseif shiftLeft == true then
  23. depthTravelled = depthTravelled + 1
  24. shiftLeft = false
  25. return dirs[2]
  26. elseif goBack == true then
  27. depthTravelled = depthTravelled + 1
  28. goBack = false
  29. return dirs[5]
  30. end
  31.  
  32. --if the turtle has reached the end of a column
  33. if depthTravelled == depth then
  34. --reset dt; the turtle is starting on a new column
  35. depthTravelled = 1
  36. --if the turtle has reached the end of a layer
  37. if widthTravelled == width then
  38. goBack = true
  39. --reset the width travelled
  40. widthTravelled = 1
  41. --go to the next layer
  42. heightTravelled = heightTravelled + 1
  43. return dirs[4]
  44. end
  45. --if the turtle is in the middle of a layer, shift columns
  46. --if width is even, flip turn direction at every even height
  47. --if wt % 2 == 1, turn right, else turn left
  48. local flip = (width%2 == 0 and heightTravelled % 2 == 0)
  49. if (widthTravelled%2 == 0 and flip) or (widthTravelled%2 == 1 and not flip) then
  50. shiftRight = true
  51. widthTravelled = widthTravelled + 1
  52. return dirs[3]
  53. else
  54. shiftLeft = true
  55. widthTravelled = widthTravelled + 1
  56. return dirs[2]
  57. end
  58. end
  59. depthTravelled = depthTravelled + 1
  60. return dirs[1]
  61. end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement