JerryWester

[ComputerCraft] [Turtle] Maze Solver

Nov 9th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. turtle.select(1) -- This uses the "Right Hand" rule, so don't expect it to always work
  2. print("Make sure to put a fuel source in slot 1")
  3. print("Press any key to continue...")
  4. sleep(0.1)
  5. os.pullEvent("char")
  6.  
  7. function clr()
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10. end
  11.  
  12. function refuel()
  13.     if turtle.getFuelLevel() == 0 then
  14.         if turtle.getItemCount() > 0 then
  15.             turtle.refuel(1)
  16.             return true
  17.         else
  18.             return false
  19.         end
  20.     else
  21.         return true
  22.     end
  23. end
  24.  
  25. function move()
  26.     turtle.turnRight()
  27.     local count = 0
  28.     while turtle.detect() do
  29.         if count ~= 4 then
  30.             turtle.turnLeft()
  31.             count = count + 1
  32.         else
  33.             return false
  34.         end
  35.     end
  36.     if turtle.forward() then
  37.         return true
  38.     else
  39.         return false
  40.     end
  41. end
  42.  
  43. clr()
  44. print("Press ctrl+t to terminate the program.")
  45. while true do
  46.     if refuel() then
  47.         if not move() then
  48.             break
  49.         end
  50.     else
  51.         break
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment