Advertisement
jifima68

gps

Mar 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.48 KB | None | 0 0
  1.  xp1,yp1,zp1 = gps.locate()
  2.  
  3. print("veuillez entrer les coordonnes")
  4. write ("x: ")
  5.  xd = tonumber(read())
  6. write ("\ny: ")
  7.  yd = tonumber(read())+1
  8. write ("\nz: ")
  9.  zd = tonumber(read())
  10.  
  11. -- voir dans quel sens est la tortue
  12.  
  13. turtle.forward()
  14. local xp2,yp2,zp2 = gps.locate()
  15.  
  16. if xd < xp2 then
  17.  
  18.     if xp1 < xp2 then
  19.     turtle.turnRight()
  20.     turtle.turnRight()
  21.     elseif xp1 == xp2 and zp1 < zp2 then
  22.     turtle.turnRight()
  23.     elseif xp1 == xp2 and zp1 > zp2 then
  24.     turtle.turnLeft()
  25.     end
  26.    
  27. end
  28.  
  29. if xd > xp2 then
  30.  
  31.     if xp1 > xp2 then
  32.     turtle.turnRight()
  33.     turtle.turnRight() 
  34.     elseif xp1 == xp2 and zp1 < zp2 then
  35.     turtle.turnLeft()
  36.     elseif xp1 == xp2 and zp1 > zp2 then
  37.     turtle.turnRight()
  38.     end
  39.    
  40. end
  41.  
  42. if xd == xp2 then
  43.     if zp1 > zp2 and zp2 < zd then
  44.     turtle.turnLeft()
  45.     turtle.turnLeft()
  46.     elseif zp1 < zp2 and zp2 > zd then
  47.     turtle.turnLeft()
  48.     turtle.turnLeft()
  49.     end
  50.    
  51. end
  52.  
  53.  
  54. -- faire déplacer la tortue
  55.  
  56. while xp2~=xd or yp2~=yd or zp2~=zd do
  57.  
  58. -- xd < xp2
  59.  
  60. if xd < xp2 then
  61. for i = 0, 1 do
  62.     if xp2~= xd then
  63.         if turtle.forward() then
  64.         if yd > yp2 and yd ~= yp2 then
  65.         turtle.up()
  66.         xp2,yp2,zp2 = gps.locate()
  67.         elseif yd < yp2 and yd ~= yp2 then
  68.         turtle.down()
  69.         xp2,yp2,zp2 = gps.locate()
  70.         end
  71.         xp2,yp2,zp2 = gps.locate()
  72.         else
  73.         while not turtle.forward() do
  74.             if not turtle.up() then
  75.             turtle.turnRight()
  76.             turtle.forward()
  77.             turtle.turnLeft()
  78.             xp2,yp2,zp2 = gps.locate()
  79.                 if not turtle.forward() then
  80.                 turtle.turnLeft()
  81.                 turtle.forward()
  82.                 turtle.forward()
  83.                 turtle.turnRight()
  84.                 turtle.forward()
  85.                 xp2,yp2,zp2 = gps.locate()
  86.                 end
  87.             end
  88.         end
  89.         xp2,yp2,zp2 = gps.locate()
  90.         end
  91.     end
  92. end
  93.  
  94. if zp2 > zd then
  95. turtle.turnRight()
  96.     for k = 0 , 1 do
  97.         if zp2 ~= zd then
  98.             if turtle.forward() then
  99.         if yd > yp2 and yd ~= yp2 then
  100.         turtle.up()
  101.         xp2,yp2,zp2 = gps.locate()
  102.         elseif yd < yp2 and yd ~= yp2 then
  103.         turtle.down()
  104.         xp2,yp2,zp2 = gps.locate()
  105.         end
  106.         xp2,yp2,zp2 = gps.locate()
  107.         else
  108.         while not turtle.forward() do
  109.             if not turtle.up() then
  110.             turtle.turnRight()
  111.             turtle.forward()
  112.             turtle.turnLeft()
  113.             xp2,yp2,zp2 = gps.locate()
  114.                 if not turtle.forward() then
  115.                 turtle.turnLeft()
  116.                 turtle.forward()
  117.                 turtle.forward()
  118.                 turtle.turnRight()
  119.                 turtle.forward()
  120.                 xp2,yp2,zp2 = gps.locate()
  121.                 end
  122.             end
  123.         end
  124.         xp2,yp2,zp2 = gps.locate()
  125.         end
  126.         end
  127.     end
  128.     if xd < xp2 then
  129.     turtle.turnLeft()
  130.     end
  131. elseif zp2 < zd then
  132. turtle.turnLeft()
  133.     for k=0,2 do
  134.         if zp2 ~= zd then
  135.             if turtle.forward() then
  136.         if yd > yp2 and yd ~= yp2 then
  137.         turtle.up()
  138.         xp2,yp2,zp2 = gps.locate()
  139.         elseif yd < yp2 and yd ~= yp2 then
  140.         turtle.down()
  141.         xp2,yp2,zp2 = gps.locate()
  142.         end
  143.         xp2,yp2,zp2 = gps.locate()
  144.         else
  145.         while not turtle.forward() do
  146.             if not turtle.up() then
  147.             turtle.turnRight()
  148.             turtle.forward()
  149.             turtle.turnLeft()
  150.             xp2,yp2,zp2 = gps.locate()
  151.                 if not turtle.forward() then
  152.                 turtle.turnLeft()
  153.                 turtle.forward()
  154.                 turtle.forward()
  155.                 turtle.turnRight()
  156.                 turtle.forward()
  157.                 xp2,yp2,zp2 = gps.locate()
  158.                 end
  159.             end
  160.         end
  161.         xp2,yp2,zp2 = gps.locate()
  162.         end
  163.         end
  164.     end
  165.     if xd < xp2 then
  166.     turtle.turnRight()
  167.     end
  168. end
  169. xp2,yp2,zp2 = gps.locate()
  170. end
  171.  
  172. --xd > xp2
  173.  
  174. if xd > xp2 then
  175. for i = 0, 1 do
  176.     if xp2~= xd then
  177.         if turtle.forward() then
  178.         if yd > yp2 and yd ~= yp2 then
  179.         turtle.up()
  180.         xp2,yp2,zp2 = gps.locate()
  181.         elseif yd < yp2 and yd ~= yp2 then
  182.         turtle.down()
  183.         xp2,yp2,zp2 = gps.locate()
  184.         end
  185.         xp2,yp2,zp2 = gps.locate()
  186.         else
  187.         while not turtle.forward() do
  188.             if not turtle.up() then
  189.             turtle.turnRight()
  190.             turtle.forward()
  191.             turtle.turnLeft()
  192.             xp2,yp2,zp2 = gps.locate()
  193.                 if not turtle.forward() then
  194.                 turtle.turnLeft()
  195.                 turtle.forward()
  196.                 turtle.forward()
  197.                 turtle.turnRight()
  198.                 turtle.forward()
  199.                 xp2,yp2,zp2 = gps.locate()
  200.                 end
  201.             end
  202.         end
  203.         xp2,yp2,zp2 = gps.locate()
  204.         end
  205.     end
  206. end
  207.  
  208. if zp2 > zd then
  209. turtle.turnLeft()
  210.     for k = 0 , 1 do
  211.         if zp2 ~= zd then
  212.             if turtle.forward() then
  213.         if yd > yp2 and yd ~= yp2 then
  214.         turtle.up()
  215.         xp2,yp2,zp2 = gps.locate()
  216.         elseif yd < yp2 and yd ~= yp2 then
  217.         turtle.down()
  218.         xp2,yp2,zp2 = gps.locate()
  219.         end
  220.         xp2,yp2,zp2 = gps.locate()
  221.         else
  222.         while not turtle.forward() do
  223.             if not turtle.up() then
  224.             turtle.turnRight()
  225.             turtle.forward()
  226.             turtle.turnLeft()
  227.             xp2,yp2,zp2 = gps.locate()
  228.                 if not turtle.forward() then
  229.                 turtle.turnLeft()
  230.                 turtle.forward()
  231.                 turtle.forward()
  232.                 turtle.turnRight()
  233.                 turtle.forward()
  234.                 xp2,yp2,zp2 = gps.locate()
  235.                 end
  236.             end
  237.         end
  238.         xp2,yp2,zp2 = gps.locate()
  239.         end
  240.         end
  241.     end
  242.     if xd > xp2 then
  243.     turtle.turnRight()
  244.     end
  245. elseif zp2 < zd then
  246. turtle.turnRight()
  247.     for k=0,1 do
  248.         if zp2 ~= zd then
  249.             if turtle.forward() then
  250.         if yd > yp2 and yd ~= yp2 then
  251.         turtle.up()
  252.         xp2,yp2,zp2 = gps.locate()
  253.         elseif yd < yp2 and yd ~= yp2 then
  254.         turtle.down()
  255.         xp2,yp2,zp2 = gps.locate()
  256.         end
  257.         xp2,yp2,zp2 = gps.locate()
  258.         else
  259.         while not turtle.forward() do
  260.             if not turtle.up() then
  261.             turtle.turnRight()
  262.             turtle.forward()
  263.             turtle.turnLeft()
  264.             xp2,yp2,zp2 = gps.locate()
  265.                 if not turtle.forward() then
  266.                 turtle.turnLeft()
  267.                 turtle.forward()
  268.                 turtle.forward()
  269.                 turtle.turnRight()
  270.                 turtle.forward()
  271.                 xp2,yp2,zp2 = gps.locate()
  272.                 end
  273.             end
  274.         end
  275.         xp2,yp2,zp2 = gps.locate()
  276.         end
  277.         end
  278.     end
  279.     if xd > xp2 then
  280.     turtle.turnLeft()
  281.     end
  282. end
  283. xp2,yp2,zp2 = gps.locate()
  284. end
  285.  
  286. -- xd = xp2
  287.  
  288.     if xd == xp2  then
  289.     while zp2 ~= zd do
  290.     if turtle.forward() then
  291.         if yd > yp2 and yd ~= yp2 then
  292.         turtle.up()
  293.         xp2,yp2,zp2 = gps.locate()
  294.         elseif yd < yp2 and yd ~= yp2 then
  295.         turtle.down()
  296.         xp2,yp2,zp2 = gps.locate()
  297.         end
  298.         xp2,yp2,zp2 = gps.locate()
  299.         else
  300.         while not turtle.forward() do
  301.             if not turtle.up() then
  302.             turtle.turnRight()
  303.             turtle.forward()
  304.             turtle.turnLeft()
  305.             xp2,yp2,zp2 = gps.locate()
  306.                 if not turtle.forward() then
  307.                 turtle.turnLeft()
  308.                 turtle.forward()
  309.                 turtle.forward()
  310.                 turtle.turnRight()
  311.                 turtle.forward()
  312.                 xp2,yp2,zp2 = gps.locate()
  313.                 end
  314.             end
  315.         end
  316.         xp2,yp2,zp2 = gps.locate()
  317.         end
  318.     end
  319.     end
  320.     if xp2 == xd and zp2 == zd and yp2 ~= yd then
  321.         if yd < yp2 then
  322.             while yp2 ~= yd do
  323.             turtle.down()
  324.             xp2,yp2,zp2 = gps.locate()
  325.             end
  326.         elseif yd > yp2 then
  327.             while yp2 ~= yd do
  328.             turtle.up()
  329.             xp2,yp2,zp2 = gps.locate()
  330.             end
  331.         end
  332.     end
  333. end
  334.  
  335. print("\nfin")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement