Example #1
0
/** 以最快的方式跑到目标点
* Run to the destination point with the fastest method.
* \param agent the agent itself.
* \param pos the destination point.
* \param buffer point buffer, means the real destinantion is a cycle with the certer 
* 		of pos and radius of buffer.
* \param power the intend power to use.
* \param can_inverse true means can run in the inverse direction of the agent's body.
* \param turn_first true means that the agent should turn first to adjust the direction.
* \return true if the action excuted successfully.
*/
bool Dasher::GoToPoint(Agent & agent, Vector pos, double buffer, double power, bool can_inverse, bool turn_first)
{
	AtomicAction act;

	GoToPoint(agent, act, agent.GetStrategy().AdjustTargetForSetplay(pos), buffer, power, can_inverse, turn_first);
	return act.Execute(agent);
}
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");
}
Example #3
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);
}