kamilosxd678

Untitled

Feb 8th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. local robot = require("robot")
  2. local moving = true
  3. local moving2 = true
  4. local invPos = 1
  5.  
  6. function verifyInv()
  7.    if(robot.count(invPos) == 0) then
  8.       invPos = invPos + 1
  9.       if(invPos > (robot.inventorySize() - 1) or robot.count(invPos) == 0) then
  10.          return false
  11.       end
  12.       robot.select(invPos)
  13.    end
  14.    
  15.    return true
  16. end
  17.  
  18. function replaceBlockForward()
  19.    local check = verifyInv()
  20.    
  21.    if(check) then
  22.       robot.swing()
  23.       robot.place()
  24.    end
  25.    
  26.    return check
  27. end
  28.  
  29. function replaceBlockBeneath()
  30.    local check = verifyInv()
  31.    
  32.    if(check) then
  33.       robot.swingDown()
  34.       robot.placeDown()
  35.    end
  36.    
  37.    return check
  38. end
  39.  
  40. function diveReplace()
  41.    local check = true
  42.    local moving2 = robot.down()
  43.    if(moving2) then
  44.       if(not replaceBlockBeneath()) then
  45.          check = false
  46.       end
  47.       robot.up()
  48.    end
  49.    
  50.    return check
  51. end
  52.  
  53. while moving do
  54.    for move=1,93 do
  55.       moving = robot.forward()
  56.       if(not moving) then
  57.          break
  58.       end
  59.    end
  60.    
  61.    if(not moving) then
  62.       break
  63.    end
  64.    
  65.    -- Pierwszy klocek na scianie
  66.    robot.turnRight()
  67.    if(not replaceBlockForward()) then
  68.       break
  69.    end
  70.    
  71.    robot.turnLeft()
  72.    moving = robot.forward()
  73.    if(not moving) then
  74.       break
  75.    end
  76.    moving = robot.down()
  77.    if(not moving) then
  78.       break
  79.    end
  80.    
  81.    -- Drugi klocek na scianie
  82.    robot.turnRight()
  83.    if(not replaceBlockForward()) then
  84.       break
  85.    end
  86.    
  87.    robot.turnLeft()
  88.    moving = robot.forward()
  89.    if(not moving) then
  90.       break
  91.    end
  92.    
  93.    -- Probujemy zejsc nizej i postawic trzeci klocek na scianie nr 1 oraz klocek nizej
  94.    moving2 = robot.down()
  95.    if(moving2) then
  96.       robot.turnRight()
  97.       if(not replaceBlockForward()) then
  98.          break
  99.       end
  100.       robot.turnLeft()
  101.       if(not replaceBlockBeneath()) then
  102.          break
  103.       end
  104.       robot.up()
  105.    end
  106.    
  107.    -- Przechodzimy przez tory
  108.    moving = robot.forward()
  109.    if(not moving) then
  110.       break
  111.    end
  112.    moving = robot.forward()
  113.    if(not moving) then
  114.       break
  115.    end
  116.    
  117.    robot.turnLeft()
  118.    if(not moving) then
  119.       break
  120.    end
  121.    moving = robot.forward()
  122.    if(not moving) then
  123.       break
  124.    end
  125.    moving = robot.forward()
  126.    if(not moving) then
  127.       break
  128.    end
  129.    
  130.    -- Kladziemy pierwszy na srodku
  131.    moving = diveReplace()
  132.    if(not moving) then
  133.       break
  134.    end
  135.    
  136.    robot.forward()
  137.    robot.turnRight()
  138.    robot.forward()
  139.    
  140.    moving = diveReplace()
  141.    if(not moving) then
  142.       break
  143.    end
  144.    
  145.    robot.forward()
  146.    robot.turnLeft()
  147.    robot.forward()
  148.    
  149.    moving = diveReplace()
  150.    if(not moving) then
  151.       break
  152.    end
  153.    
  154.    robot.forward()
  155.    robot.forward()
  156.    
  157.    robot.turnRight()
  158.    
  159.    robot.forward()
  160.    robot.forward()
  161.    
  162.    moving2 = robot.down()
  163.    if(moving2) then
  164.       if(not replaceBlockBeneath()) then
  165.          break
  166.       end
  167.       robot.turnLeft()
  168.       if(not replaceBlockForward()) then
  169.          break
  170.       end
  171.       robot.turnLeft()
  172.       robot.up()
  173.    end
  174.    
  175.    robot.forward()
  176.    
  177.    robot.turnRight()
  178.    
  179.    if(not replaceBlockForward()) then
  180.       break
  181.    end
  182.    
  183.    robot.turnLeft()
  184.    robot.forward()
  185.    robot.up()
  186.    robot.turnRight()
  187.    
  188.    if(not replaceBlockForward()) then
  189.       break
  190.    end
  191.    
  192.    robot.turnRight()
  193.    robot.turnRight()
  194.    for move=1,6 do
  195.       moving = robot.forward()
  196.       if(not moving) then
  197.          break
  198.       end
  199.    end
  200.    
  201.    if(not moving) then
  202.       break
  203.    end
  204.    
  205.    robot.turnLeft()
  206. end
Advertisement
Add Comment
Please, Sign In to add comment