📄 player.cpp
字号:
obj != WM->getAgentObjectType() )
return false;
// in the defense, player 6 keeps track of the opponent attacker
if( WM->getBallPos().getX() < - PENALTY_X + 4.0 &&
WM->getConfidence( OBJECT_BALL ) > 0.96 &&
WM->getPlayerNumber() == 6 &&
WM->getCurrentCycle() % 3 == 0 ) // once very 3 cycles is enough
{
Log.log( 600, "player 6 is going to communicate attacker info" );
return true;
}
VecPosition posBallPred;
WM->predictBallInfoAfterCommand( socPri, &posBallPred );
VecPosition posAgentPred = WM->predictAgentPosAfterCommand( socPri );
// in all other cases inform teammates of ball when you have good information
if( ( WM->getTimeChangeInformation(OBJECT_BALL) == WM->getCurrentTime() &&
WM->getRelativeDistance( OBJECT_BALL ) < 20.0 &&
WM->getTimeLastSeen( OBJECT_BALL ) == WM->getCurrentTime() )
||
(
WM->getRelativeDistance( OBJECT_BALL ) < SS->getVisibleDistance() &&
WM->getTimeLastSeen( OBJECT_BALL ) == WM->getCurrentTime()
)
||
( // pass ball
WM->getRelativeDistance( OBJECT_BALL ) < SS->getMaximalKickDist() &&
posBallPred.getDistanceTo( posAgentPred ) > SS->getMaximalKickDist()
)
)
return true;
return false;
}
/*! This method encodes the opponent attacker status in a visual message.
\return string in which the opponent attacker position is encoded.*/
void Player::sayOppAttackerStatus( char* strMsg )
{
char strTmp[MAX_SAY_MSG];
// fill the first byte with some encoding to indicate the current cycle.
// The second byte is the last digit of the cycle added to 'a'.
sprintf( strMsg, "%c", 'a' + WM->getCurrentCycle()%10 );
// fill the second byte with information about the offside line.
// Enter either a value between a-z or A-Z indicating. This gives 52 possible
// values which correspond with meters on the field. So B means the offside
// line lies at 27.0.
int iOffside = (int)WM->getOffsideX();
if( iOffside < 26 ) // 0..25
sprintf( strTmp, "%c", 'a' + iOffside );
else // 26...
sprintf( strTmp, "%c", 'A' + max(iOffside - 26, 25) );
strcat( strMsg, strTmp );
// find the closest opponent attacker to the penalty spot.
double dDist ;
ObjectT objOpp = WM->getClosestInSetTo( OBJECT_SET_OPPONENTS,
VecPosition(- PITCH_LENGTH/2.0 + 11.0, 0 ), &dDist ) ;
if( objOpp == OBJECT_ILLEGAL || dDist >= 20.0 )
{
strncpy( strMsg, "", 0 );
return;
}
VecPosition posOpp = WM->getGlobalPosition( objOpp );
if( fabs( posOpp.getY() ) > 10 )
{
strncpy( strMsg, "", 0 );
return;
}
// encode the position of this attacker in the visual message. The
// player_number is the third byte, then comes the x position in 3 digits (it
// is assumed this value is always negative), a space and finally the y
// position in 2 digits. An example of opponent nr. 9 at position
// (-40.3223,-3.332) is "j403 -33)
sprintf( strTmp, "%c%d %d", 'a' + SoccerTypes::getIndex( objOpp ) ,
(int)(fabs(posOpp.getX())*10),
(int)(posOpp.getY()*10));
strcat( strMsg, strTmp );
return ;
}
/*! This method creates a string to communicate the ball status. When
the player just kicks the ball, it is the new velocity of the
ball, otherwise it is the current velocity.
\param strMsg will be filled */
void Player::sayBallStatus( char * strMsg )
{
VecPosition posBall = WM->getGlobalPosition( OBJECT_BALL );
VecPosition velBall = WM->getGlobalVelocity( OBJECT_BALL );
int iDiff = 0;
SoccerCommand soc = ACT->getPrimaryCommand();
if( WM->getRelativeDistance( OBJECT_BALL ) < SS->getMaximalKickDist() )
{
// if kick and a pass
if( soc.commandType == CMD_KICK )
{
WM->predictBallInfoAfterCommand( soc, &posBall, &velBall );
VecPosition posAgent = WM->predictAgentPos( 1, 0 );
if( posBall.getDistanceTo( posAgent ) > SS->getMaximalKickDist() + 0.2 )
iDiff = 1;
}
if( iDiff == 0 )
{
posBall = WM->getGlobalPosition( OBJECT_BALL );
velBall.setVecPosition( 0, 0 );
}
}
Log.log( 600, "create comm. ball after: (%1.2f,%1.2f)(%1.2f,%1.2f) diff %d",
posBall.getX(), posBall.getY(), velBall.getX(), velBall.getY(), iDiff);
makeBallInfo( posBall, velBall, iDiff, strMsg );
}
/*! This method is used to create the communicate message for the
status of the ball, that is its position and velocity is encoded.
\param VecPosition posBall ball position
\param VecPosition velBall ball velocity
\param iDiff time difference corresponding to given ball information
\strMsg string message in which the ball information is encoded. */
void Player::makeBallInfo( VecPosition posBall, VecPosition velBall, int iDiff,
char * strMsg )
{
char strTmp[MAX_SAY_MSG];
// fill the first byte with some encoding to indicate the next cycle.
// The second byte is the last digit of the cycle added to 'a'.
sprintf( strMsg, "%c", 'a' + (WM->getCurrentCycle()+iDiff)%10 );
// fill the second byte with information about the offside line.
// Enter either a value between a-z or A-Z indicating. This gives 52 possible
// values which correspond with meters on the field. So B means the offside
// line lies at 27.0.
int iOffside = (int)( WM->getOffsideX( false ) - 1.0 );
if( iOffside < 26 ) // 0..25
sprintf( strTmp, "%c", 'a' + max( 0, iOffside) );
else // 26...
sprintf( strTmp, "%c", 'A' + min(iOffside - 26, 25) );
strcat( strMsg, strTmp );
// First add al values to a positive interval, since then we don't need
// another byte for the minus sign. then take one digit at a time
double x = max(0,min( rint( posBall.getX() + 48.0), 99.0));
sprintf( strTmp, "%c%c%c%c%c%c%c%c",
'0' + ((int)( x ) % 100 ) / 10 ,
'0' + ((int)( x ) % 100 ) % 10 ,
'0' + ((int)( rint(posBall.getY() + 34.0)) % 100 ) / 10 ,
'0' + ((int)( rint(posBall.getY() + 34.0)) % 100 ) % 10 ,
'0' + ((int)(( velBall.getX() + 2.7) * 10 )) / 10 ,
'0' + ((int)(( velBall.getX() + 2.7) * 10 )) % 10 ,
'0' + ((int)(( velBall.getY() + 2.7) * 10 )) / 10 ,
'0' + ((int)(( velBall.getY() + 2.7) * 10 )) % 10 );
strcat( strMsg, strTmp );
Log.log( 6560, "say (%d) %s\n", WM->getPlayerNumber() , strMsg );
return ;
}
/*! This method is called when a penalty kick has to be taken (for both the
goalkeeper as the player who has to take the penalty. */
void Player::performPenalty( )
{
VecPosition pos;
int iSide = ( WM->getSide() == WM->getSidePenalty() ) ? -1 : 1;
VecPosition posPenalty( iSide*(52.5 - SS->getPenDistX()), 0.0 );
VecPosition posAgent = WM->getAgentGlobalPosition();
AngDeg angBody = WM->getAgentGlobalBodyAngle();
SoccerCommand soc(CMD_ILLEGAL);
static PlayModeT pmPrev = PM_ILLEGAL;
// raise number of penalties by one when a penalty is taken
if(
( WM->getSide() == SIDE_LEFT &&
pmPrev != PM_PENALTY_SETUP_LEFT &&
WM->getPlayMode() == PM_PENALTY_SETUP_LEFT )
||
( WM->getSide() == SIDE_RIGHT &&
pmPrev != PM_PENALTY_SETUP_RIGHT &&
WM->getPlayMode() == PM_PENALTY_SETUP_RIGHT ) )
m_iPenaltyNr++;
// start with player 11 and go downwards with each new penalty
// if we take penalty
if( WM->isPenaltyUs() && WM->getPlayerNumber() == (11 - (m_iPenaltyNr % 11)))
{
if( WM->getPlayMode() == PM_PENALTY_SETUP_LEFT ||
WM->getPlayMode() == PM_PENALTY_SETUP_RIGHT )
{
pos = posPenalty - VecPosition( iSide*2.0, 0 );
if( fabs( posAgent.getX() ) > fabs( pos.getX() ) )
pos = posPenalty;
if( pos.getDistanceTo( posAgent ) < 0.6 )
{
pos = posPenalty;
if( fabs( VecPosition::normalizeAngle(
(pos-posAgent).getDirection() - angBody ) ) > 20 )
soc = turnBodyToPoint( pos );
}
// pos = WM->getAgentGlobalPosition();
}
else if( ( WM->getPlayMode() == PM_PENALTY_READY_LEFT ||
WM->getPlayMode() == PM_PENALTY_READY_RIGHT ||
WM->getPlayMode() == PM_PENALTY_TAKEN_LEFT ||
WM->getPlayMode() == PM_PENALTY_TAKEN_RIGHT
)
&& WM->isBallKickable() )
{
soc = kickTo(VecPosition(iSide*52.5,((drand48()<0.5)?1:-1)*5.9 ),2.7);
}
else
pos = posPenalty;
}
else if( formations->getPlayerType() == PT_GOALKEEPER )
{
if( WM->getAgentViewAngle() != VA_NARROW )
ACT->putCommandInQueue(
SoccerCommand( CMD_CHANGEVIEW, VA_NARROW, VQ_HIGH ));
// is penalty them, stop it, otherwise go to outside field
pos = posPenalty;
if( WM->isPenaltyThem( ) )
{
pos = VecPosition( iSide*(52.5 - 2.0), 0.0 );
if( SS->getPenAllowMultKicks() == false )
{
if( WM->getPlayMode() == PM_PENALTY_TAKEN_LEFT ||
WM->getPlayMode() == PM_PENALTY_TAKEN_RIGHT )
{
if( WM->isBallCatchable( ) )
soc = catchBall();
else
soc = intercept( true );
}
}
else if( pos.getDistanceTo( posAgent ) < 1.0 )
soc = turnBodyToPoint( VecPosition( 0,0) ) ;
else
soc = moveToPos( pos, 25 );
}
else
pos.setVecPosition( iSide * ( PITCH_LENGTH/2.0 + 2 ) , 25 );
}
else
{
pos = VecPosition( 5.0,
VecPosition::normalizeAngle(
iSide*(50 + 20*WM->getPlayerNumber())),
POLAR );
}
if( soc.isIllegal() &&
WM->getAgentGlobalPosition().getDistanceTo( pos ) < 0.8 )
{
soc = turnBodyToPoint( posPenalty );
}
else if( soc.isIllegal() )
{
soc = moveToPos( pos, 10);
}
if( WM->getAgentStamina().getStamina() <
SS->getRecoverDecThr()*SS->getStaminaMax() + 500 &&
soc.commandType == CMD_DASH)
soc.dPower = 0;
ACT->putCommandInQueue( soc );
pmPrev = WM->getPlayMode();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -