📄 decisionmakingx.cpp
字号:
}
/************************************************************************/
/* 跑位函数 */
/************************************************************************/
void CDecisionMakingx::Wait(int nRobot, VecPosition posTarget, double angle, double speed)
{
VecPosition posRobot(Robot[nRobot].x, Robot[nRobot].y);
if ( (posTarget - posRobot).GetMagnitude() > 1)
{
#if 0
VecPosition* posObstatcles = new VecPosition[m_nPriorityResult[nRobot]+3];
posObstatcles[0] = posTarget; // 目标
posObstatcles[1] = m_posBall; // 球
int nOb = 1;
for (int i=0; i<ROBOTNUMBER; i++)
{
if (m_nPriorityResult[i] < m_nPriorityResult[nRobot])
{
posObstatcles[nOb+1].SetVecPosition(Robot[i].x, Robot[i].y);
nOb++;
}
}
if (nOb != m_nPriorityResult[nRobot]+1)
::MessageBox(NULL, "Obstacle Avoid, Priority", "Error", MB_OK);
ToPositionAvoidObstacles(&Robot[nRobot], posObstatcles, nOb, &rbV[nRobot]);
delete[] posObstatcles;
#else
ToPositionPD(nRobot, posTarget, speed);
#endif
}
else
{
TurnToAnglePD(nRobot, angle, NOCLOCK);
}
}
void CDecisionMakingx::Wait(int nRobot, VecPosition posTarget, VecPosition posToward, double speed)
{
VecPosition posRobot(Robot[nRobot].x, Robot[nRobot].y);
double angle = (posToward-posRobot).GetDirection();
Wait(nRobot, posTarget, angle, speed);
}
/************************************************************************/
/* 直线射门函数 */
/************************************************************************/
void CDecisionMakingx::ShootLine(int nRobot)
{
VecPosition posRobot(Robot[nRobot].x, Robot[nRobot].y);
VecPosition posBall;
int nCycle = GetKickBallPerformance(21, nRobot, posBall);
Line line = Line::MakeLineFromTwoPoints(posRobot, posBall);
double y = line.GetYGivenX(PITCH_LENGTH);
VecPosition posOpponentGoalie(Robot[2*ROBOTNUMBER-1].x, Robot[2*ROBOTNUMBER-1].y);
SendMsg(1, "%d %2.2f", nCycle, y);
if ( m_bShootLine[nRobot]
|| (y > PITCH_WIDTH/2-GOAL_WIDTH/2 -5
&& y < PITCH_WIDTH/2 + GOAL_WIDTH/2 + 5
&& posBall.GetX() < PITCH_LENGTH + 10
&& posBall.GetX() > PITCH_LENGTH/2
&& posRobot.GetX() < posBall.GetX()
&& posRobot.GetX() > PITCH_LENGTH/3)
)
{
ToPositionN(nRobot, posBall, MAXSPEED);
m_bShootLine[nRobot] = TRUE;
m_timerShootLine.Start(10);
}
if ( (posRobot-m_posBall).GetMagnitude() < 10
|| m_posBall.GetX() > PITCH_LENGTH)
{
m_bShootLine[nRobot] = FALSE;
Turn(nRobot, 90, ANTICLOCK);
}
}
int CDecisionMakingx::GetShootLinePerformance(int nRobot)
{
VecPosition posRobot(Robot[nRobot].x, Robot[nRobot].y);
VecPosition posBall;
int nCycle = GetKickBallPerformance(21, nRobot, posBall);
Line line = Line::MakeLineFromTwoPoints(posRobot, posBall);
double y = line.GetYGivenX(PITCH_LENGTH);
if ( m_bShootLine[nRobot]
|| (y > PITCH_WIDTH/2-GOAL_WIDTH/2 -5
&& y < PITCH_WIDTH/2 + GOAL_WIDTH/2 + 5
&& posBall.GetX() < PITCH_LENGTH + 10
&& posBall.GetX() > PITCH_LENGTH/2
&& posRobot.GetX() < posBall.GetX()
&& posRobot.GetX() > PITCH_LENGTH/2)
)
{
if (!m_bShootLine[nRobot])
return nCycle;
else
return static_cast<int>(nCycle*0.6);
}
else
{
return -1;
}
}
/************************************************************************/
/* 预测踢球函数 */
/************************************************************************/
void CDecisionMakingx::KickBall(int nRobot)
{
VecPosition posBall;
VecPosition posTarget;
if(posBall.GetY() > PITCH_WIDTH/2)
posTarget=(30,54);
else
posTarget=(30,126);
if(m_posBall.GetX()>Robot[nRobot].x)
{
GetKickBallPerformance(21, nRobot, posBall);
ToPositionN(nRobot, posBall, MAXSPEED);
}
else
{
GetToPositionNewPerformance(11, nRobot, posTarget, posBall);
ToPositionNew(nRobot,posTarget,posBall,MAXSPEED,3);
}
}
/************************************************************************/
/* 归位函数 */
/************************************************************************/
void CDecisionMakingx::RobotReturn2Pt()
{
if(together)
{
RobotReturn2bound();
return;
}
if(round)
{
Round(m_nTestRobot-1);
return;
}
dbPOINT pt[12];
switch(dmDEG.DEStartMode)
{
case NormalStart:
{
if(dmDEG.DEStartState == Attack)
{
pt[1].x = PITCH_LENGTH/2+8;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = PITCH_LENGTH/2-15;
pt[2].y = PITCH_WIDTH/2;
pt[3].x = PITCH_LENGTH*.25;
pt[3].y = PITCH_WIDTH*.75;
pt[4].x = PITCH_LENGTH*.25;
pt[4].y = PITCH_WIDTH*.25;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else
{
pt[1].x = PITCH_LENGTH/2-20;
pt[1].y = PITCH_WIDTH/2+20;
pt[2].x = PITCH_LENGTH/2-15;
pt[2].y = PITCH_WIDTH/2;
pt[3].x = PITCH_LENGTH*.25;
pt[3].y = PITCH_WIDTH*.75;
pt[4].x = PITCH_LENGTH*.25;
pt[4].y = PITCH_WIDTH*.25;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
}
break;
case PenaltyKick:
{
if(dmDEG.DEStartState == Defense)
{
pt[1].x = PITCH_LENGTH/2+8;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = PITCH_LENGTH/2+8;
pt[2].y = PITCH_WIDTH/2+70;
pt[3].x = PITCH_LENGTH/2+8;
pt[3].y = PITCH_WIDTH*.25;
pt[4].x = PITCH_LENGTH/2+8;
pt[4].y = PITCH_WIDTH*.75;
pt[5].x = 8;
pt[5].y = PITCH_WIDTH/2;
}
else
{
pt[1].x = PITCH_LENGTH-45;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = PITCH_LENGTH/2-10;
pt[2].y = PITCH_WIDTH/2;
pt[3].x = PITCH_LENGTH/2-10;
pt[3].y = PITCH_WIDTH*.25;
pt[4].x = PITCH_LENGTH/2-10;
pt[4].y = PITCH_WIDTH*.75;
pt[5].x = 8;
pt[5].y = PITCH_WIDTH/2;
}
}
break;
case GoalKick:
{
if(dmDEG.DEStartState == Defense)
{
pt[1].x = PITCH_LENGTH/2-15;
pt[1].y = m_posBall.GetY();
pt[2].x = PITCH_LENGTH/2-30;
pt[2].y = PITCH_WIDTH/2;
pt[3].x = PITCH_LENGTH/2-15;
pt[3].y = PITCH_WIDTH*.75;
pt[4].x = PITCH_LENGTH/2-15;
pt[4].y = PITCH_WIDTH*.25;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else
{
pt[1].x = 5;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = PITCH_LENGTH/2-15;
pt[2].y = PITCH_WIDTH/2-40;
pt[3].x = PITCH_LENGTH*.25;
pt[3].y = PITCH_WIDTH*.75;
pt[4].x = PITCH_LENGTH*.25;
pt[4].y = PITCH_WIDTH*.25;
pt[5].x = 15;
pt[5].y = PITCH_WIDTH/2+50;
}
}
break;
case FreeKick:
{
if(dmDEG.DEStartState == Attack)
{
pt[1].x = PITCH_LENGTH/2+63;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = PITCH_LENGTH/2-15;
pt[2].y = PITCH_WIDTH/2;
pt[3].x = PITCH_LENGTH*.75;
pt[3].y = PITCH_WIDTH*.75;
pt[4].x = PITCH_LENGTH*.75;
pt[4].y = PITCH_WIDTH*.25;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else
{
pt[1].x = 5;
pt[1].y = PITCH_WIDTH/2;
pt[2].x = 25;
pt[2].y = PITCH_WIDTH/2-20;
pt[3].x = 25;
pt[3].y = PITCH_WIDTH/2+20;
pt[4].x = PITCH_LENGTH*.15;
pt[4].y = PITCH_WIDTH/2-45;
pt[5].x = 15;
pt[5].y = PITCH_WIDTH/2+45;
}
}
break;
case FreeBall:
{
if(m_posBall.GetX()<PITCH_LENGTH/2 && m_posBall.GetY()<PITCH_WIDTH/2)
{
pt[1].x = 30;
pt[1].y = 30;
pt[2].x = PITCH_LENGTH/2+15;
pt[2].y = PITCH_WIDTH/2+40;
pt[3].x = 20;
pt[3].y = PITCH_WIDTH/2+10;
pt[4].x = 40;
pt[4].y = PITCH_WIDTH/2+20;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else if(m_posBall.GetX()<PITCH_LENGTH/2 && m_posBall.GetY()>PITCH_WIDTH/2)
{
pt[1].x = 30;
pt[1].y = PITCH_WIDTH-30;
pt[2].x = PITCH_LENGTH/2+15;
pt[2].y = PITCH_WIDTH-(PITCH_WIDTH/2+15);
pt[3].x = 20;
pt[3].y = PITCH_WIDTH-(PITCH_WIDTH/2+10);
pt[4].x = 40;
pt[4].y = PITCH_WIDTH-(PITCH_WIDTH/2+20);
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else if(m_posBall.GetX()>PITCH_LENGTH/2 && m_posBall.GetY()<PITCH_WIDTH/2)
{
pt[1].x = (PITCH_LENGTH-80);
pt[1].y = 30;
pt[2].x = PITCH_LENGTH - 80;
pt[2].y = PITCH_WIDTH/2+15;
pt[3].x = 2*156-(PITCH_LENGTH-10);
pt[3].y = 30;
pt[4].x = 2*156-(PITCH_LENGTH-20);
pt[4].y = 60;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
else
{
pt[1].x = (PITCH_LENGTH-80);//2*156-
pt[1].y = PITCH_WIDTH-30;
pt[2].x = PITCH_LENGTH - 80;
pt[2].y = PITCH_WIDTH-(PITCH_WIDTH/2+15);
pt[3].x = 2*156-(PITCH_LENGTH-10);
pt[3].y = PITCH_WIDTH-30;
pt[4].x = 2*156-(PITCH_LENGTH-20);
pt[4].y = PITCH_WIDTH-60;
pt[5].x = 5;
pt[5].y = PITCH_WIDTH/2;
}
}
break;
default:
break;
}
for(int i=0;i<ROBOTNUMBER-1;i++)
{
Wait(i, VecPosition(pt[i+1].x, pt[i+1].y), m_posBall, 40);
}
Wait(ROBOTNUMBER, VecPosition(pt[ROBOTNUMBER].x, pt[ROBOTNUMBER].y),
PI/2, 40);
}
void CDecisionMakingx::RobotReturn2bound()
{
PreProcess();//信息预处理
VecPosition pos[ROBOTNUMBER];
pos[0].SetVecPosition(PITCH_LENGTH/2-30, 15);
pos[1].SetVecPosition(PITCH_LENGTH/2-15, 15);
pos[2].SetVecPosition(PITCH_LENGTH/2, 15);
pos[3].SetVecPosition(PITCH_LENGTH/2+15, 15);
pos[4].SetVecPosition(PITCH_LENGTH/2+30, 15);
for(int i=0;i<ROBOTNUMBER;i++)
ToPositionPD(i,pos[i], 40);
}
void CDecisionMakingx::Round(int nRoundRobot)
{
VecPosition pos[12];
pos[0].SetVecPosition(25, 25);
pos[1].SetVecPosition(25, PITCH_WIDTH-25);
pos[2].SetVecPosition(PITCH_LENGTH-25, PITCH_WIDTH-25);
pos[3].SetVecPosition(PITCH_LENGTH-25, 25);
pos[4] = pos[0];
pos[5] = pos[2];
pos[6] = pos[3];
pos[7] = pos[1];
pos[8].SetVecPosition(25, PITCH_WIDTH/2);
pos[9].SetVecPosition(PITCH_LENGTH-25, PITCH_WIDTH/2);
pos[10] = pos[3];
pos[11].SetVecPosition(PITCH_LENGTH/2, 25);
VecPosition pRobot[5];
static int k[5] = {0, 0, 0, 0, 0};
{
pRobot[nRoundRobot].SetVecPosition(Robot[nRoundRobot+1].x, Robot[nRoundRobot+1].y);
ToPositionPD(nRoundRobot+1, pos[k[nRoundRobot]], 30);
if (k[nRoundRobot]>11)
{
rbV[nRoundRobot+1].LeftValue = 40;
rbV[nRoundRobot+1].RightValue = 36;
}
if (pRobot[nRoundRobot].GetDistanceTo(pos[k[nRoundRobot]]) < 10)
{
k[nRoundRobot]++;
}
if (k[nRoundRobot]>12) k[nRoundRobot]=0;
}
}
/////////////////// Complex Actions End ////////////////////////////////////////////////////
/////////////////// Goalie ////////////////////////////////////////////////////////////////
void CDecisionMakingx::GoalieAction(int nRobot)
{
int gtError =2 , glError = 2; // gate corner and goal corner +-
int goToken = 0; // 动作类型 最小的速度
BOOL bIsGate = FALSE; // 是否球轨迹在门区
double speed = gVMAX;
VecPosition posTarget(G_OFFSET+ROBOT_LENGTH, PITCH_WIDTH/2);
// double yBall = GetCrossPtWithGLLine();
Line lineBall(ballCharacter.Formu.b, ballCharacter.Formu.a, ballCharacter.Formu.c);
double yGate = lineBall.GetYGivenX(0); //球轨迹与球门交点
double yBall = lineBall.GetYGivenX(2*ROBOT_LENGTH+G_OFFSET);
if(m_posBall.GetX() < 9.5)
{
int y=1;
}
VecPosition posBall;
posBall = PredictBall(2);//就是简单的直线预测。没有起到预测的作用,就是处理一下X
// 球往本方而来
if((oldBallPt[4].x > oldBallPt[6].x || oldBallPt[5].x > oldBallPt[6].x)) // GG new add
{
// 交点在门区
if(yGate < PITCH_WIDTH/2 + GOAL_WIDTH/2 + 2
&& yGate > PITCH_WIDTH/2 - GOAL_WIDTH/2 - 2)
{
bIsGate = TRUE;
SendMsg(1, "bIsGate");
}
}
if(m_posBall.GetX() < 19.5)
{
posTarget.SetY(AdjustTarget());//此处是关键
}
// x方向离门很近,penalty
if(m_posBall.GetX() < GOAL_AREA_LENGTH+5)
{
SendMsg(1, "X<15");
int key;
key = dmDEG.DEPenaltyDirection;
if (key==1)
SendMsg(1, "X<15");
// 交点在门区
if(bIsGate)
{
#ifdef SimuroSot5
posTarget.SetY(yBall);
#else
posTarget.SetY(AdjustTarget());//此处是关键
#endif
goToken = 0;//最终停止
SendMsg(1, " 0 posTarget %2.2f", posTarget.GetY());
}
else
{
// 大禁区外,站在小禁区边上
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -