Guest User

Hilbert Turtle Miner

a guest
May 16th, 2014
1,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. -- https://en.wikipedia.org/wiki/Hilbert_curve
  2. -- The Hilbert Curve can be expressed by a rewrite system (L-system).
  3. --     Alphabet : A, B
  4. --     Constants : F + -
  5. --     Axiom : A
  6. --     Production rules:
  7. --     A → - B F + A F A + F B -
  8. --     B → + A F - B F B - F A +
  9. -- Here, F means "draw forward", - means "turn left 90°", + means "turn right 90°" (see turtle graphics), and "A" and "B" are ignored during drawing.
  10.  
  11. currentSlot = 1
  12. torchInterval = 13      -- Must correspond to lineLength
  13. lineLength = 4
  14. recursiveDepth = 4
  15. repetition = 1
  16. distance = 0
  17.  
  18. function A(depth)
  19.  
  20.    if depth < 1 then return end
  21.    print("A" .. depth)
  22.    turtle.turnLeft()
  23.    B(depth - 1)
  24.    F()
  25.    turtle.turnRight()
  26.    A(depth - 1)
  27.    F()
  28.    A(depth - 1)
  29.    turtle.turnRight()
  30.    F()
  31.    B(depth - 1)
  32.    turtle.turnLeft()
  33.  
  34. end
  35.  
  36. function B(depth)
  37.  
  38.    if depth < 1 then return end
  39.    print("B" .. depth)
  40.    turtle.turnRight()
  41.    A(depth - 1)
  42.    F()
  43.    turtle.turnLeft()
  44.    B(depth - 1)
  45.    F()
  46.    B(depth - 1)
  47.    turtle.turnLeft()
  48.    F()
  49.    A(depth - 1)
  50.    turtle.turnRight()
  51.  
  52. end
  53.  
  54. function F()
  55.  
  56.    for i = 1, lineLength do
  57.       turtle.dig()
  58.       turtle.forward()
  59.       turtle.digDown()
  60.       distance = distance + 1
  61.  
  62.       if distance % torchInterval == 0 then
  63.          if turtle.getItemCount(currentSlot) > 1 then
  64.             turtle.placeDown()
  65.          else
  66.             currentSlot = currentSlot + 1
  67.             turtle.select(currentSlot)
  68.             if currentSlot <= 16 and turtle.getItemCount(currentSlot) > 1 then
  69.                   turtle.placeDown()
  70.             end
  71.          end
  72.       end
  73.    end
  74. end
  75.  
  76. -- MAIN
  77.  
  78. -- Fuel completely before starting
  79. -- Torches in all slots
  80. -- Does not gather resources!
  81. turtle.select(1)
  82.  
  83. for i=1, repetition do
  84.    print("Repetition " .. repetition)
  85.    A(recursiveDepth)
  86. end
Advertisement
Add Comment
Please, Sign In to add comment