This commit is contained in:
Igor Timofeev 2018-06-14 14:52:20 +03:00
parent 68aeec790d
commit 6a97a7ec75
2 changed files with 38 additions and 68 deletions

View File

@ -1,82 +1,52 @@
local robot = require("robot")
local robotAPI = require("robotAPI") local robotAPI = require("robotAPI")
local args = {...} local args = {...}
------------------------------------------------------------------------------------------------------------------------ if #args < 0 then
print("No arguments")
return
end
if #args < 0 then error("No arguments!") end print("Task stated")
local commands = args[1]
local symbols = {} local function execute(symbol)
local symbolcounter = 1
------------------------------------------------------------------------------------------------------------------------
local function executeCommand(symbol)
if symbol == "f" then if symbol == "f" then
robotAPI.move("forward") print("Moving forward:", robotAPI.moveForward())
elseif symbol == "r" then elseif symbol == "b" then
robot.turnRight() print("Moving backward:", robotAPI.moveBackward())
print("Поворачиваюсь направо!")
elseif symbol == "l" then
robot.turnLeft()
print("Поворачиваюсь налево!")
elseif symbol == "t" then
robot.turnAround()
print("Крррррууу-гом!")
elseif symbol == "u" then elseif symbol == "u" then
robotAPI.move("up") print("Moving up:", robotAPI.moveUp())
print("Поднимаюсь выше!")
elseif symbol == "d" then elseif symbol == "d" then
robotAPI.move("down") print("Moving down:", robotAPI.moveDown())
print("Опускаюсь ниже!") elseif symbol == "r" then
elseif symbol == "m" then print("Turning right:", robotAPI.turnRight())
robotAPI.move("forward") elseif symbol == "l" then
robot.swing() print("Turning left:", robotAPI.turnLeft())
print("Копаю вперед!") elseif symbol == "t" then
print("Turning around:", robotAPI.turnAround())
elseif symbol == "s" then elseif symbol == "s" then
print("Копаю впереди!", robot.swing()) print("Swinging:", robotAPI.swing())
elseif symbol == "e" then
--Вообще потная хуйня, но работает, епта! print("Swinging:", robotAPI.use())
elseif tonumber(symbol) ~= nil then
local startNumber = symbol
local counter = 1
for i = (symbolcounter + 1), #symbols do
local newNumber = tonumber(symbols[i])
if newNumber then
startNumber = startNumber .. symbols[i]
counter = counter + 1
else
break
end
end
startNumber = tonumber(startNumber)
print("Выполняю "..startNumber.." раз команду "..symbols[symbolcounter + counter])
for i = 1, startNumber do
executeCommand(symbols[symbolcounter + counter])
end
symbolcounter = symbolcounter + counter
end end
end end
------------------------------------------------------------------------------------------------ local i, commands, symbol, starting, ending, count = 1, args[1]
while i <= #commands do
starting, ending = commands:find("%d+", i)
if starting == i then
symbol, count = commands:sub(ending + 1, ending + 1), tonumber(commands:sub(starting, ending))
print("Executing \"" .. symbol .. "\" command for " .. count .. " times")
for j = 1, count do
execute(symbol)
end
for i = 1, #commands do i = ending + 2
table.insert(symbols, string.sub(commands, i, i)) else
execute(commands:sub(i, i))
i = i + 1
end
end end
print(" ") print("Task finished")
print("Начинаю работать!")
print(" ")
while symbolcounter <= #symbols do
executeCommand(symbols[symbolcounter])
symbolcounter = symbolcounter + 1
end
print(" ")
print("Работа завершена!")
print(" ")

View File

@ -315,7 +315,7 @@ function robotAPI.moveForward()
robotAPI.move(sides.front) robotAPI.move(sides.front)
end end
function robotAPI.moveBack() function robotAPI.moveBackward()
robotAPI.move(sides.back) robotAPI.move(sides.back)
end end