From 066e7dc9631296446ace351f59fa618fcc288491 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 9 Apr 2024 21:29:28 +0800 Subject: [PATCH] [Core] link real number with subPlay Role --- Core/tactics/play/TestMyRun.lua | 29 ++++++++ Core/tactics/play/TestPassAndKick.lua | 12 ++-- Core/tactics/play/TestSubScript.lua | 15 ++-- ZBin/lua_scripts/Play.lua | 58 +++++++++------- ZBin/lua_scripts/SelectPlay.lua | 20 +----- ZBin/lua_scripts/SubPlay.lua | 95 ++++++++++++++++++++++---- ZBin/lua_scripts/utils/utils.lua | 4 +- ZBin/lua_scripts/worldmodel/cond.lua | 65 ------------------ ZBin/lua_scripts/worldmodel/dir.lua | 8 +-- ZBin/lua_scripts/worldmodel/player.lua | 29 +++++--- ZBin/lua_scripts/worldmodel/pos.lua | 19 ------ 11 files changed, 181 insertions(+), 173 deletions(-) create mode 100644 Core/tactics/play/TestMyRun.lua diff --git a/Core/tactics/play/TestMyRun.lua b/Core/tactics/play/TestMyRun.lua new file mode 100644 index 0000000..8f09306 --- /dev/null +++ b/Core/tactics/play/TestMyRun.lua @@ -0,0 +1,29 @@ +local testPos = {CGeoPoint:new_local(1000, 1000), CGeoPoint:new_local(-1000, 1000), CGeoPoint:new_local(-1000, -1000), + CGeoPoint:new_local(1000, -1000)} +local vel = CVector:new_local(0, 0) +local maxvel = 0 +local time = 120 +local DSS_FLAG = bit:_or(flag.allow_dss, flag.dodge_ball) + +local DIR = function() + return (player.pos('Assister') - ball.pos()):dir() +end + +return { + firstState = "run1", + + ["run1"] = { + switch = function() + end, + Assister = task.goCmuRush(testPos[1], DIR, nil, DSS_FLAG), + match = "[A]" + }, + + name = "TestMyRun", + applicable = { + exp = "a", + a = true + }, + attribute = "attack", + timeout = 99999 +} diff --git a/Core/tactics/play/TestPassAndKick.lua b/Core/tactics/play/TestPassAndKick.lua index adc2372..ef516d7 100644 --- a/Core/tactics/play/TestPassAndKick.lua +++ b/Core/tactics/play/TestPassAndKick.lua @@ -1,11 +1,12 @@ local waitPos = ball.antiYPos(CGeoPoint:new_local(2600,1500)) local waitPos2 = ball.antiYPos(CGeoPoint:new_local(1800,1500)) local mode = true -gPlayTable.CreatePlay{ + +return { firstState = "init", ["init"] = { switch = function() - if player.toTargetDist("Assister") < 1000 then + if player.toTargetDist("Assister") < 1000 and player.toTargetDist("Leader") < 100 then return "pass" end end, @@ -19,15 +20,18 @@ firstState = "init", return "shoot" end end, - Leader = task.touchKick(waitPos,false,540,mode), + Leader = task.touchKick(waitPos,false,3500,mode), Assister = task.goCmuRush(waitPos2), match = "" }, ["shoot"] = { switch = function() + if player.kickBall("Assister") then + return "init" + end end, Leader = task.stop(), - Assister = task.touchKick(pos.theirGoal(), false,300,mode), + Assister = task.touchKick(pos.theirGoal(), false,6000,mode), match = "" }, diff --git a/Core/tactics/play/TestSubScript.lua b/Core/tactics/play/TestSubScript.lua index a448d35..8ccb32b 100644 --- a/Core/tactics/play/TestSubScript.lua +++ b/Core/tactics/play/TestSubScript.lua @@ -25,15 +25,14 @@ return { switch = function() if bufcnt(true,30) then if not subScript then - gSubPlay.new(PLAY_NAME .. "task1", "TestSubScript", {pos=start_pos + Utils.Polar2Vector(2*dist, math.pi/4), dist=2000}) - gSubPlay.new(PLAY_NAME .. "task2", "TestSubScript", {pos=start_pos + Utils.Polar2Vector(2*dist, -math.pi/4*3), dist=500}) - rotateSpeed = -1 + gSubPlay.new("kickTask", "TestPassAndKick") end return "run" end end, + Assister = task.stop(), Leader = task.stop(), - match = "[L]" + match = "[LA]" }, ["run"] = { switch = function() @@ -42,10 +41,10 @@ return { -- print("printFileTable: ", key, value) -- end end, - Assister = gSubPlay.roleTask("task1","Leader"), - Fronter = gSubPlay.roleTask("task2","Leader"), - Leader = task.goCmuRush(runPos, 0, nil, DSS_FLAG), - match = "(LAF)" + b = gSubPlay.roleTask("kickTask", "Assister"), + c = gSubPlay.roleTask("kickTask", "Leader"), + a = task.goCmuRush(runPos, 0, nil, DSS_FLAG), + match = "(abc)" }, name = "TestSubScript", diff --git a/ZBin/lua_scripts/Play.lua b/ZBin/lua_scripts/Play.lua index 9816c0c..f5dc7c9 100644 --- a/ZBin/lua_scripts/Play.lua +++ b/ZBin/lua_scripts/Play.lua @@ -85,28 +85,28 @@ end -- 注意,此处只是针对间接和直接定位球的防守 -- 此时,Leader和Goalie不参与第二次防碰撞检测 -function UsePenaltyCleaner(curPlay) - for rolename, task in pairs(curPlay[gRealState]) do - if(type(task) == "table" and rolename ~= "match" and rolename ~= "Goalie" and rolename ~= "Kicker") then - local p - if type(gRolePos[rolename]) == "function" then - p = gRolePos[rolename]() - else - p = gRolePos[rolename] - end - CAddPenaltyCleaner(string.sub(rolename,1,1), gRoleNum[rolename], p:x(), p:y()) - end - end - CCleanPenalty() - for rolename, task in pairs(curPlay[gRealState]) do - if(type(task) == "table" and rolename ~= "match" and rolename ~= "Goalie" and rolename ~= "Kicker") then - local x, y = CGetPenaltyCleaner(string.sub(rolename,1,1)) - gRolePos[rolename] = CGeoPoint:new_local(x,y) - end - end - -- print(gCurrentState, CGetResetMatchStr()) - DoRoleMatchReset(CGetResetMatchStr()) -end +-- function UsePenaltyCleaner(curPlay) +-- for rolename, task in pairs(curPlay[gRealState]) do +-- if(type(task) == "table" and rolename ~= "match" and rolename ~= "Goalie" and rolename ~= "Kicker") then +-- local p +-- if type(gRolePos[rolename]) == "function" then +-- p = gRolePos[rolename]() +-- else +-- p = gRolePos[rolename] +-- end +-- CAddPenaltyCleaner(string.sub(rolename,1,1), gRoleNum[rolename], p:x(), p:y()) +-- end +-- end +-- CCleanPenalty() +-- for rolename, task in pairs(curPlay[gRealState]) do +-- if(type(task) == "table" and rolename ~= "match" and rolename ~= "Goalie" and rolename ~= "Kicker") then +-- local x, y = CGetPenaltyCleaner(string.sub(rolename,1,1)) +-- gRolePos[rolename] = CGeoPoint:new_local(x,y) +-- end +-- end +-- -- print(gCurrentState, CGetResetMatchStr()) +-- DoRoleMatchReset(CGetResetMatchStr()) +-- end function DoRolePosMatch(curPlay, isPlaySwitched, isStateSwitched) if gCurrentState == "exit" or gCurrentState == "finish" then @@ -116,6 +116,13 @@ function DoRolePosMatch(curPlay, isPlaySwitched, isStateSwitched) end gActiveRole = {} for rolename, itask in pairs(curPlay[gRealState]) do + local task = itask + -- unpack for subPlayTask + if (type(task) == "table" and task.name == "subPlayTask" and task.task ~= nil) then + gSubPlay.register("", rolename, task.args) + itask = task.task + end + if(type(itask) == "function" and rolename ~= "match" and rolename~="switch") then itask = itask() end @@ -196,7 +203,7 @@ function RunPlay(name) isStateSwitched = true PlayFSMClearAll() end - + -- debugEngine:gui_debug_msg(vision:ourPlayer(gRoleNum[rolename]):Pos(), rolename) gSubPlay.step() DoRolePosMatch(curPlay, false, isStateSwitched) @@ -210,6 +217,10 @@ function RunPlay(name) --~ 1 ---> task, 2 --> matchpos, 3--->kick, 4 --->dir, 5 --->pre, 6 --->kp, 7--->cp, 8--->flag kickStatus:clearAll() for rolename, task in pairs(curPlay[gRealState]) do + if (type(task) == "table" and task.name == "subPlayTask" and task.task ~= nil) then + gSubPlay.register("", rolename, task.args) + task = task.task + end if (type(task) == "function" and rolename ~= "match" and (gRoleNum[rolename] ~= nil or type(rolename)=="function")) then task = task(gRoleNum[rolename]) end @@ -226,7 +237,6 @@ function RunPlay(name) elseif type(rolename)=="function" then roleNum = rolename() --print("Here in function : "..roleNum) - end if roleNum ~= -1 then diff --git a/ZBin/lua_scripts/SelectPlay.lua b/ZBin/lua_scripts/SelectPlay.lua index 1545c55..d6fe51b 100644 --- a/ZBin/lua_scripts/SelectPlay.lua +++ b/ZBin/lua_scripts/SelectPlay.lua @@ -158,23 +158,5 @@ debugEngine:gui_debug_msg_fix(CGeoPoint:new_local(-param.pitchLength*2/5, param. RunPlay(gCurrentPlay) gLastTask = gRoleTask gRoleTask = {} --- local stateFile=io.open(".\\LOG\\"..gStateFileNameString..".txt","a") --- if not stateFile then --- print("-------- Can't create LOG FILE !!!!!!!!!!!!! --------") --- end --- stateFile:write(vision:getCycle().." "..gCurrentState.." "..gCurrentPlay.." me:"..skillUtils:getOurBestPlayer() --- .." he:"..skillUtils:getTheirBestPlayer().."\n") --- stateFile:close() ---print( world:getSuitSider()) ---print("vel"..enemy.vel(skillUtils:getTheirGoalie()):y()*2) ---print(skillUtils:getTheirGoalie()) ---print("hello",skillUtils:getOurBestPlayer()) ---print(gCurrentState,vision:getCycle()) ---print("ball",ball.posX(),ball.valid()) ---print("raw",vision:rawBall():X(),vision:rawBall():Valid()) ---print(vision:getBallVelStable(),vision:ballVelValid()) -debugEngine:gui_debug_msg_fix(CGeoPoint:new_local(-param.pitchLength*2/5, param.pitchWidth/2),gCurrentState) ---world:drawReflect(gRoleNum["Tier"]) ---defenceInfo:setNoChangeFlag() ---print(vision:getCycle()..vision:getCurrentRefereeMsg(),vision:gameState():gameOn()) +debugEngine:gui_debug_msg_fix(CGeoPoint:new_local(-param.pitchLength*2/5, param.pitchWidth/2),gCurrentState) \ No newline at end of file diff --git a/ZBin/lua_scripts/SubPlay.lua b/ZBin/lua_scripts/SubPlay.lua index 75f3668..4398b40 100644 --- a/ZBin/lua_scripts/SubPlay.lua +++ b/ZBin/lua_scripts/SubPlay.lua @@ -33,6 +33,10 @@ function gSubPlay.new(name, playName, initParam) gSubPlay.playTable[name] = SubPlay.pack(name, spec, initParam) end +function gSubPlay.del(name) + gSubPlay.playTable[name] = nil +end + function gSubPlay.step() local debugX = -2000 local debugY = param.pitchWidth/2+200 @@ -44,7 +48,6 @@ function gSubPlay.step() curState = _RunPlaySwitch(_subPlay, curState) local isStateSwitched = false if curState ~= nil then - print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") play.lastState = play.curState play.curState = curState isStateSwitched = true @@ -66,20 +69,82 @@ function gSubPlay.getState(name) end function gSubPlay.roleTask(name, role) - return function() - if gSubPlay.playTable[name] == nil then - warning("roleTask not exist - ", name, role) - return - end - local _subPlayState = gSubPlay.playTable[name].play[gSubPlay.playTable[name].curState] - return _subPlayState[role] + return { + name = "subPlayTask", + task = function() + if gSubPlay.playTable[name] == nil then + warning("roleTask not exist - " .. name .. " " .. role) + return + end + local _subPlayState = gSubPlay.playTable[name].play[gSubPlay.playTable[name].curState] + subTask = _subPlayState[role] + if subTask ~= nil and type(subTask) == "table" and subTask.name == "subPlayTask" then -- subtask call subtask + gSubPlay.register(name, role, subTask.args) + return subTask.task() + end + return _subPlayState[role] + end, + args = { + name = name, + role = role, + } + } +end + +function gSubPlay.register(playName, rolename, args) + local msg = string.format("%s:%s - %s:%s ",args.name, args.role, playName, rolename) + -- print("register : ",msg) + if gSubPlay.playTable[args.name] == nil then + warning("register failed, play not exist - " .. msg) + return end + gSubPlay.playTable[args.name].roleMapping[args.role] = {playName, rolename} end --- function gSubPlay.getRoleNum(roleName) --- print("in getRoleNum : ", roleName) --- if gSubPlay.curScope == nil then --- return gRoleNum[roleName] --- end --- return -1 --- end \ No newline at end of file +function gSubPlay.getRole(roleName) + local role, num = gSubPlay.getRoleAndNum(roleName) + return role +end + +function gSubPlay.getRoleNum(roleName) + local role, num = gSubPlay.getRoleAndNum(roleName) + return num +end + +function gSubPlay.getRoleAndNum(roleName) + local scope = gSubPlay.curScope + local role = roleName + local iterCount = 0 + local findPath = {} + local pathOutput = function(path) + local str = "" + for i, v in ipairs(path) do + str = str .. " -> " .. v[1] .. ":" .. v[2] + end + return str + end + -- print("getRoleNum - ", scope, role) + while true do + if scope == "" then + return role, gRoleNum[role] + else + if gSubPlay.playTable[scope] == nil then + warning("subPlay not exist - " .. scope .. " " .. role .. pathOutput(findPath)) + return -1 + end + if gSubPlay.playTable[scope].roleMapping[role] == nil then + warning("role not exist - " .. scope .. " " .. role .. pathOutput(findPath)) + return -1 + end + local tRoleMap = gSubPlay.playTable[scope].roleMapping[role] + scope, role = tRoleMap[1], tRoleMap[2] + end + table.insert(findPath, {scope,role}) + -- prevent infinite loop + iterCount = iterCount + 1 + if iterCount > 10 then + warning("getRoleNum failed - " .. pathOutput(findPath)) + return -1 + end + end +end \ No newline at end of file diff --git a/ZBin/lua_scripts/utils/utils.lua b/ZBin/lua_scripts/utils/utils.lua index 2e041fb..4548bd7 100644 --- a/ZBin/lua_scripts/utils/utils.lua +++ b/ZBin/lua_scripts/utils/utils.lua @@ -1,9 +1,9 @@ -local warningX = 0 +local warningX = -param.pitchLength/2 local warningY = 0 function warning(msg) msg = "WARNING: " .. msg print( msg) - debugEngine:gui_debug_msg(CGeoPoint(warningX, warningY), msg, param.CYAN) + debugEngine:gui_debug_msg_fix(CGeoPoint(warningX, warningY), msg, param.CYAN) warningY = warningY + 120 if warningY > param.pitchWidth/2 then warningY = -param.pitchWidth/2 diff --git a/ZBin/lua_scripts/worldmodel/cond.lua b/ZBin/lua_scripts/worldmodel/cond.lua index d5582c2..93d979a 100644 --- a/ZBin/lua_scripts/worldmodel/cond.lua +++ b/ZBin/lua_scripts/worldmodel/cond.lua @@ -36,38 +36,10 @@ function isNormalStart() return vision:gameState():canEitherKickBall() end ---~ ----------------------------------------------- ---~ geometry condition ---~ ----------------------------------------------- - - ---~ ----------------------------------------------- ---~ other condition ---~ ----------------------------------------------- -function bestPlayerChanged() - return world:IsBestPlayerChanged() -end - -function canShootOnBallPos(role) - return world:canShootOnBallPos(vision:getCycle(),gRoleNum[role]) -end - -function canPassOnBallPos(role,passPos,guisePos) - return world:canPassOnBallPos(vision:getCycle(),passPos,guisePos,gRoleNum[role]) -end - --- function canKickAtEnemy(role,kickDir) --- return world:canKickAtEnemy(vision:getCycle(),kickDir,gRoleNum[role]) --- end - function validNum() return vision:getValidNum() end -function canDefenceExit() - return world:CanDefenceExit() -end - function timeRemain() return vision:timeRemain() end @@ -242,43 +214,6 @@ function kickOffEnemyNumChanged() end --------------------------------------For Freekick-------------------------------------------------- -function canPassAndShoot(role) - if gRoleNum[role] ~= 0 and not world:isPassLineBlocked(gRoleNum[role]) and not world:isShootLineBlocked(gRoleNum[role]) then - return true - else - return false - end -end - --- 优先级从role1至role5降低, 可少角色 -function findChance(role1, role2, role3, role4, role5) - if role1 ~= nil and type(role1) == "string" then - if gRoleNum[role1] ~= 0 and not world:isBeingMarked(gRoleNum[role1]) and canPassAndShoot(role1) then - return role1 - end - end - if role2 ~= nil and type(role2) == "string" then - if gRoleNum[role2] ~= 0 and not world:isBeingMarked(gRoleNum[role2]) and canPassAndShoot(role2) then - return role2 - end - end - if role3 ~= nil and type(role3) == "string" then - if gRoleNum[role3] ~= 0 and not world:isBeingMarked(gRoleNum[role3]) and canPassAndShoot(role3) then - return role3 - end - end - if role4 ~= nil and type(role4) == "string" then - if gRoleNum[role4] ~= 0 and not world:isBeingMarked(gRoleNum[role4]) and canPassAndShoot(role4) then - return role4 - end - end - if role5 ~= nil and type(role5) == "string" then - if gRoleNum[role5] ~= 0 and not world:isBeingMarked(gRoleNum[role5]) and canPassAndShoot(role5) then - return role5 - end - end - return "None" -end -- str 为所在的区域 -- script 为所使用的脚本 diff --git a/ZBin/lua_scripts/worldmodel/dir.lua b/ZBin/lua_scripts/worldmodel/dir.lua index 5617a0e..bc0c713 100644 --- a/ZBin/lua_scripts/worldmodel/dir.lua +++ b/ZBin/lua_scripts/worldmodel/dir.lua @@ -90,7 +90,7 @@ function evaluateTouch(p) end return function (role) if type(role) == "string" then - role = gRoleNum[role] + role = gSubPlay.getRoleNum(role) elseif type(role) == "number" and role >= 1 and role <= param.maxPlayer then role = role @@ -269,12 +269,6 @@ function sideBackDir() return (pos.sideBackPos()- pos.ourGoal()):dir() end -function getTandemDir(role) - return function () - return world:getTandemDir(gRoleNum[role]) - end -end - function reflectDir(d) return ball.refSyntYDir(d) end diff --git a/ZBin/lua_scripts/worldmodel/player.lua b/ZBin/lua_scripts/worldmodel/player.lua index 86792d2..533e962 100644 --- a/ZBin/lua_scripts/worldmodel/player.lua +++ b/ZBin/lua_scripts/worldmodel/player.lua @@ -3,7 +3,7 @@ module(..., package.seeall) function instance(role) local realIns if type(role) == "string" then - realIns = vision:ourPlayer(gRoleNum[role]) + realIns = vision:ourPlayer(num(role)) elseif type(role) == "number" then -- and role >= 1 and role <= param.maxPlayer then realIns = vision:ourPlayer(role) @@ -16,8 +16,12 @@ end function num(role) local retNum + if type(role) == "function" then + role = role() + end if type(role) == "string" then - retNum = gRoleNum[role] + retNum = gSubPlay.getRoleNum(role) + -- retNum = gRoleNum[role] elseif type(role) == "number" then retNum = role else @@ -150,10 +154,14 @@ end function toTargetDist(role) local p - if type(gRolePos[role]) == "function" then - p = gRolePos[role]() + local realrole = gSubPlay.getRole(role) + if type(gRolePos[realrole]) == "function" then + p = gRolePos[realrole]() else - p = gRolePos[role] + p = gRolePos[realrole] + end + if p == nil then + return 9999 end return player.pos(role):dist(p) end @@ -241,12 +249,13 @@ function canBreak(role) for i=1,param.maxPlayer do if enemy.valid(i) then local p - if type(gRolePos[role]) == "function" then - p = gRolePos[role]() + local realrole = gSubPlay.getRole(role) + if type(gRolePos[realrole]) == "function" then + p = gRolePos[realrole]() else - p = gRolePos[role] + p = gRolePos[realrole] end - local breakSeg = CGeoSegment:new_local(player.pos(role), p) + local breakSeg = CGeoSegment:new_local(player.pos(realrole), p) local projP = breakSeg:projection(enemy.pos(i)) if breakSeg:IsPointOnLineOnSegment(projP) then if enemy.pos(i):dist(projP) < 40 then @@ -353,7 +362,7 @@ function canFlatPassToPos(role, targetpos) end end for j = 1, param.maxPlayer do - if player.valid(j) and j ~= gRoleNum["Leader"] and player.pos(j):dist(p2) > 20 then + if player.valid(j) and j ~= num("Leader") and player.pos(j):dist(p2) > 20 then local dist = seg:projection(player.pos(j)):dist(player.pos(j)) local isprjon = seg:IsPointOnLineOnSegment(seg:projection(player.pos(j))) if dist < 12 and isprjon then diff --git a/ZBin/lua_scripts/worldmodel/pos.lua b/ZBin/lua_scripts/worldmodel/pos.lua index 4706682..b6b097c 100644 --- a/ZBin/lua_scripts/worldmodel/pos.lua +++ b/ZBin/lua_scripts/worldmodel/pos.lua @@ -254,12 +254,6 @@ function theirBestPlayer() return enemy.pos(oppNum) end -function getTandemPos(role) - return function () - return world:getTandemPos(gRoleNum[role]) - end -end - -- x, y分别为相对于球的偏移量, yys 2014-06-11 function reflectPos(x, y) return function () @@ -272,19 +266,6 @@ function reflectPos(x, y) end end -function reflectPassPos(role) - return function () - return world:getReflectPos(gRoleNum[role]) - end -end - --- y表示在距离中线多远的地方做touch, yys 2014-06-20 -function reflectTouchPos(role, y) - return function () - return world:getReflectTouchPos(gRoleNum[role], y) - end -end - -- 定位球传球点, yys 2014-06-16 function generateFreeKickPassPos(role) return function ()