Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function vPath(width, height, depth)
- local dirs = {"forward", "left", "right", "up", "back"}
- local depthTravelled = 1
- local widthTravelled = 1
- local heightTravelled = 1
- local shiftRight = false
- local shiftLeft = false
- local goBack = false
- return function()
- --the turtle has been through every block
- if heightTravelled == height and widthTravelled == width and depthTravelled == depth then
- return nil
- end
- --if either of these flags are true, the turtle is in the middle of shifting columns
- --that means the turtle will turn, then move forward along the depth axis
- --therefore, dt must be incremented by 1
- if shiftRight == true then
- depthTravelled = depthTravelled + 1
- shiftRight = false
- return dirs[3]
- elseif shiftLeft == true then
- depthTravelled = depthTravelled + 1
- shiftLeft = false
- return dirs[2]
- elseif goBack == true then
- depthTravelled = depthTravelled + 1
- goBack = false
- return dirs[5]
- end
- --if the turtle has reached the end of a column
- if depthTravelled == depth then
- --reset dt; the turtle is starting on a new column
- depthTravelled = 1
- --if the turtle has reached the end of a layer
- if widthTravelled == width then
- goBack = true
- --reset the width travelled
- widthTravelled = 1
- --go to the next layer
- heightTravelled = heightTravelled + 1
- return dirs[4]
- end
- --if the turtle is in the middle of a layer, shift columns
- --if width is even, flip turn direction at every even height
- --if wt % 2 == 1, turn right, else turn left
- local flip = (width%2 == 0 and heightTravelled % 2 == 0)
- if (widthTravelled%2 == 0 and flip) or (widthTravelled%2 == 1 and not flip) then
- shiftRight = true
- widthTravelled = widthTravelled + 1
- return dirs[3]
- else
- shiftLeft = true
- widthTravelled = widthTravelled + 1
- return dirs[2]
- end
- end
- depthTravelled = depthTravelled + 1
- return dirs[1]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement