Advertisement
Blackhome

Reaktorraum

Apr 14th, 2015
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. local length = 3
  2. local width = 4
  3. local height = 3
  4. local bigness = 1
  5.  
  6. local g_length = length + 2 * bigness
  7. local g_width = width + 2 * bigness
  8. local g_height = height + 2 * bigness
  9.  
  10. local nl = 1
  11. local nw = 1
  12. local nh = 1
  13.  
  14. local l_pos = 1
  15. local w_pos = 1
  16. local h_pos = 1
  17.  
  18. function turtleF()
  19.     while turtle.detect() == true do
  20.         turtle.dig()
  21.         sleep(1)
  22.     end
  23.     turtle.forward()
  24. end
  25.  
  26. function turtleD()
  27.     while turtle.detectDown() == true do
  28.         turtle.digDown()
  29.         sleep(1)
  30.     end
  31.     turtle.down()
  32. end
  33.  
  34. function go_length (l, pos)
  35.     local i = 1
  36.     if nl % 2 == 1 then
  37.     while i<l do
  38.         turtleF()
  39.         pos = pos + 1
  40.         i = i + 1
  41.     end
  42.     else
  43.         while i<l do
  44.             turtleF()
  45.             pos = pos - 1
  46.             i = i + 1
  47.         end
  48.     end
  49.     nl = nl + 1
  50.     return pos
  51. end
  52. function go_width (l, w, h, posl, posw)
  53.     local i = 0
  54.     if h % 2 == 1 then
  55.         if nw % 2 == 1 then
  56.             while i < w do
  57.                 posl = go_length(l, posl)
  58.                 if posl  == l and i < w - 1 then
  59.                     turtle.turnLeft()
  60.                     turtleF()
  61.                     turtle.turnLeft()
  62.                     posw = posw + 1
  63.                 elseif posl == 1 and i < w - 1 then
  64.                     turtle.turnRight()
  65.                     turtleF()
  66.                     turtle.turnRight()
  67.                     posw = posw + 1
  68.                 end
  69.                 i = i + 1
  70.             end
  71.         else
  72.             while i < w do
  73.                 posl = go_length(l, posl)
  74.                 if posl  == l and i < w - 1 then
  75.                     turtle.turnLeft()
  76.                     turtleF()
  77.                     turtle.turnLeft()
  78.                     posw = posw - 1
  79.                 elseif posl == 1 and i < w - 1 then
  80.                     turtle.turnRight()
  81.                     turtleF()
  82.                     turtle.turnRight()
  83.                     posw = posw - 1
  84.                 end
  85.                 i = i + 1
  86.             end
  87.         end
  88.     else
  89.         if nw % 2 == 1 then
  90.             while i < w do
  91.                 posl = go_length(l, posl)
  92.                 if posl  == l and i < w - 1 then
  93.                     turtle.turnRight()
  94.                     turtleF()
  95.                     turtle.turnRight()
  96.                     posw = posw + 1
  97.                 elseif posl == 1 and i < w - 1 then
  98.                     turtle.turnLeft()
  99.                     turtleF()
  100.                     turtle.turnLeft()
  101.                     posw = posw + 1
  102.                 end
  103.                 i = i + 1
  104.             end
  105.         else
  106.             while i < w do
  107.                 posl = go_length(l, posl)
  108.                 if posl  == l and i < w - 1 then
  109.                     turtle.turnRight()
  110.                     turtleF()
  111.                     turtle.turnRight()
  112.                     posw = posw - 1
  113.                 elseif posl == 1 and i < w - 1 then
  114.                     turtle.turnLeft()
  115.                     turtleF()
  116.                     turtle.turnLeft()
  117.                     posw = posw - 1
  118.                 end
  119.                 i = i + 1
  120.             end
  121.         end
  122.     end
  123.     nw = nw + 1
  124.     local a = {posl, posw}
  125.     return a
  126. end
  127.  
  128. function go_height (l, w, h, posl, posw, posh)
  129.     local i = 1
  130.     while i < h do
  131.         local pa = go_width (l, w, i, posl, posw)
  132.         posl = pa[1]
  133.         posw = pa[2]
  134.        
  135.         turtle.turnLeft()
  136.         turtle.turnLeft()
  137.         turtleD()
  138.         i = i + 1
  139.     end
  140.         posh = posh + 1
  141.  
  142.     local a = {posl, posw, posh}
  143.     return a
  144. end
  145.  
  146. local b1 = go_height (g_length, g_width, g_height, l_pos, w_pos, h_pos)
  147. local b2 = go_width (g_length, g_width, g_height, l_pos, w_pos)
  148. l_pos = b1[1]
  149. w_pos = b1[2]
  150. h_pos = b1[3]
  151. write(l_pos)
  152. write("\t")
  153. write(w_pos)
  154. write("\t")
  155. print(h_pos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement