Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PF program - Path Finder
- -- Version: 1.0.3
- -- by @markman4897
- -- Requires MPR library.
- -- TODO:
- -- - make it use the 3 while loops so it
- -- first checks for x ignoring z and y
- -- and so on (V2.0.0)
- -- =========
- -- Variables
- -- =========
- -- Load MPR library
- os.loadAPI("MPR")
- -- Overwrite starting coords from MPR
- MPR.set("x",109)
- MPR.set("z",1021)
- MPR.set("y",93)
- MPR.set("dir",1)
- -- =========
- -- Functions
- -- =========
- -- Move to coordinates function
- function backTrack(dir)
- print(dir," STAGE 4")
- MPR.turn("left")
- MPR.move("forw",1,false)
- --verticalSolution = false
- end
- function verticalCheck(dir)
- verticalSolution = true
- print("VERTICAL SOLUTION TRUE !!!")
- print("VERTICAL SOLUTION TRUE !!!")
- print("VERTICAL SOLUTION TRUE !!!")
- print("VERTICAL SOLUTION TRUE !!!")
- if not(MPR.move("up",1,false)) then
- print(dir," STAGE 2.1")
- if not(MPR.move("down",1,false)) then
- print(dir," STAGE 2.2")
- backTrack(dir)
- end
- end
- end
- function horizontalCheck(dir)
- verticalSolution = false
- MPR.turn("left")
- if dir == "X" then
- ignoreZ = true
- else
- ignoreX = true
- end
- if not(MPR.move("forw",1,false)) then
- print(dir," STAGE 3.1")
- if not(MPR.move("back",1,false)) then
- print(dir," STAGE 3.2")
- backTrack(dir)
- end
- end
- end
- function xzMove(dir)
- if not(MPR.move("forw",1,false)) then
- print(dir," STAGE 1")
- if not verticalSolution then
- verticalCheck(dir)
- else
- horizontalCheck(dir)
- end
- end
- end
- function moveTo(x,z,y)
- print("Going to ",x,",",z,",",y)
- ignoreX = false
- ignoreZ = false
- ignoreY = false
- verticalSolution = false
- while (x~=MPR.get("x") or z~=MPR.get("z") or y~=MPR.get("y")) do
- moved = false
- if (x ~= MPR.get("x")) and not(ignoreX) then
- print("in X X X X X X cycle")
- ignoreZ = false
- if x > MPR.get("x") then
- MPR.turn("east")
- else
- MPR.turn("west")
- end
- xzMove("X")
- elseif (z ~= MPR.get("z")) and not(ignoreZ) then
- print("in Z Z Z Z Z Z cycle")
- ignoreX = false
- if z > MPR.get("z") then
- MPR.turn("south")
- else
- MPR.turn("north")
- end
- xzMove("Z")
- elseif (y ~= MPR.get("y")) and not(ignoreY) then
- print("in Y Y Y Y Y Y cycle")
- ignoreY = false
- if y > MPR.get("y") then
- where = "up"
- whereNot = "down"
- else
- where = "down"
- whereNot = "up"
- end
- if not(move(where,1,false)) then
- print("STAGE 1")
- if not(MPR.move("forw",1,false)) then
- print("STAGE 2")
- if not(MPR.move("back",1,false)) then
- print("STAGE 3")
- MPR.turn("left")
- if (dir==1 or dir==3) then
- ignoreZ = true
- else
- ignoreX = true
- end
- if not(MPR.move("forw",1,false)) then
- print("STAGE 4")
- if not(MPR.move("back",1,false)) then
- print("STAGE 5")
- move(whereNot)
- end
- end
- end
- end
- end
- end
- end
- print("Ended at ",MPR.get("x"),",",MPR.get("z"),",",MPR.get("y"))
- return true
- end
- -- ============
- -- Main program
- -- ============
- print("= Executing main program.")
- moveTo(121,1009,93) --the hard location
- --[[
- while true do
- moveTo(119,1025,85)
- print("DONE - DONE - DONE")
- moveTo(99,1016,92)
- print("DONE - DONE - DONE")
- end
- --]]
- -- Extra EXTRA!
- -- try:
- -- turtle.native.forward()
- -- turtle.native.left()
- -- and see if it rotates while moving forward
- -- or does it just not rotate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement