BehaviorAttackData::BehaviorAttackData(Agent & agent): mAgent ( agent ), mWorldState ( agent.GetWorldState() ), mBallState ( agent.GetWorldState().GetBall() ), mSelfState ( agent.Self() ), mPositionInfo ( agent.Info().GetPositionInfo()), mInterceptInfo ( agent.Info().GetInterceptInfo()), mStrategy (agent.GetStrategy()), mFormation ( agent.GetFormation() ) { mFormation.Update(Formation::Offensive, "Offensive"); }
/** * Update data used by tackle. * \param agent. */ void Tackler::UpdateTackleData(const Agent & agent) { if (mAgentID == agent.GetAgentID()) { return; /** no need to update */ } mAgentID = agent.GetAgentID(); const BallState & ball_state = agent.GetWorldState().GetBall(); const PlayerState & player_state = agent.GetSelf(); Vector ball_2_player = (ball_state.GetPos() - player_state.GetPos()).Rotate(-player_state.GetBodyDir()); Vector ball_vel; mMaxTackleSpeed = -1.0; mDirMap.clear(); const double max_tackle_power = ServerParam::instance().maxTacklePower(); const double min_back_tackle_power = ServerParam::instance().maxBackTacklePower(); double factor = 1.0 - 0.5 * (fabs(Deg2Rad(ball_2_player.Dir())) / M_PI); for (AngleDeg tackle_angle = -180.0 + FLOAT_EPS; tackle_angle <= 180.0 + FLOAT_EPS; tackle_angle += 1.0) { Vector ball_vel(ball_state.GetVel()); double eff_power = (min_back_tackle_power + ((max_tackle_power - min_back_tackle_power) * (1.0 - fabs(Deg2Rad(tackle_angle)) / M_PI))) * ServerParam::instance().tacklePowerRate(); eff_power *= factor; ball_vel += Polar2Vector(eff_power, tackle_angle + player_state.GetBodyDir()); ball_vel = ball_vel.SetLength(Min(ball_vel.Mod(), ServerParam::instance().ballSpeedMax())); int angle_idx = ang2idx(tackle_angle); int dir_idx = dir2idx(ball_vel.Dir()); mTackleAngle[angle_idx] = tackle_angle; mBallVelAfterTackle[angle_idx] = ball_vel; mDirMap[dir_idx].push_back(std::make_pair(angle_idx, ang2idx(tackle_angle + 1.0))); if (ball_vel.Mod() > mMaxTackleSpeed){ mMaxTackleSpeed = ball_vel.Mod(); } if (ball_vel.Mod() * ServerParam::instance().ballDecay() < FLOAT_EPS) { mCanTackleStopBall = true; mTackleStopBallAngle = tackle_angle; } } // // // for (AngleDeg tackle_angle = -180.0 + 0.3; tackle_angle <= 180.0 + FLOAT_EPS; tackle_angle += 1.0) { // Vector ball_vel = GetBallVelAfterTackle(agent, tackle_angle); // AngleDeg tackle_angle2 = 0.0; // GetTackleAngleToDir(agent, ball_vel.Dir(), & tackle_angle2); // // std::cout << tackle_angle << " " << tackle_angle2 << std::endl; // } // // exit(0); }
/** * Caculate the get ball cycles and actions. * @param agent the agent itself. * @param act the atomic action to execute this cycle to get the ball. * @param int_cycle the beginning cycle to do the action, while -1 means now. * @param can_inverse true means allow runnning backwards to get the ball. * @param turn_first true means the agent turn first to get the ball. * @return a double to show the cycles needed and if it less than 0, that is to say impossible. */ double Dasher::GetBall(Agent & agent, AtomicAction & act, int int_cycle , bool can_inverse, bool turn_first) { Assert(int_cycle == -1 || int_cycle >= 0); if (int_cycle == -1) { double min_diff = HUGE_VALUE; const int max_consider_cycle = Min(int(MobileState::Predictor::MAX_STEP), agent.GetStrategy().GetSureOppInterCycle() - 1); for (int i = 0; i <= max_consider_cycle; ++i) { Vector target = agent.GetWorldState().GetBall().GetPredictedPos(i); double my_cycle = RealCycleNeedToPoint(agent.GetSelf(), target, can_inverse); double diff = fabs(my_cycle - i + 1.0); if (diff < min_diff) { min_diff = diff; int_cycle = i; } } } if (int_cycle == -1) { int_cycle = Max(0, agent.GetStrategy().GetMyInterCycle()); } //int_cycle = 1; //std::cout << "Max consider cycle " << int_cycle << std::endl; //std::cout << "Predicted Ball position " << agent.GetWorldState().GetBall().GetPredictedPos(int_cycle).X() << " " << agent.GetWorldState().GetBall().GetPredictedPos(int_cycle).Y() << std::endl; //std::cout << "Ball position " << agent.GetWorldState().GetBall().GetPos().X() << " " << agent.GetWorldState().GetBall().GetPos().Y() << std::endl; GoToPoint( agent, act, agent.GetWorldState().GetBall().GetPredictedPos(int_cycle), agent.GetSelf().GetKickableArea() - GETBALL_BUFFER, agent.GetSelf().CorrectDashPowerForStamina(ServerParam::instance().maxDashPower()), can_inverse, turn_first ); return RealCycleNeedToPoint(agent.GetSelf(), agent.GetWorldState().GetBall().GetPredictedPos(int_cycle), can_inverse); }
ActionEffector::ActionEffector(Agent & agent): mAgent( agent ), mWorldState( agent.GetWorldState() ), mBallState( agent.GetWorldState().GetBall()), mSelfState( agent.GetSelf()), mTurn( agent ), mDash( agent ), mTurnNeck( agent ), mSay( agent ), mAttentionto( agent ), mKick( agent ), mTackle( agent ), mPointto( agent ), mCatch( agent ), mMove( agent ), mChangeView( agent ), mCompression( agent ), mSenseBody( agent ), mScore( agent ), mBye( agent ), mDone( agent ), mClang( agent ), mEar( agent ), mSynchSee( agent ), mChangePlayerType( agent ), mStart( agent ), mChangePlayMode( agent ), mMovePlayer( agent ), mMoveBall( agent ), mLook( agent ), mTeamNames( agent ), mRecover( agent ), mCheckBall( agent ) { mTurnCount = 0; mDashCount = 0; mTurnNeckCount = 0; mSayCount = 0; mAttentiontoCount = 0; mKickCount = 0; mTackleCount = 0; mPointtoCount = 0; mCatchCount = 0; mMoveCount = 0; mChangeViewCount = 0; mCompressionCount = 0; mSenseBodyCount = 0; mScoreCount = 0; mByeCount = 0; mDoneCount = 0; mClangCount = 0; mEarCount = 0; mSynchSeeCount = 0; mChangePlayerTypeCount = 0; mIsMutex = false; mIsTurn = false; mIsDash = false; mIsTurnNeck = false; mIsSay = false; mIsAttentionto = false; mIsKick = false; mIsTackle = false; mIsPointto = false; mIsCatch = false; mIsMove = false; mIsChangeView = false; mIsCompression = false; mIsSenseBody = false; mIsScore = false; mIsBye = false; mIsDone = false; mIsClang = false; mIsEar = false; mIsSynchSee = false; mIsChangePlayerType = false; mIsSayMissed = false; mLastCommandType = CT_None; }