zoukankan      html  css  js  c++  java
  • 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();
    }



    作者:BuildNewApp
    出处:http://syxchina.cnblogs.comBuildNewApp.com
    本文版权归作者、博客园和百度空间共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则作者会诅咒你的。
    如果您阅读了我的文章并觉得有价值请点击此处,谢谢您的肯定1。
  • 相关阅读:
    4-vim-工作模式-01-职责以及切换模式
    3-vim-打开和新建文件-02-删除交换文件
    poj1011Stick(dfs+剪枝)
    POJ 1251 Jungle Roads (prim)
    poj 2502 Subway
    poj 3624 Charm Bracelet (01背包)
    拦截导弹问题(动态规划)
    Policy Gradient
    深入了解马尔科夫决策过程(Markov Decision Process)
    深度学习中调参对模型容量的影响
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197411.html
Copyright © 2011-2022 走看看