Skip to content

Commit

Permalink
[Core-TC] defB not finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed May 16, 2024
1 parent 81386d6 commit adf21fe
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 1 deletion.
1 change: 1 addition & 0 deletions Core/src/LuaModule/worldmodel.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class CWorldModel{
bool IsInfraredOn(int);
int InfraredOnCount(int);
int InfraredOffCount(int);
double predictRunTime(const PlayerVisionT& start, const CGeoPoint& Target, const CVector& targetVel);
}
5 changes: 4 additions & 1 deletion Core/src/WorldModel/WorldModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "BufferCounter.h"
// #include "BallStatus.h"
#include <singleton.hpp>
#include "CMmotion.h"
extern bool record_run_pos_on;
///
/// @file WoldModel.h
Expand Down Expand Up @@ -43,7 +44,9 @@ class CWorldModel{
int InfraredOnCount(int);
int InfraredOffCount(int);
bool KickDirArrived (int current_cycle, double kickdir, double kickdirprecision, int myNum = myDefaultNum);

double predictRunTime(const PlayerVisionT& start, const CGeoPoint& Target, const CVector& targetVel = CVector(0, 0)){
return predictedTime(start, Target, targetVel);
}
private:
const CVisionModule* _pVision;
const COptionModule* _pOption;
Expand Down
126 changes: 126 additions & 0 deletions Core/tactics/play/TC/TC2024DefenseB.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
local ORIGIN = CGeoPoint:new_local(0,0)
local CIRCLE_RADIUS = 800
local CIRCLE_DIST = 1500
local RUN_DIST = 1200
local WAIT_POS = {
ORIGIN + Utils.Polar2Vector(CIRCLE_DIST, 0*math.pi*2/3+math.pi),
ORIGIN + Utils.Polar2Vector(CIRCLE_DIST, 1*math.pi*2/3+math.pi),
ORIGIN + Utils.Polar2Vector(CIRCLE_DIST, 2*math.pi*2/3+math.pi),
}
local RUN_POS = {
ORIGIN + Utils.Polar2Vector(RUN_DIST, 0*math.pi*2/3),
ORIGIN + Utils.Polar2Vector(RUN_DIST, 1*math.pi*2/3),
ORIGIN + Utils.Polar2Vector(RUN_DIST, 2*math.pi*2/3),
}

local area = 1
local minDist = 99999
local farArea = 1
local farDist = 0
local checkClosest = function(pos)
local tempMinDist = 99999
local tempArea = -1
for i = 1, 3 do
if (pos-WAIT_POS[i]):mod() < tempMinDist then
tempMinDist = (pos-WAIT_POS[i]):mod()
tempArea = i
end
end
return tempArea, tempMinDist
end

local checkFarthest = function(pos)
local tempMaxDist = 0
local tempArea = -1
for i = 1, 3 do
if (pos-WAIT_POS[i]):mod() > tempMaxDist then
tempMaxDist = (pos-WAIT_POS[i]):mod()
tempArea = i
end
end
return tempArea, tempMaxDist
end

local update = function()
local ball = ball.rawPos()
area, minDist = checkClosest(ball)
farArea, farDist = checkFarthest(ball)
end

local dynPos = function()
return ORIGIN+Utils.Polar2Vector(500,(ORIGIN-WAIT_POS[farArea]):dir())
end
local dynDir = function()
return (ORIGIN - WAIT_POS[area]):dir() + math.pi/2
end

local RUSH_TASK = function()
local DIR = player.dir("a")
local ballVel = ball.vel()
local ball = ball.pos()
local targetPos = ball
local minTimePos = ball
local minTime = 99999
for dist = 0, 1000, 50 do
local targetPos = ball + Utils.Polar2Vector(dist, ballVel:dir())
local t1 = world:predictRunTime(player.instance("a"), targetPos, CVector(0,0))
local t2 = ballModel:timeForDist(dist)
if t1 < t2 then
return task.goCmuRush(targetPos,DIR)
end
if t1 < minTime then
minTime = t1
minTimePos = targetPos
end
end
local runDir = (minTimePos - player.pos("a")):dir()
return task.goCmuRush(minTimePos,DIR,_,_,Utils.Polar2Vector(2000,runDir))
end

return {
firstState = "reset",
["reset"] = {
switch = function()
gSubPlay.new("TC", "ZJRoboCon2024TC")
return "run"
end,
a = task.stop(),
match = "(a)"
},
["wait"] = {
switch = function()
update()
return gSubPlay.getState("TC") == "run" and "run" or "wait"
end,
a = task.goCmuRush(ORIGIN, player.dir("a")),
match = "(a)"
},
["run"] = {
switch = function()
update()
if not gSubPlay.getState("TC") == "run" then
return "wait"
end
if minDist > CIRCLE_RADIUS then
return "rush"
end
end,
-- a = task.runMultiPos(RUN_POS,true,30,0),
a = task.goCmuRush(dynPos, player.dir("a")),
match = "(a)"
},
['rush'] = {
switch = function()
update()
if not gSubPlay.getState("TC") == "run" then
return "wait"
end
if minDist < CIRCLE_RADIUS then
return "run"
end
end,
a = RUSH_TASK,
match = "(a)"
},
name = "TC2024DefenseB",
}

0 comments on commit adf21fe

Please sign in to comment.