Advertisement
TeoremaPi

Iluminar

Apr 11th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. -- programa que pone luces de forma optima en una planicie delimitada por bloques
  2.  
  3. -- huecos entre una fila y otra
  4. -- dis = 3 -> oxxxo
  5. -- y: hacia adelante, x: hacia la derecha
  6. disX = 5
  7. disY = 11
  8.  
  9. turtle.select(1)
  10.  
  11. function colocarLampara(xf,yf)
  12.  
  13.     fila = (xf - 1)/(disX + 1) + 1
  14.  
  15.     desfase = (disY + 1)/2*fila
  16.  
  17.     condicion = (yf - desfase)%(disY + 1) == 1
  18.  
  19.     if condicion then
  20.         while (turtle.getItemCount() == 0) and (turtle.getSelectedSlot() < 16) do
  21.             turtle.select(turtle.getSelectedSlot() + 1)
  22.         end
  23.        
  24.         if (turtle.getItemCount() == 0) and (turtle.getSelectedSlot() == 16) then
  25.             return false
  26.         end
  27.        
  28.         turtle.digDown()
  29.         turtle.placeDown()
  30.    
  31.     end
  32.     return true
  33. end
  34.  
  35. x = 1
  36. y = 0
  37. difY = 1
  38.  
  39. while true do
  40.     while turtle.forward() do
  41.         y = y + difY
  42.  
  43.         if not colocarLampara(x,y) then
  44.             print("colocar")
  45.             return
  46.         end
  47.     end
  48.        
  49.     if difY == 1 then
  50.         turtle.turnRight()
  51.     else
  52.         turtle.turnLeft()
  53.     end
  54.  
  55.     for k = 1, disX + 1 do
  56.         if not turtle.forward() then
  57.             print("final")
  58.             return
  59.         end
  60.  
  61.         x = x + 1
  62.     end
  63.  
  64.     if difY == 1 then
  65.         turtle.turnRight()
  66.     else
  67.         turtle.turnLeft()
  68.     end
  69.  
  70.     if not colocarLampara(x,y) then
  71.         print("colocar")
  72.         return
  73.     end
  74.  
  75.     difY = difY*(-1)
  76.  
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement