Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local robot = require("robot")
- local shell = require("shell")
- local sides = require("sides")
- local red = component.redstone
- -- Проверка робот ли используется
- if not component.isAvailable("robot") then
- io.stderr:write("can only run on robots")
- return
- end
- -- Проверка параметров запуска
- local args, options = shell.parse(...)
- if #args < 2 then
- io.write("Zapusk: sadovnik <dlina> <kol-vo> <rasstoyanie>\n")
- return
- end
- -- Проверка корректности ввода размера при старте
- local dlina = tonumber(args[1])
- if not dlina then
- io.stderr:write("dlina ne zadana")
- return
- end
- local kolvo = tonumber(args[2])
- if not kolvo then
- io.stderr:write("kolvo ne zadano")
- return
- end
- local rasstoyanie = tonumber(args[3])
- if not rasstoyanie then
- io.stderr:write("rasstoyanie ne zadano")
- return
- end
- -- Переменные
- local x, y, z, f = 0, 0, 0, 0
- -- Осн функция
- function sadovnik()
- while y < kolvo do
- herachVpered()
- if y < kolvo - 1 then
- robot.turnLeft()
- paraShagov( rasstoyanie )
- robot.turnLeft()
- end
- y = y + 1
- end
- robot.turnRight()
- paraShagov( rasstoyanie * ( kolvo - 1 ) )
- kidaiLut()
- robot.turnRight()
- print( robot.level() )
- return true
- end
- -- Вываливаем все в сундук
- function kidaiLut()
- for k = 2, 16 do
- robot.select(k)
- robot.drop()
- end
- robot.select(1)
- end
- -- Делаем пару шагов
- function paraShagov( skolkoNado )
- proideno = 0
- while proideno < skolkoNado do
- shag()
- proideno = proideno + 1
- end
- end
- -- Один шаг
- function shag()
- if robot.forward() == false then
- shag()
- end
- end
- -- Фигачим линию огорода
- function herachVpered()
- while x < dlina do
- shagVpered('plus')
- robot.turnLeft()
- robot.swing()
- robot.place()
- robot.turnAround()
- robot.swing()
- robot.place()
- robot.turnLeft()
- end
- robot.turnAround()
- while x ~= 0 do
- shagVpered('minus')
- end
- end
- -- Шаг вперед
- function shagVpered( action )
- if robot.forward() == false then
- sharVpered()
- end
- if action == 'plus' then
- x = x + 1
- else
- x = x - 1
- end
- end
- -- Поиск сигнала красной пыли позади робота
- function redstoneFinder()
- if red.getInput( sides.top ) > 0 then
- x, y, z, f = 0, 0, 0, 0
- sadovnik()
- else
- print('net signala na4ala')
- end
- return true
- end
- repeat until not redstoneFinder()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement