Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Umbrella167/Rocos
Browse files Browse the repository at this point in the history
  • Loading branch information
Umbrella167 committed May 14, 2024
2 parents 9336b34 + e3a0938 commit 60f3fbf
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Core/HuRocos-2024/play/Nor_Defend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ return {
end,
Tier = function() return task.defend_norm("Tier", 0) end,
Defender = function() return task.defend_norm("Defender", 1) end,
match = "(TD)"
match = "{TD}"
},
["defend_front"] = {
switch = function()
Expand All @@ -48,7 +48,7 @@ return {
end,
Tier = function() return task.defend_front("Tier") end,
Defender = function() return task.defend_front("Defender") end,
match = "(TD)"
match = "{TD}"
},
["defend_kick"] = {
switch = function()
Expand All @@ -58,7 +58,7 @@ return {
end,
Tier = function() return task.defend_kick("Tier") end,
Defender = function() return task.defend_kick("Defender") end,
match = "(TD)"
match = "{TD}"
},

name = "Nor_Defend",
Expand Down
77 changes: 77 additions & 0 deletions Core/HuRocos-2024/play/Nor_DefendV2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
return {
__init__ = function(name, args)
print("in __init__ func : ",name, args)
end,
firstState = "defend_norm",
["defend_norm"] = {
switch = function()
local rolePos = CGeoPoint:new_local(player.rawPos("Goalie"):x(), player.rawPos("Goalie"):y())
local getBallPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 1, 1,param.V_DECAY_RATE)




-- local ballToCloestEnemyDist = ball.rawPos():dist(enemy.pos(enemy.closestBall()))
-- for i=0, param.maxPlayer-1 do
-- if enemy.valid(i) then
-- -- debugEngine:gui_debug_msg(CGeoPoint(-1000, 1000+(i*150)), i.." "..enemy.toOurGoalDist(i).." "..param.FronterRadius*5/3)
-- if enemy.toOurGoalDist(i) < param.FronterRadius*5/3 then
-- return "defend_front"
-- end
-- end
-- end

-- if player.toBallDist(player.closestBall()) > param.playerRadius * 6 then
-- for i=0, task.FronterCount-1 do
-- local rolePos = CGeoPoint:new_local(player.rawPos(task.FronterNums[i]):x(), player.rawPos(task.FronterNums[i]):y())
-- local getBallPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 2,0,param.V_DECAY_RATE)
-- if player.toPointDist(task.FronterNums[i], getBallPos) < 1000 then
-- return "defend_kick"
-- end
-- end
-- end
end,
Breaker = function() return task.defend_normV2("Breaker", 0, 1) end,
Fronter = function() return task.defend_normV2("Fronter", 1, 1) end,
match = "[BF]"
},
["defend_front"] = {
switch = function()
if bufcnt(true, 20) then
end
if player.toBallDist(player.closestBall()) > param.playerRadius * 6 then
for i=0, task.FronterCount-1 do
local rolePos = CGeoPoint:new_local(player.rawPos(task.FronterNums[i]):x(), player.rawPos(task.FronterNums[i]):y())
local getBallPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 2,0,param.V_DECAY_RATE)
if player.toPointDist(task.FronterNums[i], getBallPos) < 300 then
return "defend_kick"
end
end
end
if enemy.toOurGoalDist(enemy.closestGoal()) > param.FronterRadius*5/3 then
return "defend_norm"
end
end,
Breaker = function() return task.defend_front("Breaker") end,
Fronter = function() return task.defend_front("Fronter") end,
match = "[TD]"
},
["defend_kick"] = {
switch = function()
if bufcnt(true, 20) then
return "defend_norm"
end
end,
Breaker = function() return task.defend_kick("Breaker") end,
Fronter = function() return task.defend_kick("Fronter") end,
match = "[TD]"
},

name = "Nor_DefendV2",
applicable = {
exp = "a",
a = true
},
attribute = "attack",
timeout = 99999
}
11 changes: 9 additions & 2 deletions ZBin/lua_scripts/worldmodel/param.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ penaltyDepth = CGetSettings("field/penaltyWidth", "Int")
penaltyRadius = penaltyWidth / 2
penaltySegment = 500
ourTopRightPenaltyPos = CGeoPoint:new_local(-pitchLength / 2 + penaltyDepth, penaltyRadius)
ourButtomRightPenaltyPos = CGeoPoint:new_local(-pitchLength / 2 + penaltyDepth, -penaltyRadius)
ourTopPenaltyPos = CGeoPoint:new_local(-pitchLength / 2, penaltyRadius)
ourButtomPenaltyPos = CGeoPoint:new_local(-pitchLength / 2, -penaltyRadius)
-- 球门参数
Expand All @@ -37,7 +38,7 @@ ourGoalLine = CGeoSegment(CGeoPoint:new_local(-pitchLength / 2, -I
ourGoalPos = CGeoPoint:new_local(-pitchLength / 2, 0)
ourTopGoalPos = CGeoPoint:new_local(-pitchLength / 2, goalRadius)
ourButtomGoalPos = CGeoPoint:new_local(-pitchLength / 2, -goalRadius)

penaltyMiddleLine = CGeoSegment(ourGoalPos, ourGoalPos + Utils.Polar2Vector(penaltyDepth, 0))

-- 是否为真实场地
isReality = false
Expand Down Expand Up @@ -102,7 +103,13 @@ markingPosRate2 = 1 / 10
-- defend参数 --|
-----------------------------------------------|
defenderShootMode = function() return 1 end -- 1 flat 2 chip
defenderBuf = playerRadius * 3
defenderBuf = playerRadius * 1.5

defenderTopRightPos = CGeoPoint:new_local(-pitchLength / 2 + penaltyDepth + defenderBuf, penaltyRadius + defenderBuf)
defenderButtomRightPos = CGeoPoint:new_local(-pitchLength / 2 + penaltyDepth + defenderBuf, -penaltyRadius - defenderBuf)
defenderTopPos = CGeoPoint:new_local(-pitchLength / 2, penaltyRadius + defenderBuf)
defenderButtomPos = CGeoPoint:new_local(-pitchLength / 2, -penaltyRadius - defenderBuf)

defenderRadius = ourGoalPos:dist(ourTopRightPenaltyPos) + defenderBuf
defenderAimX = -pitchLength / 4
-----------------------------------------------|
Expand Down
130 changes: 129 additions & 1 deletion ZBin/lua_scripts/worldmodel/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ function getDefenderCount()
defenderCount = 0
for i=0, param.maxPlayer-1 do
playerName = player.name(i)
if player.valid(i) and (playerName == "Tier" or playerName == "Defender") then
if player.valid(i) and (playerName == "Breaker" or playerName == "Fronter") then
defenderNums[defenderCount] = i
defenderCount = defenderCount + 1
end
Expand All @@ -743,6 +743,134 @@ function isClosestPointDefender(role, p)
return player.num(role)==roleNum and true or false
end

function getLineCrossDefenderPos(pos_, posOrDir_)
local resPos = CGeoPoint(param.INF, param.INF)
local minDist = param.INF
local line_ = CGeoSegment(pos_, pos_)
if type(posOrDir_) == 'number' then
line_ = CGeoSegment(pos_, pos_+Utils.Polar2Vector(param.INF, posOrDir_))
debugEngine:gui_debug_line(pos_, pos_+Utils.Polar2Vector(param.INF, posOrDir_))
elseif type(posOrDir_) == 'userdata' then
line_ = CGeoSegment(pos_, posOrDir_)
debugEngine:gui_debug_line(pos_, posOrDir_)
end
-- 打印defender行走的框
debugEngine:gui_debug_line(param.defenderTopRightPos, param.defenderButtomRightPos)
debugEngine:gui_debug_line(param.defenderTopPos, param.defenderTopRightPos)
debugEngine:gui_debug_line(param.defenderButtomPos, param.defenderButtomRightPos)

local defenderTopLine = CGeoSegment(param.defenderTopPos, param.defenderTopRightPos)
local defenderMiddleLine = CGeoSegment(param.defenderTopRightPos, param.defenderButtomRightPos)
local defenderButtomLine = CGeoSegment(param.defenderButtomPos, param.defenderButtomRightPos)
local tPos = line_:segmentsIntersectPoint(defenderTopLine)
if pos_:dist(tPos) < minDist then
resPos = tPos
minDist = pos_:dist(tPos)
end
-- debugEngine:gui_debug_x(tPos, 0)
local tPos = line_:segmentsIntersectPoint(defenderMiddleLine)
if pos_:dist(tPos) < minDist then
resPos = tPos
minDist = pos_:dist(tPos)
end
-- debugEngine:gui_debug_x(tPos, 0)
local tPos = line_:segmentsIntersectPoint(defenderButtomLine)
if pos_:dist(tPos) < minDist then
resPos = tPos
minDist = pos_:dist(tPos)
end
-- debugEngine:gui_debug_x(tPos, 0)
return resPos
end

function isCrossPenalty(rolePos, targetPos)
local line_ = CGeoSegment(rolePos, targetPos)
local tPos = line_:segmentsIntersectPoint(param.penaltyMiddleLine)
debugEngine:gui_debug_x(tPos)
debugEngine:gui_debug_msg(CGeoPoint(1000, 1000), tPos:x().." "..tPos:y())
if tPos == CGeoPoint(9999, 9999) then
return false
end
return true
end

function simpleMoveTargetPos(rolePos, targetPos)
local tPosX = targetPos:x()
local tPosY = targetPos:y()
debugEngine:gui_debug_msg(CGeoPoint(-2000, 2000), "x: "..math.abs(rolePos:x() - targetPos:x()))
debugEngine:gui_debug_msg(CGeoPoint(-2000, 2200), "y: "..math.abs(rolePos:y() - targetPos:y()))

debugEngine:gui_debug_msg(CGeoPoint(0,0), tostring(isCrossPenalty(rolePos, targetPos)))

if math.abs(rolePos:x() - targetPos:x()) > 100 and math.abs(rolePos:y() - targetPos:y()) > 100 or isCrossPenalty(rolePos, targetPos) then
tPosX = param.defenderTopRightPos:x()
if math.abs(rolePos:y() - param.defenderTopRightPos:y()) < 100 and math.abs(rolePos:x() - param.defenderTopRightPos:x()) > param.defenderBuf then
tPosY = param.defenderTopRightPos:y()
-- tPosY = rolePos:y()
end
if math.abs(rolePos:y() - param.defenderButtomRightPos:y()) < 100 and math.abs(rolePos:x() - param.defenderButtomRightPos:x()) > param.defenderBuf then
tPosY = param.defenderButtomRightPos:y()
-- tPosY = rolePos:y()
end
end

return CGeoPoint(tPosX, tPosY)
end


-- defender_norm script
-- mode: 0 upper area, 1 down area, 2 middle
-- flag: 0 aim the ball, 1 aim the enemy
function defend_normV2(role, mode, flag)
debugEngine:gui_debug_x(getLineCrossDefenderPos(ball.pos(), ball.velDir()), 3)
debugEngine:gui_debug_x(getLineCrossDefenderPos(ball.pos(), param.ourGoalPos), 3)


getDefenderCount()
if defenderCount == 1 then
mode = 2
end
if flag == nil then
flag = 0
end
local enemyNum = getManMarkEnemy()
local enemyPos = CGeoPoint:new_local(enemy.posX(enemyNum), enemy.posY(enemyNum))
local goalieToEnemyDir = (enemy.pos(enemyNum) - player.rawPos("Goalie")):dir()
local rolePos = CGeoPoint:new_local(player.rawPos(role):x(), player.rawPos(role):y())
local ballPos = CGeoPoint:new_local(ball.rawPos():x(), ball.rawPos():y())
local basePos = param.ourGoalPos
local targetPos = ballPos

if mode == 0 then
basePos = param.ourTopGoalPos
elseif mode == 1 then
basePos = param.ourButtomGoalPos
elseif mode == 2 then
basePos = param.ourGoalPos
end

if flag == 0 then
targetPos = ballPos
elseif flag == 1 then
targetPos = enemyPos
end

local defenderPoint = getLineCrossDefenderPos(targetPos, basePos)

if defenderPoint == CGeoPoint(9999, 9999) then
defenderPoint = rolePos
end
defenderPoint = simpleMoveTargetPos(rolePos, defenderPoint)
debugEngine:gui_debug_x(defenderPoint, 0)

local idir = player.toPointDir(enemyPos, role)
local mexe, mpos = SimpleGoto { pos = defenderPoint, dir = idir, acc = a, flag = 0x00000100, rec = r, vel = endVelController(role, defenderPoint) }
-- local mexe, mpos = GoCmuRush { pos = defenderPoint, dir = idir, acc = a, flag = 0x00000100, rec = r, vel = endVelController(role, defenderPoint) }
return { mexe, mpos }
end



-- defender_norm script
-- mode: 0 upper area, 1 down area, 2 middle
-- flag: 0 aim the ball, 1 aim the enemy
Expand Down

0 comments on commit 60f3fbf

Please sign in to comment.