Skip to content

Commit

Permalink
[Core] link real number with subPlay Role
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Apr 9, 2024
1 parent c1ee379 commit 066e7dc
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 173 deletions.
29 changes: 29 additions & 0 deletions Core/tactics/play/TestMyRun.lua
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 8 additions & 4 deletions Core/tactics/play/TestPassAndKick.lua
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 = ""
},

Expand Down
15 changes: 7 additions & 8 deletions Core/tactics/play/TestSubScript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down
58 changes: 34 additions & 24 deletions ZBin/lua_scripts/Play.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -226,7 +237,6 @@ function RunPlay(name)
elseif type(rolename)=="function" then
roleNum = rolename()
--print("Here in function : "..roleNum)

end

if roleNum ~= -1 then
Expand Down
20 changes: 1 addition & 19 deletions ZBin/lua_scripts/SelectPlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
95 changes: 80 additions & 15 deletions ZBin/lua_scripts/SubPlay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
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
4 changes: 2 additions & 2 deletions ZBin/lua_scripts/utils/utils.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 066e7dc

Please sign in to comment.