Guest User

robot.lua

a guest
Aug 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. local component = require "component"
  2. local computer = require "computer"
  3. local term = require "term"
  4. local robot = require "robot"
  5. local sides = require "sides"
  6.  
  7. local energy = computer.energy()
  8.  
  9. local function detect(type, direction)  --Обнаружение определенноо типа [направления] роботом. Возвращает boolean.
  10.   local detection
  11.   if direction == "up" then detection = select(2, robot.detectUp())
  12.    elseif direction == "down" then detection = select(2, robot.detectDown())
  13.    else
  14.     detection =  select(2, robot.detect())
  15.   end
  16.   if detection  == type then
  17.     return true
  18.   end
  19. end
  20.  
  21. local function checkEnergy() --TODO
  22.  
  23. end
  24.  
  25. local function killLiquid(slot)  -- Удаление всех жидкостей и замена на блоки вокруг робота, исключая зад
  26.  
  27.   local types = {"liquid", "replaceable"}
  28.   robot.select(slot)
  29.  
  30.   local function placeOnLiquid(direction)  -- Замена жидкости на блок в слоте, если есть жидкость
  31.     for _, type in pairs(types) do
  32.       if detect(type,direction) then
  33.         if direction == "up"  then
  34.           robot.placeUp()
  35.          elseif direction == "down"then
  36.           robot.placeDown()
  37.          else robot.place()
  38.         end
  39.       end
  40.     end
  41.   end
  42.  
  43.   placeOnLiquid("up")
  44.   placeOnLiquid("down")
  45.   placeOnLiquid()
  46.   robot.turnRight()
  47.   placeOnLiquid()
  48.   robot.turnAround()
  49.   placeOnLiquid()
  50.   robot.turnRight()
  51.  
  52. end
  53.  
  54. local function robotTunnel(numSteps, height)  --REFACTOR!!!
  55.   local function line()
  56.     for i = 1, numSteps do
  57.       if detect("solid") then robot.swing() end
  58.       robot.forward()
  59.       for i = 1, height-1 do
  60.         if detect("solid","up") then robot.swingUp() end
  61.         robot.up()
  62.       end
  63.       for i = 1, height-1 do
  64.         robot.down()
  65.       end
  66.     end
  67.   end
  68.   line()
  69.   robot.turnAround()
  70.   line()
  71.   robot.turnAround()
  72. end
  73.  
  74. term.clear()
  75. term.write("Введите длинну тоннеля \n")
  76. LENGTH = term.read()
  77. robotTunnel(LENGTH,1)
  78. print('Energy: '..energy - computer.energy())
Add Comment
Please, Sign In to add comment