Skip to content

Commit

Permalink
团体角球防守初版
Browse files Browse the repository at this point in the history
  • Loading branch information
dinzhen12 committed May 16, 2024
1 parent 622214d commit 88a610a
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 0 deletions.
174 changes: 174 additions & 0 deletions Core/HuRocos-2024/play/indirectDefend.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
local balldir = function ()
return function()
return player.toBallDir("Assister")
end
end
-- table.insert(jj,XX)
local depart =0

-- 0 = unlocked
-- 1 = locked
Locked_Enemy={
--0
--0

}

function Tdebug()
for i = 0,#Locked_Enemy-1 do
debugEngine:gui_debug_msg(CGeoPoint(-2000, 2000-150*i), "i: "..i.." ".."EnemyState: "..Locked_Enemy[i])
end
end
--获取球位置
local ballpos = ball.pos()
KeepDis = 100
--获取敌人车号
local enemy_num =0
local LockdefendNum = function(role)

local KeepEnemyNum = enemy.closestBall()
local j =KeepEnemyNum
Locked_Enemy[j] = 1
for i = 0,param.maxPlayer -1 do
if enemy.valid(i) and Locked_Enemy[i] ~= 1 then
enemy_num = i
Locked_Enemy[i] = 1
break
end
end

return enemy_num
end

local EnemyPos =function (role)
-- local enemynum = LockdefendNum(role)
local enemynum = 0



local enemypos = enemy.pos(enemynum)
return enemypos
end

local DenfendPosFront = function (role)
ballpos = ball.pos()
local denfendPosfront = EnemyPos(role) + Utils.Polar2Vector(KeepDis,(EnemyPos(role)- ballpos):dir() + math.pi / 3)
return denfendPosfront
end

local DenfendPosCenter = function (role)
ballpos = ball.pos()
local denfendPoscenter = EnemyPos(role) + Utils.Polar2Vector(KeepDis,(EnemyPos(role)- ballpos):dir() + math.pi / 3)
return denfendPoscenter
end
-------------------------------------------------------------------------------------------------
return {

__init__ = function(name, args)
print("in __init__ func : ",name, args)
end,


firstState = "Init",

["Init"] = {
switch = function ()
for i = 0,param.maxPlayer -1 do
if enemy.valid(i) then
Locked_Enemy[i] = -1
else
Locked_Enemy[i] = -2
end
end


local ballpos = ball.pos()
local enemy_num =0
local KeepEnemyNum = enemy.closestBall()
local j = KeepEnemyNum
Tdebug()
if ball.posX() < depart then
return"front"
else
return"center"
end
end,
Assister = function () return (task.goCmuRush(DenfendPosFront("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(DenfendPosFront("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(DenfendPosFront("Special"),balldir("Special"),DSS_FLAG)) end,
match = "[AKS]"
},


["front"] = {
switch = function()
--[[local enemypos_1 = enemy.pos(defendNum("Tier"))
local enemypos_2 = enemy.pos(defendNum("Defender"))--]]
local ballpos = ball.pos()
local enemy_num =0
local KeepEnemyNum = enemy.closestBall()
local ballpos = ball.pos()
if ball.velMod() > 500 then
return "exit"
end
Tdebug()
end,
Assister = function () return (task.goCmuRush(DenfendPosFront("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(DenfendPosFront("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(DenfendPosFront("Special"),balldir("Special"),DSS_FLAG)) end,

match = "[AKS]"
} ,
["center"] = {
switch = function()
--[[local enemypos_1 = enemy.pos(defendNum("Tier"))
local enemypos_2 = enemy.pos(defendNum("Defender"))--]]


-- if (LockdefendNum("Assister") == 0 and LockdefendNum("Kicker") == 0)then
-- Locked_Enemy={
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- 0,
-- }
-- end
debugEngine:gui_debug_msg(CGeoPoint(0,0),LockdefendNum("Assister"),5)
debugEngine:gui_debug_msg(CGeoPoint(0,200),LockdefendNum("Kicker"),5)
debugEngine:gui_debug_msg(CGeoPoint(0,400),LockdefendNum("Special"),5)
local ballpos = ball.pos()
local enemy_num =0
local KeepEnemyNum = enemy.closestBall()
local ballpos = ball.pos()
if ball.velMod() > 500 then
return "exit"
end
Tdebug()
end,
Assister = function () return (task.goCmuRush(DenfendPosCenter("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(DenfendPosCenter("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(DenfendPosCenter("Special"),balldir("Special"),DSS_FLAG)) end,
match = "[AKS]"
} ,


name = "IndirectDefend",
applicable = {
exp = "a",
a = true
},
attribute = "attack",
timeout = 99999
}
176 changes: 176 additions & 0 deletions Core/HuRocos-2024/play/indirectDefend_New.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
local balldir = function ()
return function()
return player.toBallDir("Assister")
end
end
-- table.insert(jj,XX)
local depart = 0

Free_Enemy={}
Free_Player={}

Match = {}
function Tdebug()
for i = 0,#Locked_Enemy-1 do
debugEngine:gui_debug_msg(CGeoPoint(-2000, 2000-150*i), "i: "..i.." ".."EnemyState: "..Locked_Enemy[i])
end
end
--获取球位置
local ballpos = ball.pos()
KeepDis = 100

--获取敌人车号
-- local LockdefendNum = function()
-- if enemy.valid(j) and Locked_Enemy[j] ==-1 then
-- local enemy_num =0
-- enemy_num = j
-- Locked_Enemy[j] = -2
-- end
-- return enemy_num
-- end


local DenfendPosFront = function (role)
-- debugEngine:gui_debug_msg(CGeoPoint(0,0), player.num(role))
-- for i =1, #Free_Player do
-- debugEngine:gui_debug_msg(CGeoPoint(0,150+i*150), Free_Player[i])
-- end

ballpos = ball.pos()
local denfendPosfront = enemy.pos(Match[player.num(role)]) + Utils.Polar2Vector(KeepDis, (enemy.pos(Match[player.num(role)]) - ballpos):dir() + math.pi / 3)
return denfendPosfront
end

local DenfendPosCenter = function (role)
-- debugEngine:gui_debug_msg(CGeoPoint(0,0), player.num(role))
-- for i =1, #Free_Player do
-- debugEngine:gui_debug_msg(CGeoPoint(0,150+i*150), Free_Player[i])
-- end

ballpos = ball.pos()
local denfendPoscenter = enemy.pos(Match[player.num(role)]) + Utils.Polar2Vector(KeepDis, (enemy.pos(Match[player.num(role)]) - ballpos):dir() + math.pi / 3)
return denfendPoscenter
end

-------------------------------------------------------------------------------------------------
return {

__init__ = function(name, args)
print("in __init__ func : ",name, args)
end,


firstState = "Init",

["Init"] = {
switch = function ()
-- 预处理,导入所有车辆
local Free_Enemy_Len = 1
for i = 0, param.maxPlayer - 1 do
if enemy.valid(i) then
Free_Enemy[Free_Enemy_Len] = i
Free_Enemy_Len = Free_Enemy_Len + 1
end
end

local Free_Player_Len = 1
for i = 0, param.maxPlayer - 1 do
if player.valid(i) then
Free_Player[Free_Player_Len] = i
Free_Player_Len = Free_Player_Len + 1
end
end

-- 排除最近的机器人并且移出队列
for i = 1, #Free_Enemy do
if Free_Enemy[i] == enemy.closestBall() then
Free_Enemy[i] = Free_Enemy[#Free_Enemy]
end
end

-- 一人一防
for i = 1, #Free_Enemy do -- E == P
if i > #Free_Player then -- E > P
break
end
Match[Free_Player[i]] = Free_Enemy[(i + #Free_Enemy - 1) % #Free_Enemy + 1] -- E < P

-- debugEngine:gui_debug_msg(CGeoPoint(0,300 + 150 * i), Free_Player[i].." "..Match[Free_Player[i]].." "..((i + #Free_Enemy - 1) % #Free_Enemy + 1))
-- debugEngine:gui_debug_msg(CGeoPoint(0,300 + 150 * i), Free_Player[i].." "..Match[Free_Player[i]])
end

if(bufcnt(true, 5)) then
Tdebug()
if ball.posX() < depart then
return "front"
else
return "center"
end
end
end,

Assister = function () return (task.goCmuRush(player.pos("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(player.pos("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(player.pos("Special"),balldir("Special"),DSS_FLAG)) end,

-- Assister = task.stop(),
-- Kicker = task.stop(),
-- Special = task.stop(),

match = "[AKS]"
},

["N"] = {
switch = function ()

end,

Assister = function () return (task.goCmuRush(player.pos("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(player.pos("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(player.pos("Special"),balldir("Special"),DSS_FLAG)) end,

match = "[AKS]"
},

["front"] = {
switch = function()

local ballpos = ball.pos()
if ball.velMod() > 500 then
return "exit"
end
Tdebug()
end,
Assister = function () return (task.goCmuRush(DenfendPosFront("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(DenfendPosFront("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(DenfendPosFront("Special"),balldir("Special"),DSS_FLAG)) end,

match = "[AKS]"
} ,
["center"] = {
switch = function()

-- debugEngine:gui_debug_msg(CGeoPoint(0,0),LockdefendNum("Assister"),5)
-- debugEngine:gui_debug_msg(CGeoPoint(0,200),LockdefendNum("Kicker"),5)
-- debugEngine:gui_debug_msg(CGeoPoint(0,400),LockdefendNum("Special"),5)
local ballpos = ball.pos()
if ball.velMod() > 500 then
return "exit"
end
Tdebug()
end,
Assister = function () return (task.goCmuRush(DenfendPosCenter("Assister"),balldir("Assister"),DSS_FLAG)) end,
Kicker = function () return (task.goCmuRush(DenfendPosCenter("Kicker"),balldir("Kicker"),DSS_FLAG)) end,
Special = function () return (task.goCmuRush(DenfendPosCenter("Special"),balldir("Special"),DSS_FLAG)) end,
match = "[AKS]"
} ,


name = "IndirectDefend_New",
applicable = {
exp = "a",
a = true
},
attribute = "attack",
timeout = 99999
}

0 comments on commit 88a610a

Please sign in to comment.