deMeer5_Attacker
生活随笔
收集整理的這篇文章主要介紹了
deMeer5_Attacker
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SoccerCommand Player::deMeer5_Attacker()
{
SoccerCommand soc(CMD_ILLEGAL);
if (WM->isBeforeKickOff())
{
if (formations->getFormation() != FT_INITIAL || //不在開球的陣型
WM->getAgentGlobalPosition().getDistanceTo(WM->getStrategicPosition()) > 2.0)//返回當前球員位置
{
formations->setFormation(FT_INITIAL); // go to kick_off formation
soc = teleportToPos(WM->getStrategicPosition());//返回一個move命令將agent移到某一位置;返回一隊員的戰略位置
}
else if (WM->isKickOffUs() && WM->getPlayerNumber() == KICKOFF_TEAMMATE_NUM) //我們開球,返回開球球員號碼
{
if (WM->isBallKickable())//球可踢
{
ObjectT ClosestTeamMate_Midfielder_Wing = WM->getClosestPlayerRelativeInSet(OBJECT_SET_TEAMMATES, PT_MIDFIELDER_WING);//我方最近的邊側中衛,返回最近球員的相對位置
if (ClosestTeamMate_Midfielder_Wing == OBJECT_ILLEGAL)
{
soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle() + 60));//標準化角度(-180,180);返回當前agent身體的絕對角度
ACT->putCommandInQueue(alignNeckWithBody());//該skill使agent的脖子轉向同身體一樣的方向。該方法返回一個turn neck命令,并將身體相對于脖子的角度作為參數。
}
else
{
soc = directPass(WM->getGlobalPosition(ClosestTeamMate_Midfielder_Wing), PASS_NORMAL);//返回全局位置
//該方法使agent將球直接傳給其他隊員。參數pos表示傳球的目的位置,通常是隊友所在位置。
//參數passType表示傳球類型(PASS_NORMAL或PASS_FAST)。該方法調用kickTo將球以一個根據
//傳球類型得出的期望的末速度踢向目標位置。
}
Log.log(100, "take kick off");
}
else
{
soc = intercept(false);//false 不是守門員
//當截球方法被調用,首先判斷agent能否在兩個周期內使用closeIntercept
//(對于守門員是closeIntereptGoalie)截球。當兩個周期內不能實現時,
//則agent使用一種迭代的方案即通過方法getInterceptionPointBall計算最優截球點。
Log.log(100, "move to ball to take kick-off");
}
}
else // else turn to front
{
soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), 0);//將agent的身體轉向某一點;返回當前agent的絕對位置。
ACT->putCommandInQueue(turnNeckToPoint(WM->getBallPos(), soc));//將agent的脖子轉向某點,它接收一個場上的絕對目標點
}
}
else
{
soc = sonruoxin4attacker();
}
ACT->putCommandInQueue(soc);
ACT->putCommandInQueue(WM->getChangeViewCommand());
return soc;
}
SoccerCommand Player::sonruoxin4attacker()
{
SoccerCommand soc(CMD_ILLEGAL);
ObjectT ClosestTeamMateAhead = WM->getClosestAheadRelativeInSet(OBJECT_SET_TEAMMATES_NO_GOALIE);
ObjectT ClosestOpponentAhead = WM->getClosestAheadRelativeInSet(OBJECT_SET_OPPONENTS);
ObjectT ClosestTeamMate = WM->getClosestRelativeInSet(OBJECT_SET_TEAMMATES);
ObjectT ClosestOpponent = WM->getClosestRelativeInSet(OBJECT_SET_OPPONENTS);
static bool DeadBallUsLock = false;
int iTmp;
if (WM->getConfidence(OBJECT_BALL) < PS->getBallConfThr())// 返回該對象信息的可信度。該可信度是與上次看到這個對象以及特定的時間(一般為上次接受信息的時間)相關的。
{
soc = searchBall(); // if ball pos unknown
ACT->putCommandInQueue(alignNeckWithBody()); //使agent的脖子轉向同身體一樣的方向。該方法返回一個turn neck命令,并將身體相對于脖子的角度作為參數。
}
else if (WM->isBallKickable()) // if kickable
{
if (fabs(WM->getBallPos().getX()) > fabs(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1).getX()))
//對于直線上的點,給出y坐標求x坐標該方法預測對象o經過iCycle周期后的位置。如果對象為球,則只考慮球速的衰減。如果對象是球員,則假設球員每周期使用iDashPower進行dash。。
{
if (WM->getAgentGlobalPosition().getDistanceTo(WM->getPosOpponentGoal())>25)//返回對方球門的位置坐標
{
soc = dribble((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection(), 12);//返回當前坐標的方向。
//該方法使agent盤球(帶球)
}
else
{
soc = kickTo(WM->getPosOpponentGoal(), SS->getBallSpeedMax());
}
//cout<<WM->getCurrentCycle()<<' '<<WM->getPlayerNumber()<<" Ahead of goalie"<<endl;
}
else
{
//shoot
VecPosition ShootPoint,ShootChioce;
VecPosition posAgent = WM->getAgentGlobalPosition();
VecPosition posGoalKeeper= WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
double shoot_value=-100,value;
double shoot_range = max(SS->getGoalWidth() * WM->getAgentGlobalPosition().getDistanceTo(
WM->getPosOpponentGoal()) / PITCH_LENGTH, 0.3);//場地長度
for(ShootPoint=VecPosition(PITCH_LENGTH/2,WM->getPosOpponentGoalTop().getY()+shoot_range);//(52.5,7.62)
ShootPoint.getY()<=WM->getPosOpponentGoalBottom().getY() - shoot_range;//-7.62
ShootPoint.setY(ShootPoint.getY()+0.3))
{
if ((value=getshootprofit(ShootPoint))>shoot_value)
{
shoot_value=value;
ShootChioce=ShootPoint;
}
}
Log.log(100,"shoot_value is %lf",shoot_value);
Log.log(100,"VecPosition.y is %lf",ShootChioce.getY());
if (( (shoot_value>26&&WM->getBallPos().getDistanceTo(posGoalKeeper)<14)
||(WM->getConfidence(OBJECT_OPPONENT_GOALIE)<0.95&&WM->getBallPos().getX()>35&&fabs(WM->getBallPos().getY())<20)
||WM->getBallPos().getDistanceTo(posGoalKeeper)<7)
&&!WM->isIndirectFreeKickUs())///我們是否有個free kick
{
soc=kickTo(ShootChioce,SS->getBallSpeedMax());
ACT->putCommandInQueue(alignNeckWithBody());
DeadBallUsLock = false;
Log.log(100, " shoot");
}
else
if (WM->isDeadBallUs() && WM->getConfidence(ClosestTeamMate) < 0.98)
{
Log.log(100, " our dead ball, search for teammate");
soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle() + 60));
ACT->putCommandInQueue(alignNeckWithBody());
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NORMAL, VQ_HIGH));
}
else
{
double disToOpp=WM->getAgentGlobalPosition().getDistanceTo(WM->getGlobalPosition(ClosestOpponentAhead));
if ((ClosestOpponentAhead==OBJECT_ILLEGAL || disToOpp>11) && !WM->isDeadBallUs()&&WM->getAgentStamina().getStamina()>2500)
{
Log.log(100,"dribble very fast 8 ");
double length;
if (fabs(WM->getBallPos().getX())<5)
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
}
else soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),8);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else if (disToOpp>9 && !WM->isDeadBallUs()&&WM->getAgentStamina().getStamina()>2000)
{
Log.log(100,"dribble fast 7");
if (fabs(WM->getBallPos().getX())<5)
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
}
else soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),7);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else if (disToOpp>6 && !WM->isDeadBallUs())
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
Log.log(100,"dribble 5");
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else
{
//pass
if (!WM->isDeadBallUs())
{ soc=getBestPassCmd_Attacker();
if (soc.commandType == CMD_ILLEGAL) soc = getSecondPassCmd_Attacker(8);
}
else
{
if ((ClosestTeamMate!=OBJECT_ILLEGAL)&&(WM->getAgentGlobalPosition().getDistanceTo(ClosestTeamMate)<10)) soc=directPass(ClosestTeamMate,PASS_NORMAL);
}
if (soc.commandType != CMD_ILLEGAL)
{
// prevent too smart kick
if (WM->isDeadBallUs() && soc.dPower < 30.0) soc.dPower = 50.0;
ACT->putCommandInQueue(lookaround(soc));
}
else if ( // if stamina low
WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 600)
{
if (WM->getBallPos().getX()<36&&ClosestTeamMate!=OBJECT_ILLEGAL&&WM->isOnside(ClosestTeamMate)&&WM->getConfidence(ClosestTeamMate)>0.95)
{
if (WM->getGlobalPosition(ClosestTeamMate).getY()>0)
soc= throughPass(ClosestTeamMate,VecPosition(52.5,6));
else
soc= throughPass(ClosestTeamMate,VecPosition(52.5,-6));
Log.log(100,"through pass");
}
else
{
VecPosition posOpGK=WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
if (posOpGK.getX()>0) soc=kickTo(VecPosition(52.5,-6),SS->getBallSpeedMax());
else soc=kickTo(VecPosition(52.5,6),SS->getBallSpeedMax());
}
}
else if (!WM->isDeadBallUs())
{
if (disToOpp>2)
{
double angOpp=VecPosition::normalizeAngle(WM->getGlobalBodyAngle(ClosestOpponentAhead));
double outPlayAng;
if ((angOpp>=0)&&(angOpp<180)) outPlayAng=fabs(VecPosition::normalizeAngle(angOpp+45));
else outPlayAng=fabs(VecPosition::normalizeAngle(angOpp-45));
soc=dribble(outPlayAng,5);
Log.log(100,"dangerous outPlayAng is %lf ",outPlayAng);
}
/*else if (disToOpp>2)
{
double angOpp=VecPosition::normalizeAngle(WM->getGlobalBodyAngle(ClosestOpponentAhead));
double outPlayAng;
if ((angOpp>=0)&&(angOpp<180)) outPlayAng=angOpp+45;
else outPlayAng=angOpp-45;
VecPosition PosTo=WM->getAgentGlobalPosition()+VecPosition(3,outPlayAng,POLAR),*ballpos;
soc=outplayOpponent(ClosestOpponentAhead,PosTo,ballpos);
Log.log(100,"outplay");
}*/
else
{
soc=holdBall();
Log.log(100,"hold ball");
}
//soc=getBestDribbleCmd_Attacker(-100);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
}
}
else if (WM->getBallPos().getDistanceTo(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1)) <= SS->getTackleDist()+1 && WM->getProbTackleSucceeds() > PS->getTackleConfThr() )
{
soc = tackle((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection());
}
// if we get a dead ball, and it's not in our penalty area (if is, the goalie will take it sooner or later)
// if this player is closest to the ball, he will go to take the ball
else if (WM->isDeadBallUs()
&& WM->getClosestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL) == WM->getAgentObjectType())
{
Log.log(100, " go to take dead ball");
// if not in position, move to position
if (WM->getRelativeDistance(OBJECT_BALL) >= SS->getMaximalKickDist())
{
soc = moveToPos(getDeadBallPosition(), 5); // move to take dead ball
// if stamina low, dash slowly
if (soc.commandType == CMD_DASH && WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
Log.log(100, " but stamina is too low");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
}
ACT->putCommandInQueue(lookaround(soc));
}
// else wait till kickable signal
else
{
soc = turnBodyToPoint(WM->getPosOpponentGoal());
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
// if this player is 2nd closest to the ball, he will go to back up the 1st one
else if (WM->isDeadBallUs() && !WM->isBallInOwnPenaltyArea()
&& WM->getSecondClosestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL) == WM->getAgentObjectType())
{
Log.log(100, " go to backup dead ball");
// if not in position, move to position
if (WM->getRelativeDistance(OBJECT_BALL) >= 6.0)
{
soc = moveToPos(getDeadBallBackUpPosition(), 5); // move to take dead ball
// if stamina low, dash slowly
if (soc.commandType == CMD_DASH && WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
Log.log(100, " but stamina is too low");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
}
ACT->putCommandInQueue(lookaround(soc));
}
// else wait till kickable signal
else
{
soc = turnBodyToPoint(WM->getGlobalPosition(OBJECT_BALL));
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else
{ // if fastest to ball
int cycles_fastest_to_ball, cycles_intercept;
ObjectT obj_fastest_to_ball = WM->getFastestInSetTo(OBJECT_SET_TEAMMATES_NO_GOALIE, OBJECT_BALL, &cycles_fastest_to_ball);
WM->predictCommandToInterceptBall(WM->getAgentObjectType(), interceptClose(), &cycles_intercept);
// if fastest to ball, intercept it
if (( obj_fastest_to_ball == WM->getAgentObjectType() || cycles_intercept<=cycles_fastest_to_ball+1 )
&& !WM->isDeadBallThem() && !WM->isDeadBallUs())
{
Log.log(100, " fastest to ball; can get there in %d cycles", cycles_intercept);
soc = intercept(false);
if (soc.commandType == CMD_DASH && // if stamina low
WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 200)
{
Log.log(100, " I will be slow");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
}
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else if (WM->getAgentGlobalPosition().getDistanceTo(WM->getStrategicPosition()) > 1.5 + fabs(WM->getAgentGlobalPosition().getX() - WM->getBallPos().getX()) / 10.0 )
// if not near strategic pos
{
if (WM->getAgentStamina().getStamina() > // if stamina high
SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
soc = moveToPos(WM->getStrategicPosition(), PS->getPlayerWhenToTurnAngle());
if(WM->isInTheirPenaltyArea(WM->getBallPos())
soc=kickTo(WM->getPosOpponentGoal(),SS->getBallSpeedMax());
else
soc = dribble((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection(),DRIBBLE_FAST);
}
else // else watch front
{
soc = turnBodyToPoint(WM->getStrategicPosition());
}
if (WM->isDeadBallUs())
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else
{
Log.log(100, " nothing to do but watching ball or looking around");
if (WM->isDeadBallUs())
{
soc = turnBodyToPoint(WM->getBallPos());
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(100, 0), 0);
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
}
return soc;
}
//***************************************************************************88
double BasicPlayer::getShootProfit(VecPosition ShootPoint)
{
double value=10,dis=0,n2=0,n3=0;
int iIndex,num=0,n1=0,n4=0,nall=0;
double dis_OP[10]={0};
Line shoot_line = Line::makeLineFromTwoPoints(WM->getBallPos(),ShootPoint);
double dis_GK=shoot_line.getDistanceWithPoint(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1));
double dis_GK_Ball=WM->getBallPos().getDistanceTo(WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE));
if (dis_GK>4.0) n2=32.0;
else n2=8*dis_GK;
if (dis_GK_Ball>20) n3=-8;
else n3=-0.4*dis_GK_Ball;
for (ObjectT o = WM->iterateObjectStart(iIndex, OBJECT_SET_OPPONENTS , PS->getPlayerConfThr());
o != OBJECT_ILLEGAL;
o = WM->iterateObjectNext(iIndex, OBJECT_SET_OPPONENTS , PS->getPlayerConfThr()))
if (dis=shoot_line.getDistanceWithPoint(WM->predictPosAfterNrCycles(o, 1))<3
&& !WM->getAgentGlobalPosition().isInFrontOf(o)&& o!=OBJECT_OPPONENT_GOALIE )
{
num++;
n1=0;
if (dis>2) n1=n1+2;
else if (dis>1) n1=n1+1;
else n1=n1-2;
dis_OP[num]=dis;
nall+=n1;
}
/*if (num==0) value=n2+n3+5;
else {
if (nall>=0) value=n2+n3+nall/num;
else value=n2+n3+nall/num;
}*/
value=n2+n3;
return value;
}
/******************************/
SoccerCommand BasicPlayer::getBestPassCmd_Attacker()
{
//return SoccerCommand(CMD_ILLEGAL);
return getBestPassCmd_Defender();
}
{
SoccerCommand soc(CMD_ILLEGAL);
if (WM->isBeforeKickOff())
{
if (formations->getFormation() != FT_INITIAL || //不在開球的陣型
WM->getAgentGlobalPosition().getDistanceTo(WM->getStrategicPosition()) > 2.0)//返回當前球員位置
{
formations->setFormation(FT_INITIAL); // go to kick_off formation
soc = teleportToPos(WM->getStrategicPosition());//返回一個move命令將agent移到某一位置;返回一隊員的戰略位置
}
else if (WM->isKickOffUs() && WM->getPlayerNumber() == KICKOFF_TEAMMATE_NUM) //我們開球,返回開球球員號碼
{
if (WM->isBallKickable())//球可踢
{
ObjectT ClosestTeamMate_Midfielder_Wing = WM->getClosestPlayerRelativeInSet(OBJECT_SET_TEAMMATES, PT_MIDFIELDER_WING);//我方最近的邊側中衛,返回最近球員的相對位置
if (ClosestTeamMate_Midfielder_Wing == OBJECT_ILLEGAL)
{
soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle() + 60));//標準化角度(-180,180);返回當前agent身體的絕對角度
ACT->putCommandInQueue(alignNeckWithBody());//該skill使agent的脖子轉向同身體一樣的方向。該方法返回一個turn neck命令,并將身體相對于脖子的角度作為參數。
}
else
{
soc = directPass(WM->getGlobalPosition(ClosestTeamMate_Midfielder_Wing), PASS_NORMAL);//返回全局位置
//該方法使agent將球直接傳給其他隊員。參數pos表示傳球的目的位置,通常是隊友所在位置。
//參數passType表示傳球類型(PASS_NORMAL或PASS_FAST)。該方法調用kickTo將球以一個根據
//傳球類型得出的期望的末速度踢向目標位置。
}
Log.log(100, "take kick off");
}
else
{
soc = intercept(false);//false 不是守門員
//當截球方法被調用,首先判斷agent能否在兩個周期內使用closeIntercept
//(對于守門員是closeIntereptGoalie)截球。當兩個周期內不能實現時,
//則agent使用一種迭代的方案即通過方法getInterceptionPointBall計算最優截球點。
Log.log(100, "move to ball to take kick-off");
}
}
else // else turn to front
{
soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), 0);//將agent的身體轉向某一點;返回當前agent的絕對位置。
ACT->putCommandInQueue(turnNeckToPoint(WM->getBallPos(), soc));//將agent的脖子轉向某點,它接收一個場上的絕對目標點
}
}
else
{
soc = sonruoxin4attacker();
}
ACT->putCommandInQueue(soc);
ACT->putCommandInQueue(WM->getChangeViewCommand());
return soc;
}
SoccerCommand Player::sonruoxin4attacker()
{
SoccerCommand soc(CMD_ILLEGAL);
ObjectT ClosestTeamMateAhead = WM->getClosestAheadRelativeInSet(OBJECT_SET_TEAMMATES_NO_GOALIE);
ObjectT ClosestOpponentAhead = WM->getClosestAheadRelativeInSet(OBJECT_SET_OPPONENTS);
ObjectT ClosestTeamMate = WM->getClosestRelativeInSet(OBJECT_SET_TEAMMATES);
ObjectT ClosestOpponent = WM->getClosestRelativeInSet(OBJECT_SET_OPPONENTS);
static bool DeadBallUsLock = false;
int iTmp;
if (WM->getConfidence(OBJECT_BALL) < PS->getBallConfThr())// 返回該對象信息的可信度。該可信度是與上次看到這個對象以及特定的時間(一般為上次接受信息的時間)相關的。
{
soc = searchBall(); // if ball pos unknown
ACT->putCommandInQueue(alignNeckWithBody()); //使agent的脖子轉向同身體一樣的方向。該方法返回一個turn neck命令,并將身體相對于脖子的角度作為參數。
}
else if (WM->isBallKickable()) // if kickable
{
if (fabs(WM->getBallPos().getX()) > fabs(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1).getX()))
//對于直線上的點,給出y坐標求x坐標該方法預測對象o經過iCycle周期后的位置。如果對象為球,則只考慮球速的衰減。如果對象是球員,則假設球員每周期使用iDashPower進行dash。。
{
if (WM->getAgentGlobalPosition().getDistanceTo(WM->getPosOpponentGoal())>25)//返回對方球門的位置坐標
{
soc = dribble((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection(), 12);//返回當前坐標的方向。
//該方法使agent盤球(帶球)
}
else
{
soc = kickTo(WM->getPosOpponentGoal(), SS->getBallSpeedMax());
}
//cout<<WM->getCurrentCycle()<<' '<<WM->getPlayerNumber()<<" Ahead of goalie"<<endl;
}
else
{
//shoot
VecPosition ShootPoint,ShootChioce;
VecPosition posAgent = WM->getAgentGlobalPosition();
VecPosition posGoalKeeper= WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
double shoot_value=-100,value;
double shoot_range = max(SS->getGoalWidth() * WM->getAgentGlobalPosition().getDistanceTo(
WM->getPosOpponentGoal()) / PITCH_LENGTH, 0.3);//場地長度
for(ShootPoint=VecPosition(PITCH_LENGTH/2,WM->getPosOpponentGoalTop().getY()+shoot_range);//(52.5,7.62)
ShootPoint.getY()<=WM->getPosOpponentGoalBottom().getY() - shoot_range;//-7.62
ShootPoint.setY(ShootPoint.getY()+0.3))
{
if ((value=getshootprofit(ShootPoint))>shoot_value)
{
shoot_value=value;
ShootChioce=ShootPoint;
}
}
Log.log(100,"shoot_value is %lf",shoot_value);
Log.log(100,"VecPosition.y is %lf",ShootChioce.getY());
if (( (shoot_value>26&&WM->getBallPos().getDistanceTo(posGoalKeeper)<14)
||(WM->getConfidence(OBJECT_OPPONENT_GOALIE)<0.95&&WM->getBallPos().getX()>35&&fabs(WM->getBallPos().getY())<20)
||WM->getBallPos().getDistanceTo(posGoalKeeper)<7)
&&!WM->isIndirectFreeKickUs())///我們是否有個free kick
{
soc=kickTo(ShootChioce,SS->getBallSpeedMax());
ACT->putCommandInQueue(alignNeckWithBody());
DeadBallUsLock = false;
Log.log(100, " shoot");
}
else
if (WM->isDeadBallUs() && WM->getConfidence(ClosestTeamMate) < 0.98)
{
Log.log(100, " our dead ball, search for teammate");
soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle() + 60));
ACT->putCommandInQueue(alignNeckWithBody());
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NORMAL, VQ_HIGH));
}
else
{
double disToOpp=WM->getAgentGlobalPosition().getDistanceTo(WM->getGlobalPosition(ClosestOpponentAhead));
if ((ClosestOpponentAhead==OBJECT_ILLEGAL || disToOpp>11) && !WM->isDeadBallUs()&&WM->getAgentStamina().getStamina()>2500)
{
Log.log(100,"dribble very fast 8 ");
double length;
if (fabs(WM->getBallPos().getX())<5)
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
}
else soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),8);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else if (disToOpp>9 && !WM->isDeadBallUs()&&WM->getAgentStamina().getStamina()>2000)
{
Log.log(100,"dribble fast 7");
if (fabs(WM->getBallPos().getX())<5)
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
}
else soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),7);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else if (disToOpp>6 && !WM->isDeadBallUs())
{
soc=dribble((WM->getPosOpponentGoal()-WM->getBallPos()).getDirection(),5);
Log.log(100,"dribble 5");
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
else
{
//pass
if (!WM->isDeadBallUs())
{ soc=getBestPassCmd_Attacker();
if (soc.commandType == CMD_ILLEGAL) soc = getSecondPassCmd_Attacker(8);
}
else
{
if ((ClosestTeamMate!=OBJECT_ILLEGAL)&&(WM->getAgentGlobalPosition().getDistanceTo(ClosestTeamMate)<10)) soc=directPass(ClosestTeamMate,PASS_NORMAL);
}
if (soc.commandType != CMD_ILLEGAL)
{
// prevent too smart kick
if (WM->isDeadBallUs() && soc.dPower < 30.0) soc.dPower = 50.0;
ACT->putCommandInQueue(lookaround(soc));
}
else if ( // if stamina low
WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 600)
{
if (WM->getBallPos().getX()<36&&ClosestTeamMate!=OBJECT_ILLEGAL&&WM->isOnside(ClosestTeamMate)&&WM->getConfidence(ClosestTeamMate)>0.95)
{
if (WM->getGlobalPosition(ClosestTeamMate).getY()>0)
soc= throughPass(ClosestTeamMate,VecPosition(52.5,6));
else
soc= throughPass(ClosestTeamMate,VecPosition(52.5,-6));
Log.log(100,"through pass");
}
else
{
VecPosition posOpGK=WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
if (posOpGK.getX()>0) soc=kickTo(VecPosition(52.5,-6),SS->getBallSpeedMax());
else soc=kickTo(VecPosition(52.5,6),SS->getBallSpeedMax());
}
}
else if (!WM->isDeadBallUs())
{
if (disToOpp>2)
{
double angOpp=VecPosition::normalizeAngle(WM->getGlobalBodyAngle(ClosestOpponentAhead));
double outPlayAng;
if ((angOpp>=0)&&(angOpp<180)) outPlayAng=fabs(VecPosition::normalizeAngle(angOpp+45));
else outPlayAng=fabs(VecPosition::normalizeAngle(angOpp-45));
soc=dribble(outPlayAng,5);
Log.log(100,"dangerous outPlayAng is %lf ",outPlayAng);
}
/*else if (disToOpp>2)
{
double angOpp=VecPosition::normalizeAngle(WM->getGlobalBodyAngle(ClosestOpponentAhead));
double outPlayAng;
if ((angOpp>=0)&&(angOpp<180)) outPlayAng=angOpp+45;
else outPlayAng=angOpp-45;
VecPosition PosTo=WM->getAgentGlobalPosition()+VecPosition(3,outPlayAng,POLAR),*ballpos;
soc=outplayOpponent(ClosestOpponentAhead,PosTo,ballpos);
Log.log(100,"outplay");
}*/
else
{
soc=holdBall();
Log.log(100,"hold ball");
}
//soc=getBestDribbleCmd_Attacker(-100);
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
}
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
}
}
else if (WM->getBallPos().getDistanceTo(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1)) <= SS->getTackleDist()+1 && WM->getProbTackleSucceeds() > PS->getTackleConfThr() )
{
soc = tackle((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection());
}
// if we get a dead ball, and it's not in our penalty area (if is, the goalie will take it sooner or later)
// if this player is closest to the ball, he will go to take the ball
else if (WM->isDeadBallUs()
&& WM->getClosestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL) == WM->getAgentObjectType())
{
Log.log(100, " go to take dead ball");
// if not in position, move to position
if (WM->getRelativeDistance(OBJECT_BALL) >= SS->getMaximalKickDist())
{
soc = moveToPos(getDeadBallPosition(), 5); // move to take dead ball
// if stamina low, dash slowly
if (soc.commandType == CMD_DASH && WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
Log.log(100, " but stamina is too low");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
}
ACT->putCommandInQueue(lookaround(soc));
}
// else wait till kickable signal
else
{
soc = turnBodyToPoint(WM->getPosOpponentGoal());
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
// if this player is 2nd closest to the ball, he will go to back up the 1st one
else if (WM->isDeadBallUs() && !WM->isBallInOwnPenaltyArea()
&& WM->getSecondClosestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL) == WM->getAgentObjectType())
{
Log.log(100, " go to backup dead ball");
// if not in position, move to position
if (WM->getRelativeDistance(OBJECT_BALL) >= 6.0)
{
soc = moveToPos(getDeadBallBackUpPosition(), 5); // move to take dead ball
// if stamina low, dash slowly
if (soc.commandType == CMD_DASH && WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
Log.log(100, " but stamina is too low");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
}
ACT->putCommandInQueue(lookaround(soc));
}
// else wait till kickable signal
else
{
soc = turnBodyToPoint(WM->getGlobalPosition(OBJECT_BALL));
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else
{ // if fastest to ball
int cycles_fastest_to_ball, cycles_intercept;
ObjectT obj_fastest_to_ball = WM->getFastestInSetTo(OBJECT_SET_TEAMMATES_NO_GOALIE, OBJECT_BALL, &cycles_fastest_to_ball);
WM->predictCommandToInterceptBall(WM->getAgentObjectType(), interceptClose(), &cycles_intercept);
// if fastest to ball, intercept it
if (( obj_fastest_to_ball == WM->getAgentObjectType() || cycles_intercept<=cycles_fastest_to_ball+1 )
&& !WM->isDeadBallThem() && !WM->isDeadBallUs())
{
Log.log(100, " fastest to ball; can get there in %d cycles", cycles_intercept);
soc = intercept(false);
if (soc.commandType == CMD_DASH && // if stamina low
WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 200)
{
Log.log(100, " I will be slow");
soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
}
if (WM->getBallPos().getX()<40&&fabs(WM->getBallPos().getY())<20)
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else if (WM->getAgentGlobalPosition().getDistanceTo(WM->getStrategicPosition()) > 1.5 + fabs(WM->getAgentGlobalPosition().getX() - WM->getBallPos().getX()) / 10.0 )
// if not near strategic pos
{
if (WM->getAgentStamina().getStamina() > // if stamina high
SS->getRecoverDecThr() * SS->getStaminaMax() + 800)
{
soc = moveToPos(WM->getStrategicPosition(), PS->getPlayerWhenToTurnAngle());
if(WM->isInTheirPenaltyArea(WM->getBallPos())
soc=kickTo(WM->getPosOpponentGoal(),SS->getBallSpeedMax());
else
soc = dribble((WM->getPosOpponentGoal()-WM->getAgentGlobalPosition()).getDirection(),DRIBBLE_FAST);
}
else // else watch front
{
soc = turnBodyToPoint(WM->getStrategicPosition());
}
if (WM->isDeadBallUs())
{
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
else
{
Log.log(100, " nothing to do but watching ball or looking around");
if (WM->isDeadBallUs())
{
soc = turnBodyToPoint(WM->getBallPos());
ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
}
else
{
soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(100, 0), 0);
ACT->putCommandInQueue(lookaround(soc));
}
WM->setChangeViewCommand(SoccerCommand(CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH));
}
}
return soc;
}
//***************************************************************************88
double BasicPlayer::getShootProfit(VecPosition ShootPoint)
{
double value=10,dis=0,n2=0,n3=0;
int iIndex,num=0,n1=0,n4=0,nall=0;
double dis_OP[10]={0};
Line shoot_line = Line::makeLineFromTwoPoints(WM->getBallPos(),ShootPoint);
double dis_GK=shoot_line.getDistanceWithPoint(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1));
double dis_GK_Ball=WM->getBallPos().getDistanceTo(WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE));
if (dis_GK>4.0) n2=32.0;
else n2=8*dis_GK;
if (dis_GK_Ball>20) n3=-8;
else n3=-0.4*dis_GK_Ball;
for (ObjectT o = WM->iterateObjectStart(iIndex, OBJECT_SET_OPPONENTS , PS->getPlayerConfThr());
o != OBJECT_ILLEGAL;
o = WM->iterateObjectNext(iIndex, OBJECT_SET_OPPONENTS , PS->getPlayerConfThr()))
if (dis=shoot_line.getDistanceWithPoint(WM->predictPosAfterNrCycles(o, 1))<3
&& !WM->getAgentGlobalPosition().isInFrontOf(o)&& o!=OBJECT_OPPONENT_GOALIE )
{
num++;
n1=0;
if (dis>2) n1=n1+2;
else if (dis>1) n1=n1+1;
else n1=n1-2;
dis_OP[num]=dis;
nall+=n1;
}
/*if (num==0) value=n2+n3+5;
else {
if (nall>=0) value=n2+n3+nall/num;
else value=n2+n3+nall/num;
}*/
value=n2+n3;
return value;
}
/******************************/
SoccerCommand BasicPlayer::getBestPassCmd_Attacker()
{
//return SoccerCommand(CMD_ILLEGAL);
return getBestPassCmd_Defender();
}
轉載于:https://www.cnblogs.com/syxchina/archive/2010/05/29/2197411.html
總結
以上是生活随笔為你收集整理的deMeer5_Attacker的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转] 做个自强不息的青年
- 下一篇: U盘专杀工具,U盘防御软件,U盘病毒防火