Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local th = require("threads")
- local e = require("event")
- local nav = require("nav")
- local sir = require("serialization")
- local robot = require("robot")
- local colors = com.colors
- local modem = com.modem
- local args = {...}
- if #args<1 then
- error("Номер робота напиши")
- elseif #args<2 then
- error("ещё цвет")
- end
- th.init()
- local m, cordss, times, start, ma, chup, tasks, numar, varo, chm, slot
- modem.open(12345)
- local color={["red"]={0xff2020,1,2},["blue"]={0x20afff,2,1},["green"]={0xafff20,1,2},["yellow"]={0xffff20,2,1}}
- local TEAM_COLOR = color[args[2]][1]
- colors.setColor(TEAM_COLOR)
- com.robot.setLightColor(TEAM_COLOR)
- function ini()
- times, start= 300, false
- tasks={}
- cordss={}
- local ifarr={{7,8,0,0},{7,1,0,9},{19,8,10,0},{18,0,9,10}}
- local raspo={{9,8},{8,9},{9,8},{8,9}}
- local eari={0,2,0,2}
- m=nav:new()
- numar=tonumber(args[1])
- slot=math.random(1,13)
- robot.select(slot)
- local kx=ifarr[numar]
- local dx, dy, axz
- for x=0, raspo[numar][color[args[2]][2]] do
- for z=0, raspo[numar][color[args[2]][3]] do
- if args[2] == "red" then
- dx=((-948)-x-kx[3])
- dz=((639-z)-kx[4])
- axz={x+kx[1],z-kx[2],0,0}
- elseif args[2] == "yellow" then
- dx=((639-z)-kx[3])
- dz=((-966)+x+kx[4])
- axz={z+kx[1],x-kx[2],0,0}
- elseif args[2] == "blue" then
- dx=((-966)+x+kx[3])
- dz=((621+z)+kx[4])
- axz={x+kx[1],z-kx[2],0,0}
- elseif args[2] == "green" then
- dx=((621+z)+kx[3])
- dz=((-948)-x-kx[4])
- axz={z+kx[1],x-kx[2],0,0}
- else
- error("Правильный введи")
- end
- cordss[tostring(dx)..tostring(dz)]=axz
- end
- end
- end
- function CollectCoin(cordo)
- if cordss[cordo] ~= nil then
- print("Go to: ", cordss[cordo][1], cordss[cordo][2])
- m:go(cordss[cordo])
- robot.suckDown(64)
- end
- end
- function main()
- while true do
- for k,v in pairs(tasks) do
- CollectCoin(v)
- os.sleep(0.3)
- end
- os.sleep(0)
- end
- end
- function rmformtbl(varr)
- for k=#tasks,1,-1 do
- if tasks[k] == varr then
- table.remove(tasks, k)
- end
- end
- end
- function checkup()
- while true do
- local nd=m:getPos()
- if nd.z >= 5 then
- m:stopgo()
- end
- os.sleep(0)
- end
- end
- function checkm()
- while true do
- if sir.serialize(m:gettarg()) == sir.serialize(cordss[varo]) and start==true then
- m:stopgo()
- end
- os.sleep(0)
- end
- end
- function clearmap()
- for k, v in pairs(cordss) do
- m:putMap(v,{})
- end
- print("ok")
- end
- local timero=e.timer(30,clearmap,math.huge)
- function eve()
- while true do
- local recv={e.pull("modem_message")}
- if recv[7] and recv[9] then
- if args[2] == "red" then
- var = tostring(recv[7]+1)..tostring(recv[9])
- elseif args[2] == "yellow" then
- var = tostring(recv[9])..tostring(recv[7]+1)
- elseif args[2] == "blue" then
- var = tostring(recv[7]+1)..tostring(recv[9])
- elseif args[2] == "green" then
- var = tostring(recv[9])..tostring(recv[7]+1)
- else
- error("Правильный введи, идиот")
- end
- end
- local var2 = recv[6]
- if var2 == "gamestart" then
- local aone={{11,-1,0},{11,1,0},{22,0,0},{22,0,0}}
- m:go(aone[numar])
- start = true
- end
- if start then
- if var2 == "setcoin" then
- table.insert(tasks, var)
- elseif var2 == "unsetcoin" then
- varo = var
- rmformtbl(var)
- elseif var2 == "time" then
- times=recv[7]
- elseif var2 == "gamestop" then
- start = false
- th.kill(ma)
- while true do
- m:go({0,0,0,0})
- os.sleep(0.1)
- local nda=m:getPos()
- print(sir.serialize(nda))
- if nda.x == 0 and nda.y == 0 and nda.z == 0 and nda.f == 0 then
- break
- end
- m:step()
- end
- th.kill(chup)
- th.kill(chm)
- e.cancel(timero)
- for i=0,3 do
- robot.select(slot+i)
- robot.dropDown()
- end
- break
- end
- end
- if times <= 30 then
- start = false
- th.kill(ma)
- while true do
- m:go({0,0,0,0})
- os.sleep(0.1)
- local nda=m:getPos()
- print(sir.serialize(nda))
- if nda.x == 0 and nda.y == 0 and nda.z == 0 and nda.f == 0 then
- break
- end
- m:step()
- end
- th.kill(chup)
- th.kill(chm)
- e.cancel(timero)
- for i=0,3 do
- robot.select(slot+i)
- robot.dropDown()
- end
- print(sir.serialize(tasks))
- break
- end
- os.sleep(0)
- end
- end
- th.create(ini)
- ma = th.create(main)
- chup = th.create(checkup)
- th.create(eve)
- chm=th.create(checkm)
- th.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement