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 16, 2024
2 parents 408cefe + 16c66ef commit b9db9ce
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Core/HuRocos-2024/play/our_Penalty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local p2 = CGeoPoint(- param.pitchLength / 2 + 300,param.pitchWidth / 2 - 600)
local p3 = CGeoPoint(- param.pitchLength / 2 + 300, -param.pitchWidth / 2 + 300)
local p4 = CGeoPoint(- param.pitchLength / 2 + 300,-param.pitchWidth / 2 + 600)
local p5 = CGeoPoint(- param.pitchLength / 2 , 0)
local shootThreshold = 2500
local shootThreshold = 2000

local canShoot = function(role,ishootThreshold)
if ball.posX() > ishootThreshold then
Expand Down
113 changes: 80 additions & 33 deletions Core/HuRocos-2024/play/their_Penalty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,47 @@ local stopPos = function(role)
end

local getBallPos = function(role)
local enemyNum = enemy.closestBall()
local rolePos = player.pos(role)
local enemyPos = enemy.pos(enemyNum)
local tPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 1, 1,param.V_DECAY_RATE)
if enemyPos:dist(tPos) < param.playerRadius then
tPos = tPos + Utils.Polar2Vector(param.playerRadius, (param.ourGoalPos-enemyPos):dir())
end
return tPos
local idir = (ball.pos() - param.ourGoalPos):dir()
local getBallPos = ball.pos() + Utils.Polar2Vector(-param.playerFrontToCenter*2, idir)
if Utils.InExclusionZone(getBallPos, 0, "our") and ball.velMod() < 200 then
return player.pos(role)
end
return getBallPos
end

local getBestInterBallPos = function(role)
local getBallPos = Utils.GetBestInterPos(vision, player.pos(role), param.playerVel, 2, 1, param.V_DECAY_RATE)
if getBallPos == CGeoPoint(param.INF, param.INF) then
return player.pos(role)
end
-- local getBallPos = getBallPos + Utils.Polar2Vector(-param.playerFrontToCenter*4, ball.velDir())
local getBallPos = getBallPos + Utils.Polar2Vector(ball.velMod()/10, ball.velDir())
if Utils.InExclusionZone(getBallPos, 0, "our") and ball.velMod() < 200 then
return player.pos(role)
end
return getBallPos
end

local getPlayerFlag = function(role)
local idir = math.abs(player.toBallDir(role))
return (idir < math.pi/2) and flag.allow_dss or flag.dodge_ball
end

local getShootPoint = function(role)
local enemyNum = enemy.closestBall()
local idir = (enemy.pos(enemyNum) - player.pos(role)):dir()
local targetPos = idir < 0 and CGeoPoint(player.posX(role), param.INF) or CGeoPoint(player.posX(role), -param.INF)
return targetPos
end

local subScript = false

return {

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


firstState = "Init",

["Init"] = {
Expand All @@ -48,52 +70,77 @@ firstState = "Init",
gSubPlay.new("Goalie", "Nor_Goalie")
end
if cond.isNormalStart() then
return "Defend"
return "Wait"
end
end,
Assister = function() return task.goCmuRush(stopPos("Assister"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Kicker = function() return task.goCmuRush(stopPos("Kicker"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Special = function() return task.goCmuRush(stopPos("Special"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Defender = function() return task.goCmuRush(stopPos("Defender"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Center = function() return task.goCmuRush(stopPos("Tier"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Goalie = task.goCmuRush(param.ourGoalPos, player.toBallDir("Goalie"), a, DSS_FLAG),
match = "[AKSC]{DG}"
Tier = function() return task.goCmuRush(stopPos("Tier"), 0, a, DSS_FLAG, r, v, s, force_manual) end,
Goalie = function() return task.goCmuRush(param.ourGoalPos, player.toBallDir("Goalie"), a, DSS_FLAG) end,
match = "[AKS]{TDG}"
},

["Defend"] = {
["Wait"] = {
switch = function()
-- debugEngine:gui_debug_msg(CGeoPoint(0,0),ball.posX())
-- if bufcnt(ball.pos():dist(enemy.pos(enemy.closestBall())) < param.playerRadius * 1.5, 20) then
-- return "Getball"
-- end
return "CatchBall"

-- if bufcnt(ball.pos():dist(enemy.pos(enemy.closestBall())) < param.playerRadius * 1.5, 20) then
-- return "Getball"
-- end
local enemyNum = enemy.closestBall()
if enemy.toBallDist(enemyNum)<param.playerRadius*1.5 then
return "Getball"
end
end,
Goalie = gSubPlay.roleTask("Goalie", "Goalie"),
-- Leader = task.getball(function() return shoot_pos end,playerVel,getballMode),
Goalie = function() return task.goCmuRush(param.ourGoalPos, player.toBallDir("Goalie"), a, DSS_FLAG) end,
match = "{G}"
},

["Getball"] = {
switch = function()
local enemyNum = enemy.closestBall()
if ball.velMod() < 100 then
maxBallVel = 0
end
if enemy.toBallDist(enemyNum)>param.playerRadius*4 or ball.velMod()>1000 then
return "CatchBall"
end

if player.myinfraredCount("Goalie") > 10 then
return "KickBall"
end
end,
-- Goalie = task.stop(),
Goalie = function() return task.goSimplePos(getBallPos("Goalie"), player.toBallDir("Goalie"), flag.dribbling) end,
match = "{G}"
},
["CatchBall"] = {
switch = function()
-- debugEngine:gui_debug_msg(CGeoPoint(0,0),ball.posX())
-- if ball.pos():dist(enemy.pos(enemy.closestBall())) > param.playerRadius * 1.5 then
-- return "Defend"
-- end
-- if ball.posX() < player.posX("Goalie") then
-- return "CatchBall"
-- end
local enemyNum = enemy.closestBall()

if bufcnt(enemy.toBallDist(enemyNum)<param.playerRadius*2, 50) then
return "Getball"
end

if player.myinfraredCount("Goalie") > 10 then
return "KickBall"
end
end,
-- Goalie = task.stop(),
Goalie = function() return task.goCmuRush(getBestInterBallPos("Goalie"), player.toBallDir("Goalie"), a, getPlayerFlag("Goalie")) end,
match = "{G}"
},

["KickBall"] = {
switch = function()
if player.toBallDist("Goalie") > param.playerRadius*2 then
return "CatchBall"
end
end,
Goalie = function() return task.goalie_catchBall("Goalie") end,
-- Goalie = task.stop(),
Goalie = task.ShootdotV3("Goalie", function() return getShootPoint("Goalie") end, 45, kick.flat),
match = "{G}"
},



name = "their_Penalty",
applicable ={
exp = "a",
Expand Down
1 change: 1 addition & 0 deletions Core/src/Utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ namespace Utils
ball_pos = pVision->rawBall().Pos();
double maxDist = GetBallMaxDist(pVision,acc) * (1 - rate);
CGeoPoint maxBallPos = ball_pos + Polar2Vector(maxDist, pVision->ball().Vel().dir());
GDebugEngine::Instance()->gui_debug_x(maxBallPos, 3);
CGeoPoint maxAllowedBallPos = CGeoPoint(inf, inf);
CGeoPoint maxTolerancePos = CGeoPoint(inf, inf);
CGeoPoint minGetBallPos = CGeoPoint(inf, inf);
Expand Down
2 changes: 1 addition & 1 deletion ZBin/lua_scripts/worldmodel/param.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ playerInfraredCountBuffer = CGetSettings("ZJHU/playerInfraredCountBuffer", "Int"
our_goalie_num = CGetSettings("ZJHU/our_goalie_num", "Int")
defend_num1 = CGetSettings("ZJHU/defend_num1", "Int")
defend_num2 = CGetSettings("ZJHU/defend_num2", "Int")
LeaderNum = 5
LeaderNum = 4
-----------------------------------------------|
-- feild参数 --|
-----------------------------------------------|
Expand Down
69 changes: 52 additions & 17 deletions ZBin/lua_scripts/worldmodel/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function power(p, num,shootFlag)
-- res = res * SimulationRate
res = 3500
if iflag == kick.chip() then
res = 3500
res = 3000
end
end
debugEngine:gui_debug_msg(CGeoPoint(-param.pitchLength / 2,param.pitchWidth / 2), "POWER:"..res .." TargetPos: " .. p1:x())
Expand Down Expand Up @@ -529,6 +529,28 @@ function ShootdotV2(p, error_, flag_,role)
end
end

-- goalie only
function ShootdotV3(role, p, error_, flag_)
local p1
if type(p) == 'function' then
p1 = p()
else
p1 = p
end

local shootpos = function(role)
return ball.pos() + Utils.Polar2Vector(-50, (p1 - ball.pos()):dir())
end
local idir = function(role)
return (p1 - player.pos(role)):dir()
end
local error__ = function()
return error_ * math.pi / 180.0
end

local mexe, mpos = GoCmuRush { pos = shootpos, dir = idir, acc = a, flag = flag.dribbling, rec = r, vel = v }
return { mexe, mpos, flag_, idir, error__, power(p, player.num(role), flag_), power(p, player.num(role), flag_), flag.dribbling }
end

function ShootdotDribbling(error_, flag_,power)
return function()
Expand Down Expand Up @@ -1218,34 +1240,47 @@ function goalie_catchBall(role)
local playerToBallDir = (ball.pos()-rolePos):dir()
local ballPos = ball.pos()


local getBallPos = ballPos + Utils.Polar2Vector(param.playerFrontToCenter, playerToBallDir)
local getBallPos = ballPos + Utils.Polar2Vector(-param.playerFrontToCenter, playerToBallDir)
local idir = playerToBallDir
local iflag = flag.dribbling


local ballLine = CGeoSegment(ballPos, ballPos+Utils.Polar2Vector(param.INF, ball.velDir()))
local tdist = (ballLine:projection(rolePos)-rolePos):mod()
if tdist > 500 then
idir = ball.velDir() + math.pi
iflag = flag.dodge_ball
getBallPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 1, 1,param.V_DECAY_RATE)
end





-- local ballLine = CGeoSegment(ballPos, ballPos+Utils.Polar2Vector(param.INF, ball.velDir()))
-- local tdist = (ballLine:projection(rolePos)-rolePos):mod()
-- if tdist > 100 then
-- idir = ball.velDir() + math.pi
-- iflag = flag.dodge_ball
-- getBallPos = Utils.GetBestInterPos(vision, rolePos, param.playerVel, 1, 1, param.V_DECAY_RATE)
-- end

-- if rolePos:dist(ballPos) < 300 then
-- iflag = flag.dribbling
-- iflag = flag.dribbling.abs(player.dir(role)-playerToBallDir)
-- -- local iflag = bit:_or(flag.allow_dss, flag.dodge_ball)
-- if Subdir > 0.14 then
-- return TurnToPointV2(role, ballPos, 4.8)
-- else
-- local mexe, mpos = GoCmuRush { pos = getBallPos, dir = idir, acc = a, flag = iflag, rec = r, vel = v }
-- return { mexe, mpos }
-- end

-- idir = playerToBallDir
-- getBallPos = ballPos + Utils.Polar2Vector(param.playerFrontToCenter, playerToBallDir)
-- end


-- local Subdir = math.abs(player.dir(role)-playerToBallDir)
-- -- local iflag = bit:_or(flag.allow_dss, flag.dodge_ball)
-- if Subdir > 0.14 then
-- return TurnToPointV2(role, ballPos, 4.8)
-- else
-- local mexe, mpos = GoCmuRush { pos = getBallPos, dir = idir, acc = a, flag = iflag, rec = r, vel = v }
-- return { mexe, mpos }
-- end


-- local mexe, mpos = GoCmuRush { pos = getBallPos, dir = idir, acc = a, flag = iflag, rec = r, vel = v }
local mexe, mpos = SimpleGoto { pos = getBallPos, dir = idir, flag = iflag }

local mexe, mpos = GoCmuRush { pos = getBallPos, dir = idir, acc = a, flag = iflag, rec = r, vel = v }
return { mexe, mpos }
end

Expand Down

0 comments on commit b9db9ce

Please sign in to comment.