⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmodel.cpp

📁 用robocup2d改编设计的2d球队。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{  double dViewQualityFactor ;  double dViewWidthFactor   ;  if( va == VA_ILLEGAL )    va = getAgentViewAngle();  if( vq == VQ_ILLEGAL )    vq = getAgentViewQuality();  switch( va )  {    case VA_NARROW:  dViewWidthFactor   = 0.5; break;    case VA_NORMAL:  dViewWidthFactor   = 1.0; break;    case VA_WIDE:    dViewWidthFactor   = 2.0; break;    case VA_ILLEGAL:    default:         dViewWidthFactor   = 0.0; break;  }  switch( vq )  {    case VQ_LOW:     dViewQualityFactor = 0.5; break;    case VQ_HIGH:    dViewQualityFactor = 1.0; break;    case VQ_ILLEGAL:    default:         dViewQualityFactor = 0.0; break;  }  return dViewQualityFactor*dViewWidthFactor;}/*! This method returns whether the arm of the agent can be moved. */bool WorldModel::getAgentArmMovable( ){  return agentObject.getArmMovable();}/*! This method returns the current position the arm of the agent is     pointing towards. */VecPosition WorldModel::getAgentArmPosition( ){  return agentObject.getGlobalArmPosition();}/*! This method returns how many cycles it will last before the arm    of the agent stops pointing. */int WorldModel::getAgentArmExpires( ){  return agentObject.getArmExpires();}/*! This method returns the global position of the ball. The method    getConfidence with as argument OBJECT_BALL should be called to check the    confidence of this global position.    \return global position bal. */VecPosition  WorldModel::getBallPos(){  return getGlobalPosition( OBJECT_BALL );}/*! This method returns the current estimate of the speed of the ball.    \return speed of the ball (magnitude of the global velocity vector). */double WorldModel::getBallSpeed(){  return Ball.getGlobalVelocity().getMagnitude();}/*! This method returns the global direction of the ball velocity.    \return global direction of the ball velocity */AngDeg WorldModel::getBallDirection(){  return Ball.getGlobalVelocity().getDirection();}/*! This method returns the time of the global position    of the specified object.    \param ObjectT that represent the type of the object to check    \return time corresponding to the global position of 'o' */Time WorldModel::getTimeGlobalPosition( ObjectT o ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeGlobalPosition();  return UnknownTime;}/*! This method returns the global position of an objectType. This    method is normally used for the objects on the field (player,    opponents and the ball).  When the global position cannot be    determined, a VecPosition with both the x and y coordinate are set    to 'UnknownDoubleValue'.    \param ObjectT that represent the type of the object to check    \return VecPosition containing the global position. */VecPosition WorldModel::getGlobalPosition( ObjectT o ){  Object *object = getObjectPtrFromType( o );  if( object != NULL )  {    if( SoccerTypes::isFlag( o ) || SoccerTypes::isGoal( o ) )      return SoccerTypes::getGlobalPositionFlag( o, getSide(),                                                 SS->getGoalWidth() );    else      return object->getGlobalPosition();  }  return VecPosition( UnknownDoubleValue, UnknownDoubleValue);}/*! This method returns the time of the global velocity    of the specified object.    \param ObjectT that represent the type of the object to check    \return time corresponding to the global velocity of 'o' */Time WorldModel::getTimeGlobalVelocity( ObjectT o ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeGlobalVelocity();  return UnknownTime;}/*! This method returns the global velocity of an objectType. When the    global position cannot be determined, a VecPosition is returned with    both the x and y coordinate set to 'UnknownDoubleValue'.    \param ObjectT that represent the type of the object to check    \return VecPosition containing the global position. */VecPosition WorldModel::getGlobalVelocity( ObjectT o ){  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalVelocity(  );  return VecPosition( UnknownDoubleValue, UnknownDoubleValue );}/*! This method returns the relative distance between the agent and the object    supplied as the first argument. No check is made whether this information    is up to date (use isVisible or getConfidence for that).    \param ObjectT that represent the type of the object to check    \return relative distance to this object */double WorldModel::getRelativeDistance( ObjectT o ){  Object *object = getObjectPtrFromType( o );  if( object != NULL )    return object->getRelativeDistance();  return UnknownDoubleValue;}/*! This method returns the relative position of the object to the agent.    No check is made whether this information is up to date (use isVisible or    getConfidence for that).    \param ObjectT that represent the type of the object to check    \return relative position to this object */VecPosition  WorldModel::getRelativePosition( ObjectT o ){  Object *object = getObjectPtrFromType( o );  if( object != NULL )    return object->getRelativePosition();  return VecPosition(UnknownDoubleValue, UnknownDoubleValue);}/*! This method returns the relative angle between the agent and the object    supplied as the first argument. No check is made whether this information    is up to date (use isVisible or getConfidence for that).    By default the returned angle is relative to the neck    of the agent. When the second argument 'bWithBody' is set to true, the    returned angle is relative to the body of the agent.    \param ObjectT that represent the type of the object to check    \param bWithBody when true angle is relative to body, otherwise to neck           (default false)    \return relative angle to this object */AngDeg WorldModel::getRelativeAngle( ObjectT o, bool bWithBody ){  Object *object = getObjectPtrFromType( o );  double dBody   = 0.0;  if( object != NULL )  {    if( bWithBody == true )      dBody = getAgentBodyAngleRelToNeck();    return VecPosition::normalizeAngle( object->getRelativeAngle() - dBody );  }  return UnknownDoubleValue;}/*! This method returns the time of the global angles (both body and    neck angle) of the specified object.    \param ObjectT that represent the type of the object to check    \return time corresponding to both the stored body and neck angle */Time WorldModel::getTimeGlobalAngles( ObjectT o ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeGlobalAngles();  return Time( -1, 0);}/*! This method returns the global body angle of the specified object.    No check is made whether this information is up to date (use    getTimeGlobalAngles).    \param ObjectT that represent the type of the object to check    \return last known global body angle of this object */AngDeg WorldModel::getGlobalBodyAngle( ObjectT o ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalBodyAngle();  return UnknownAngleValue;}/*! This method returns the global neck angle of the specified object.    No check is made whether this information is up to date (use    getTimeGlobalAngles).    \param ObjectT that represent the type of the object to check    \return last known global neck angle of this object */AngDeg WorldModel::getGlobalNeckAngle( ObjectT o ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  if( object != NULL )    return object->getGlobalNeckAngle();  return UnknownAngleValue;}/*! This method returns the global angle of the specified object (this object    is normally a line).    \param ObjectT that represent the type of the object to check    \return global angle of this object in the field */AngDeg WorldModel::getGlobalAngle( ObjectT o ){  if( SoccerTypes::isLine( o ) )    return SoccerTypes::getGlobalAngleLine( o, getSide() );  return UnknownAngleValue;}/*! This method returns the confidence value of the object    supplied as the first argument. The confidence is calculated using the    current server cycle and the time the object was last seen.    \param ObjectT that represent the type of the object to check    \return confidence value [0.0, 1.0] that indicates the confidence value */double WorldModel::getConfidence( ObjectT o){  Object *object = getObjectPtrFromType( o );  if( object != NULL )    return object->getConfidence( getCurrentTime() );  return 0.0;}/*! This method returns wheter the specified object type is a known player.    A known player is a player of which we know for certain that the player    number is correct. If a player is seen without a number and it cannot be    mapped to a player, it is put on the first empty position in the    player list and the status of known player is set to false.    \param o object type of player that should be checked    \return bool indicating whether we are certain of number of player 'o'. */bool WorldModel::isKnownPlayer( ObjectT o ){  PlayerObject *object = (PlayerObject *)getObjectPtrFromType( o );  if( object != NULL  )    return object->getIsKnownPlayer();  return false;}/*! This method returns the object type of the opponent    goalkeeper. Which object type is the actual goalkeeper is checked    in different ways. First of all this information is can be    available in a see message.  When no player is stored in the world    model of which this is is perceived, the opponent goalkeeper is    assumed the player with the highest x coordinate, but only if this    player stands very close in front of the goal    \return ObjectT that represents the opponent goalkeeper, OBJECT_ILLEGAL if    it cannot be determined which object type is the opponent goalkeeper. */ObjectT WorldModel::getOppGoalieType(){  static ObjectT objGoalieType = OBJECT_ILLEGAL;  if( objGoalieType != OBJECT_ILLEGAL &&      isConfidenceGood( objGoalieType ) &&      isKnownPlayer( objGoalieType ) )    return objGoalieType;  ObjectT objOppMaxX = OBJECT_ILLEGAL;  double  x = -100.0, y = UnknownDoubleValue;  for( int i = 0; i < MAX_OPPONENTS; i++ )  {    if( isConfidenceGood( Opponents[i].getType( ) ) )    {      if( Opponents[i].getIsGoalie() == true ) // &&//           Opponents[i].getGlobalPosition().getX() > PENALTY_X - 2.0 )      {        objGoalieType = Opponents[i].getType();        return Opponents[i].getType();      }      if( Opponents[i].getGlobalPosition().getX() > x )      {        x          = Opponents[i].getGlobalPosition().getX();        y          = Opponents[i].getGlobalPosition().getY();        objOppMaxX = Opponents[i].getType();      }    }  }  // if opponent with highest x is nr 1, assume it is goalkeeper when standing  // in own penalty area, otherwise assume goalkeeper closest player to goal.  if( (objOppMaxX == OBJECT_OPPONENT_1 && x > PENALTY_X + 4.0 ) ||      (objOppMaxX != OBJECT_ILLEGAL    && x > PITCH_LENGTH/2.0 - 6.0 &&       fabs( y ) < SS->getGoalWidth()/2.0 ))    return objOppMaxX;  return OBJECT_ILLEGAL;}/*! This method returns the object type of the own goalkeeper. Which object    type is the actual goalkeeper is checked in different ways. First of all    this information is available in the see, when (goalie) is behind the    perceived object. When no player is stored in the world model of which    this is perceived, the own goalkeeper is assumed the player with the lowest    x coordinate, but only if this player stands close in front of the goal.    \return ObjectT that represents the own goalkeeper, OBJECT_ILLEGAL if    it cannot be determined which object type is the own goalkeeper. */ObjectT WorldModel::getOwnGoalieType(){  ObjectT objOwnMinX = OBJECT_ILLEGAL;  double x = 100.0, y = UnknownDoubleValue;  for( int i = 0; i < MAX_TEAMMATES; i++ )  {    if( isConfidenceGood( Teammates[i].getType( ) ) )    {      if( Teammates[i].getIsGoalie() == true )        return Teammates[i].getType();      if( Teammates[i].getGlobalPosition().getX() < x )      {        x          = Teammates[i].getGlobalPosition().getX();        y          = Teammates[i].getGlobalPosition().getY();        objOwnMinX = Teammates[i].getType();      }    }  }  if( ( objOwnMinX == OBJECT_TEAMMATE_1 && x < - ( PENALTY_X + 4.0 ) ) ||      (objOwnMinX != OBJECT_ILLEGAL    && x < -  PITCH_LENGTH/2.0 + 6.0  &&       fabs( y ) < SS->getGoalWidth()/2.0 ))    return objOwnMinX;  return OBJECT_ILLEGAL;}/*! This method returns the last server cycle the specified object has been    seen.    \param object type of object that should be checked    \return server time this object was last seen (in a see message). */Time WorldModel::getTimeLastSeen( ObjectT o ){  Object *object = getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeLastSeen(  );  return Time( -1, 0);}/*! This method returns the last server cycle the relative distance change of    the specified object has been reported.    \param object type of object that should be checked    \return server time relative distance change of this object was last           seen (in a see message). */Time WorldModel::getTimeChangeInformation( ObjectT o ){  DynamicObject *object = (DynamicObject*)getObjectPtrFromType( o );  if( object != NULL )    return object->getTimeChangeInformation(  );  return Time( -1, 0);}/*! This method returns the last global position derived from a see message.    The time corresponds to the method 'getTimeGlobalPositionLastSee'. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -