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;
}



posted @ 2010-05-29 09:33  BuildNewApp  阅读(290)  评论(0编辑  收藏  举报