如何实现机器人足球自动放球功能?
摘要:title: 机器人足球-自动放球 date: 2021-07-16 15:49:06 tags: 比赛 categories: 比赛 策略选择-这部分放在lua层-myball.lua c++层的内容
策略选择-这部分放在lua层-myball.lua
c++层的内容
lua层
--desc:
Kicker_x = function()
return COurRole_x("Kicker")
end
Kicker_y = function()
return COurRole_y("Kicker")
end
R_x = function()
return COurRole_x("Receiver")
end
R_y = function()
return COurRole_y("Receiver")
end
--读取txt文件
local function readFile(fileName)
local f = assert(io.open(fileName,'r'))
local content = f:read('*all')
local margin = string.find(content,' ')
local x = tonumber( string.sub(content,0,margin))
local y =tonumber( string.sub(content,margin,string.len(content)))
f:close()
return x,y
end
r2kdir =function ()
return COurRole2RoleDir("Receiver","Kicker")
end
Receiverdir = function ()
return CRole2BallDir("Receiver")
end
gPlayTable.CreatePlay{
firstState = "choose",
--先根据距离选择不同的策略
["choose"]={
switch=function()
local posx,posy
posx,posy=readFile("E:\\work\\SOM\\Team\\user_skills\\target_pos.txt")
if (CBall2PointDist(posx,posy)<150) then
return "GetBall1"
else
return "GetBall2"
end
end,
Kicker = task.GotoPos("Kicker",Kicker_x,Kicker_y,0),
Receiver=task.GotoPos("Receiver",R_x,R_y,Receiverdir),
Goalie=task.GotoPos("Goalie",1000,1000,0),
},
--策略1,直接去拿球,其他不动或离开。
["GetBall1"] = {
switch = function()
end,
Kicker = task.GotoPos("Kicker",Kicker_x,Kicker_y,1.5),
Receiver=task.ReceiverTask("get_place_ball"),
Goalie=task.GotoPos("Goalie",1000,1000,0),
},
--策略2,一个去踢球,一个准备接球。
["GetBall2"] = {
switch = function()
--判断是否踢球了,本且是否是真踢球,没有获取球速的函数,所以用距离判断是否真踢球
if CIsBallKick("Kicker") and CBall2RoleDist("Kicker")>30 then
return "PlaceBall"
end
end,
Kicker = task.KickerTask("getball_shoot"),
Receiver=task.ReceiverTask("Receiver_wait"),
Goalie=task.GotoPos("Goalie",1000,1000,0),
},
--策略2,接到球之后,再放球。
