ChinaOpenSSL系列笔记足球机器人
观察一下: TestDribbleAndKick(吸球射门)
语义
FPS 帧率
DeviceMsg //黄一排
DrawObst //障碍物信息
快捷键:ctrl+p打开
配置一个play: 在 config.lua
简单框架
报错
语法没问题,语义有问题,报错会在其他地方
一、如何使用switch函数
player.lua
enemy.lua //针对敌方
ball.lua //球速、球的位置、球的朝向
pos.lua //位置相关
bufcnt.lua
...
1、!!延长时间(bufcnt.lua)
bufcnt(cond,buf,cnt)
if bufcnt(true,200) then //当true条件持续满足200帧再执行
return "run2"
2、player.lua(升级)
if bufcnt(player.toTargetDist('Kicker')<10,10) then
return "run2"
二、match 就近匹配
{ } :不匹配,维持状态
[ ] :实时匹配
( ) :每当进行一次states的切换时进行一次匹配
机器人名字:
Assister Special Defender Middle
Leader Breaker Fronter Center ...abcd...
task.lua
框架
task function - skill.lua - skill from c++
task function 中的内容只执行一遍
Play 调试
录制 第四栏中的 DeviceMsg ;点击第三栏中的文件夹
查看
FRAREDOFF
FRAREDON 吸球吸了多久
CHIPKICK
FLATKICK
INFRARED 红外触发变1
来回跳动的简单框架
local testPos = {CGeoPoint:new_local(0,0)CGeoPoint:new_local(1000,1000) }local DEBUG_SWITCH = true;gPlayTable.CreatePlay{firstState = "run1",["run1"] = {switch = function() if bufcnt(player.toTargetDist("Leader")<5,time) thenreturn "run2"end end,Leader = task.goCmuRush(testPos[1],0),match = "{L}" },["run2"] = {switch = function() if DEBUG_SWITCH thenendif bufcnt(player.toTargetDist("Leader")<5,time) thenreturn "run1"end end,Leader = task.goCmuRush(testPos[2],0),match = "{L}" },name = "MyTestRun", applicable ={exp = "a",a = true }, attribute = "attack", timeout = 99999 }debugEngine.pkg //连接lua和c++
: 表示隐式指针
debugEngine:gui_debug_x(CGeoPoint:new_local(1000,1000))
层
Yourplay.lua/task.lua/play.lua
小车绕球旋转代码实现
local testPos = {CGeoPoint:new_local(0,0), } local TOTAL = 4 local speed = 1/4.0 local angle = 0 local radius = 500local p = function(n,TOTAL)return function()local centerX = ball.posX()local centerY = ball.posY()return CGeoPoint:new_local(centerX + radius * math.cos(angle + n*math.pi*2/TOTAL)end end gPlayTable.CreatPlay{ fristStates = "tun", ["run"] = {switch = function()angle = angle +math.pi*2/60*speedend,Leader = task.goCmuRush(p(1,TOTAL)),Assister = task.goCmuRush(p(2,TOTAL)),Middle = task.goCmuRush(p(3,TOTAL)),Special = task.goCmuRush(p(4,TOTAL)),math = "{LAMS}" },name = "MyRun", applicable = {exp = "a",a = true }, attribute = "attack", timeout = 99999 }绕敌对机器人旋转代码片段实现
local enemeyPos = function(num)return function()return enemy.pos(num)end end local p = function(n,TOTAL,pos)return function()ipos = posif type(pos) == 'function' thenipos = pos()elseipos = posendlocal centerX = ipos:x()local centerY = ipos:y()return CGeoPoint:new_local(centerX + radius*math.cos(angle + n*math.pi*2/TOTAL)end end gPlayTable.CreatePlay{ firstState = "run", ["run"] = {switch = function()angle = angle +math.pi*2/60*speedend,Leader = task.goCmuRush(p(1,2,enemyPos(1))),Assister = task.goCmuRush(p(2,2,enemyPos(1))),Middle = task.goCmuRush(p(1,2,enemyPos(0))),Special = task.goCmuRush(p(2,2,enemyPos(0))),match = "(LA)(MS)" }, ...Task.lua 的封装
TestSkill.lua
gPlayTable.CreatePlay{ fristState = "test", ["test"] = {switch = function()end,Leader = task.marking(-3500,0,-2000,2000),match = "{L}" },name = "TestSkill", applicable = {exp = "a",a = true }, attribute = "attack", timeout = 99999 }test.lua
function marking(xmin,xmax,ymin,ymax)local num = 0local ourGoal = CGeoPoint:new_local(-param.pitchLength/2.0,0)local drawDebug = function()local p1 = CGeoPoint:new_local(xmin,ymin)local p2 = CGeoPoint:new_local(xmin,ymax)local p3 = CGeoPoint:new_local(xmax,ymin)local p4 = CGeoPoint:new_local(xmax,ymax)debugEngine:gui_debug_line(p1,p2,4)debugEngine:gui_debug_line(p2,p4,4)debugEngine:gui_debug_line(p3,p4,4)debugEngine:gui_debug_line(p1,p3,4)endlocal checkNum = function()local between = function(a,min,max)if a>min and a<max thenreturn trueendreturn falseendlocal num = -1for i=0,param.maxPlayer-1 doif enemy.valid(i) and between(enemy.posX(i),xmin,xmax) and between(enemy.posY(i),ymin,ymax)return iendreturn numendlocal ipos = function()local num =checkNum()local enemyPos = enemy.pos(num)if num < 0 thenenemyPos=CGeoPoint:new_local((xmin+xmax)/2.0,(ymin+ymax)/2.0)endlocal reslocal l = (outGoal - enemy.pos(num)):mod()*0.3res = enemy.pos(num) + Util.Polar2Vector(l,(ourGoal - enemy.pos(num)):dir())return resendlocal idir = function(runner)local num = checkNum()local enemyPos = enemy.pos(num)if num < 0 thenenemyPos=CGeoPoint:new_local((xmin+xmax)/2.0,(ymin+ymax)/2.0)endlocal resres = (enemyPos - ourGoal):dir()return resendlocal mexe,mpos = GoCmuRush{pos = ipos,dir = idir,acc = a,flag = f,rec =return {mexe,mpos} end盯防配合代码简单实现(需修改)
function waitForAttack()local checkAttacker = function(runner)for i=0,param.maxPlayer-1 dolocal dis = (ball.pos() - player.pos(i)):modif player.valid(i) and dis <1000 and i~= runner thendebugEngine:gui_debug_msg(CGeoPoint:new_local(0,i*200),i..(player.valid(i) and 'T' or 'F')..dis)rerurn iendendreturn -1endlocal ipos = function(runner)local num = checkAttacker(runner)local x = player.posX(num)local y = player.posY(num)local length = param.pitchLength/2return CGeoPoint:new_local(length - x ,-y)endlocal idir = function(runner)return player.toTheiGoalDir(runner)endlocal mexe,mpos = GoCmuRush{pos = ipos,dir = idir ,acc = a,flag=f,rec=r,vel=v}return {mexe,mpos} end除了switch、match的,和机器人名称有关的才是table
task有8个参数,
if roleNum ~= -1 then
if task[3] ~= nil then
local mkick = task[3](roleNum) //踢球模式
local mdir = task[4](roleNum) //踢球方向
local mpre = task[5](roleNum) //踢球精度
local mkp = task[6](roleNum) //平射力度
local mcp = task[7](roleNum) //挑射力度
local mflag = task[8]
local isDirOk = world :KickDirArrived(vision:getCycle(),mdir,mpre...
kick.flat 平射
function speed (vx,vy,vdir)
//function speed(vx,vy,vdir,p,f)
local ikick = kick.flat
//local ikick = kick.none
local idir = dir.specified(0)
local ipre = pre.specified(10)
local ikp = kp.specified(2000)
//local ikp = kp.specified(p)
local icp = cp.specified(1000)
local iflag = flag.nothing
local spdX = function()
return vx
local spdY = function()
return vy
local spdW = function()
return vdir
end
local mexe,mpos = Speed{speedX = spdX,
return {mexe,mpos,ikick,idir,ipre,ikp,icp,iflag,
end
机器人控制对比
队伍 路径 避障 速度 性能 性能
ZJUNlict RRT* DSS Bangbang 3 1
Tigers Topo+Bspline capsule 2D-Bang 1 2
Immortals NOK-RRT DSS - 1 3
ER-Force RRT - 2D-Bang
Other.lua 对手配置
gOppoConfig = {
CornerKick = {1},
...
KickOff = "..." //开球脚本
... //防守
... //捡球
... //点球
}
lua的流程 selectPlay.lua选出当前需要的play
总结
以上是生活随笔为你收集整理的ChinaOpenSSL系列笔记足球机器人的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 华为路由器实现负载均衡和冗余备份
- 下一篇: 东北大学考研二叉树相关试题