zoukankan      html  css  js  c++  java
  • deMeer5_Midfielder

    #include "Player.h"

    SoccerCommand Player::deMeer5_Midfielder()
    {
    SoccerCommand soc(CMD_ILLEGAL);
    if (WM->isBeforeKickOff())
    {
    if (formations->getFormation() != FT_INITIAL || // not in kickoff formation
    WM->getAgentGlobalPosition().getDistanceTo(WM->getStrategicPosition()) > 2.0)
    {
    formations->setFormation(FT_INITIAL); // go to kick_off formation
    soc = teleportToPos(WM->getStrategicPosition());
    }
    else // else turn to front
    {
    soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), 0);
    ACT->putCommandInQueue(turnNeckToPoint(WM->getBallPos(), soc));
    }
    }
    else if (WM->isBallInOurPossesion() && WM->getBallPos().getX()>-3)
    {
    soc = sonruoxin4attacker();
    }
    else
    {
    soc = windywinter4defender();
    }

    ACT->putCommandInQueue(soc);
    ACT->putCommandInQueue(WM->getChangeViewCommand());
    return soc;
    }

    SoccerCommand Player::windywinter4midfielder()
    {
    SoccerCommand soc(CMD_ILLEGAL);
    ObjectT ClosestTeamMateAhead = WM->getClosestAheadRelativeInSet(OBJECT_SET_TEAMMATES_NO_GOALIE);
    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()); // search for it
    }
    else if (WM->isBallKickable()) // if kickable
    {
    if (WM->getAgentGlobalPosition().getDistanceTo(WM->getPosOpponentGoal()) < 12.0 || WM->getAgentGlobalPosition().getDistanceTo(WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE)) < 3.0)
    {
    Line shoot_line_1 = Line::makeLineFromTwoPoints(WM->getBallPos(), WM->getPosOpponentGoalTop());
    Line shoot_line_2 = Line::makeLineFromTwoPoints(WM->getBallPos(), WM->getPosOpponentGoalBottom());
    double distance_1 = shoot_line_1.getDistanceWithPoint(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1));
    double distance_2 = shoot_line_2.getDistanceWithPoint(WM->predictPosAfterNrCycles(OBJECT_OPPONENT_GOALIE, 1));
    VecPosition posGoal;
    double shoot_range = max(SS->getGoalWidth() * WM->getAgentGlobalPosition().getDistanceTo(WM->getPosOpponentGoal()) / PITCH_LENGTH, 0.3);
    if (distance_1 < distance_2)
    {
    posGoal = WM->getPosOpponentGoalBottom() - shoot_range;
    }
    else
    {
    posGoal = WM->getPosOpponentGoalTop() + shoot_range;
    }
    soc = kickTo(posGoal, SS->getBallSpeedMax()); // kick maximal
    ACT->putCommandInQueue(alignNeckWithBody());
    DeadBallUsLock = false;
    }
    else if ((ClosestOpponent == OBJECT_ILLEGAL || WM->getRelativeDistance(ClosestOpponent) > 4.0 || (WM->getAgentGlobalPosition().isInFrontOf(WM->getGlobalPosition(ClosestOpponent))
    && WM->getBallPos().getDistanceTo(WM->getGlobalPosition(ClosestOpponent)) > 2.0)) && WM->getAgentStamina().getStamina() > SS->getRecoverDecThr() * SS->getStaminaMax() + 200 && !DeadBallUsLock)
    {
    soc = dribble((WM->getPosOpponentGoal() - WM->getAgentGlobalPosition()).getDirection(), 5, 15);
    ACT->putCommandInQueue(alignNeckWithBody());
    }
    else if (DeadBallUsLock && ClosestTeamMate == OBJECT_ILLEGAL)
    {
    soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle() + 60));
    ACT->putCommandInQueue(alignNeckWithBody());
    }
    else
    {
    ObjectT ReceiverFront = OBJECT_ILLEGAL;
    ObjectT ReceiverBack = OBJECT_ILLEGAL;
    int iIndex;
    double minDist = 1000.0;
    for (ObjectT o = WM->iterateObjectStart(iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE, PS->getPlayerConfThr()); o != OBJECT_ILLEGAL; o = WM->iterateObjectNext(iIndex,
    OBJECT_SET_TEAMMATES_NO_GOALIE, PS->getPlayerConfThr()))
    {
    //if (WM->isEmptySpace(WM->getAgentObjectType(), (WM->getGlobalPosition(o)-WM->getAgentGlobalPosition()).getDirection(), WM->getRelativeDistance(o)))
    if (WM->isEmptySpace(o, (WM->getAgentGlobalPosition() - WM->getGlobalPosition(o)).getDirection(), WM->getRelativeDistance(o) / 2) && WM->getGlobalPosition(o).isBehindOf(
    WM->getLastOpponentDefender()))
    {
    if (WM->getGlobalPosition(o).isInFrontOf(WM->getAgentGlobalPosition()))
    {
    ReceiverFront = o;
    break;
    }
    else
    {
    if (WM->getRelativeDistance(o) < minDist)
    {
    ReceiverBack = o;
    minDist = WM->getRelativeDistance(o);
    }
    }
    }
    }
    WM->iterateObjectDone(iIndex);
    if (ReceiverFront != OBJECT_ILLEGAL)
    {
    //soc = directPass(WM->getGlobalPosition(ReceiverFront), PASS_FAST);
    soc = throughPass(ClosestTeamMateAhead, WM->getPosOpponentGoal());
    }
    else if (ReceiverBack != OBJECT_ILLEGAL)
    {
    soc = directPass(WM->getGlobalPosition(ReceiverBack), PASS_NORMAL);
    }
    else if (DeadBallUsLock && ClosestTeamMateAhead != OBJECT_ILLEGAL)
    {
    soc = throughPass(ClosestTeamMateAhead, WM->getPosOpponentGoal());
    }
    else if (DeadBallUsLock && ClosestTeamMate != OBJECT_ILLEGAL)
    {
    soc = leadingPass(ClosestTeamMate, WM->getRelativeDistance(ClosestTeamMate)/4, WM->getCurrentCycle() % 2 == 0 ? DIR_EAST : DIR_WEST);
    }
    else
    {
    soc = outplayOpponent(ClosestOpponent, WM->getPosOpponentGoal());
    }
    ACT->putCommandInQueue(alignNeckWithBody());
    DeadBallUsLock = false;
    }
    Log.log(100, "pass ball");
    }
    else if (!WM->isBallInOurPossesion() && WM->getBallPos().getDistanceTo(WM->getPosOwnGoal()) < 25.0
    && WM->getProbTackleSucceeds() > PS->getTackleHighConfThr())
    {
    if (ClosestTeamMate != OBJECT_ILLEGAL)
    {
    soc = tackle((WM->getGlobalPosition(ClosestTeamMate) - WM->getAgentGlobalPosition()).getDirection());
    }
    else
    {
    if (fabs(WM->getAgentGlobalBodyAngle()) > 90)
    {
    soc = tackle(WM->getAgentGlobalBodyAngle() > 0 ? 90 : -90);
    }
    else
    {
    soc = tackle(WM->getAgentGlobalBodyAngle());
    }
    }
    ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
    Log.log(100, "too dangerous, tackle it");
    }
    else if ((WM->getFastestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp) == WM->getAgentObjectType()
    || WM->getFastestInSetTo(OBJECT_SET_TEAMMATES_NO_GOALIE, OBJECT_BALL, &iTmp) == WM->getAgentObjectType() && WM->isBallHeadingToGoal())
    && !WM->isDeadBallThem())
    { // if fastest to ball
    Log.log(100, "I am fastest to ball; can get there in %d cycles", iTmp);
    soc = intercept(false); // intercept the ball

    if (soc.commandType == CMD_DASH && // if stamina low
    WM->getAgentStamina().getStamina() < SS->getRecoverDecThr() * SS->getStaminaMax() + 200)
    {
    soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
    }
    ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
    }
    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());
    ACT->putCommandInQueue(turnNeckToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), soc));
    }
    else // else watch front
    {
    //soc = SoccerCommand(CMD_TURN, VecPosition::normalizeAngle(WM->getAgentGlobalBodyAngle()+60));
    //ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
    ACT->putCommandInQueue(turnNeckToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), soc));
    }
    }
    else
    {
    // nothing to do
    //ACT->putCommandInQueue(SoccerCommand(CMD_TURNNECK, VecPosition::normalizeAngle(WM->getAgentGlobalNeckAngle()+60)));
    //ACT->putCommandInQueue(turnNeckToObject(OBJECT_BALL, soc));
    soc = turnBodyToPoint(WM->getAgentGlobalPosition() + VecPosition(1, 0), 0);
    ACT->putCommandInQueue(alignNeckWithBody());
    }
    if (!DeadBallUsLock)
    {
    DeadBallUsLock = WM->isDeadBallUs() && (WM->getFastestInSetTo(OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp) == WM->getAgentObjectType());
    }
    return soc;
    }



    作者:BuildNewApp
    出处:http://syxchina.cnblogs.comBuildNewApp.com
    本文版权归作者、博客园和百度空间共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则作者会诅咒你的。
    如果您阅读了我的文章并觉得有价值请点击此处,谢谢您的肯定1。
  • 相关阅读:
    把我给另外一个朋友的炒股劝告发给你一遍,希望你可以得到帮助!
    Microsoft Office Document Imaging批量ocr 方法
    Advanced GET 9.1 修正汉化版(免注册、页面加载、保存都正常)
    波浪分析数据转换:大智慧、钱龙、胜龙可用Advanced GET ToGet 数据转换器V3.05特别版
    怎样精确计算股市主力的持仓量
    混沌理论
    地产联盟内部资料总目录
    C语言 · P1001(大数乘法)
    C语言 · 排列数
    C语言 · 逆序排列
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197409.html
Copyright © 2011-2022 走看看