Advertisement
TwilightVulpine

Turtlebot Stairway 0.3

Apr 21st, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. test = true
  2. orientation = 0
  3. depth = 0
  4.  
  5. turtle.refuel()
  6.  
  7. function isInteresting()
  8.     interesting = false
  9.     if turtle.detect() then
  10.         common = false
  11.         for i=1,6 do -- cobble,stone,dirt,sandstone,sand,gravel
  12.             turtle.select(i)
  13.             common = common or turtle.compare()
  14.         end
  15.         interesting = not common
  16.     end
  17.    
  18.     if interesting then print("There is something interesting.") end
  19.     return interesting
  20. end
  21.  
  22. function isInterestingDown()
  23.     interesting = false
  24.     if turtle.detectDown() then
  25.         common = false
  26.         for i=1,6 do -- cobble,stone,dirt,sandstone,sand,gravel
  27.             turtle.select(i)
  28.             common = common or turtle.compareDown()
  29.         end
  30.         interesting = not common
  31.     end
  32.    
  33.     if interesting then print("There is something interesting below.") end
  34.     return interesting
  35. end
  36.  
  37. function isInterestingUp()
  38.     interesting = false
  39.     if turtle.detectUp() then
  40.         common = false
  41.         for i=1,6 do -- cobble,stone,dirt,sandstone,sand,gravel
  42.             turtle.select(i)
  43.             common = common or turtle.compareUp()
  44.         end
  45.         interesting = not common
  46.     end
  47.    
  48.     if interesting then print("There is something interesting above.") end
  49.     return interesting
  50. end
  51.  
  52. function carefulDescent()
  53.     fall = false
  54.     blocked = turtle.detectDown()
  55.     if blocked then turtle.digDown() end
  56.     descent = turtle.down()
  57.     if descent then depth = depth + 1 end
  58.     if not turtle.detectDown() then fall = true end
  59.     if fall then print("Fall below.") end
  60.     return not fall and descent
  61. end
  62.  
  63. function carefulAdvance()
  64.     fall = false
  65.     while turtle.detect() do turtle.dig() end
  66.     advance = turtle.forward()
  67.     if not turtle.detectDown() then fall = true end
  68.     if fall then print("Fall ahead.") end
  69.     return not fall and advance
  70. end
  71.  
  72. function goBack()
  73.     success = false
  74.     while orientation > 0 do
  75.         turtle.turnLeft()
  76.         orientation = orientation - 1
  77.     end
  78.    
  79.     while depth > 0 do
  80.         repeat
  81.             retreat = turtle.back()
  82.         until not retreat
  83.         success = turtle.up()
  84.         depth = depth - 1
  85.     end
  86.     repeat
  87.         retreat = turtle.back()
  88.     until not retreat
  89.     return success
  90. end
  91.  
  92. while turtle.getFuelLevel() > (depth * 4) do
  93.     warning = false
  94.     c=1
  95.     while c<4 do
  96.         warning = isInterestingUp()
  97.         warning = isInterestingDown()
  98.         while turtle.detectUp() do turtle.digUp() end
  99.         if not warning then carefulAdvance() else break end
  100.         for d=1,4 do
  101.             if not warning then
  102.                 turtle.turnRight()
  103.                 orientation = (orientation + 1) % 4
  104.                 warning = isInteresting()
  105.             else
  106.                 break
  107.             end    
  108.         end
  109.         c = c+1
  110.     end
  111.     if not warning then turtle.back() end
  112.     if not warning then warning = not carefulDescent() end
  113.     if warning then break end
  114. end
  115.  
  116. goBack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement