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

📄 worldmodel.c

📁 uva trilearn的robocup源程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/*! 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(){  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 )        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 sets the value of the specified object to a known player or not.    A known player is a player of which the exact team name and player number    are known. If the player number is not known, information about the object    is stored at an empty position in the player array and the value of    isKnownPlayer is set to 'false'.    \param o object type of which known player information should be set    \param isKnownPlayer new known player value    \return boolean indicating whether update was successful */bool WorldModel::setIsKnownPlayer( ObjectT o, bool isKnownPlayer ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  return object->setIsKnownPlayer( isKnownPlayer );}/*! This method sets the time the object 'o' has last been seen.     \param o object of which the time should be changed    \param time new time for this object    \return bool indicating whether update was successful. */bool WorldModel::setTimeLastSeen( ObjectT o, Time time ){  PlayerObject *object = (PlayerObject*) getObjectPtrFromType( o );  return object->setTimeLastSeen( time );}                                             /*! This method returns the global position of the opponent goal.    \return VecPosition containing the position of the opponent goal. */VecPosition WorldModel::getPosOpponentGoal( ){  return SoccerTypes::getGlobalPositionFlag(                        SoccerTypes::getGoalOpponent( getSide() ),                        getSide( ),                        SS->getGoalWidth() );}/*! This method returns the global position of the own goal.    \return VecPosition containing the position of the own goal. */VecPosition WorldModel::getPosOwnGoal( ){  return SoccerTypes::getGlobalPositionFlag(                        SoccerTypes::getOwnGoal( getSide() ),                        getSide( ),                        SS->getGoalWidth() );}/*! This method returns the relative distance to the opponent goal    \return relative distance from the agent to the opponent goal. */double  WorldModel::getRelDistanceOpponentGoal(){  VecPosition posGoal;  if( sideSide == SIDE_LEFT )    posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_R, sideSide );  else    posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_L, sideSide );  return getAgentGlobalPosition().getDistanceTo( posGoal );}/*! This method returns the relative angle to the opponent goal. This relative    angle is the relative angle between the opponent goal position and the agent    position. The neck and body angle of the agent are NOT taken into account.    \return relative angle between goal and agent position. */double  WorldModel::getRelAngleOpponentGoal(){  VecPosition posGoal;  if( sideSide == SIDE_LEFT )    posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_R, sideSide );  else    posGoal = SoccerTypes::getGlobalPositionFlag( OBJECT_GOAL_L, sideSide );  return ( posGoal - getAgentGlobalPosition()).getDirection() ;}/*! This method returns information about the heterogeneous player at index    'iIndex'. This information consists of a subset of the ServerSettings    values that fully specify the information of the heterogeneous player. */HeteroPlayerSettings WorldModel::getInfoHeteroPlayer( int iIndex ){  return pt[iIndex];}/*! This method checks whether a queued action is performed. The commands in    QueuedCommands are the commands that are sent to the server by the    ActHandler. The performedCommands array contains the commands that are    performed in the last cycle (using the count information in the sense_body    message). Using these two array it is possible to check whether a command    is actually performed by the server. When there is an action that is sent    to the server and not performed, this method returns false, true otherwise.    \return true when all commands sent to the server are performed. */bool WorldModel::isQueuedActionPerformed(){  // for all possible commands check if it is sent in previous cycle,  // but not performed  for( int i = 0 ; i < MAX_COMMANDS ; i++ )    if( queuedCommands[i].time   == getTimeLastSenseMessage() - 1 &&        performedCommands[i]     == false )      return false;  return true;}/*! This method checks whether the play mode indicates that we have    a free kick. When the specified PlayModeT equals PM_ILLEGAL (default), the     current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether we have a free kick. */bool WorldModel::isFreeKickUs( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();      return ( pm == PM_FREE_KICK_LEFT  && getSide() == SIDE_LEFT  ) ||         ( pm == PM_FREE_KICK_RIGHT && getSide() == SIDE_RIGHT ) ;}/*! This method checks whether the play mode indicates that the other    team has a free kick. When the specified PlayModeT equals     PM_ILLEGAL (default), the current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether the other team has a free kick. */bool WorldModel::isFreeKickThem( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return ( pm == PM_FREE_KICK_RIGHT  && getSide() == SIDE_LEFT  ) ||         ( pm == PM_FREE_KICK_LEFT   && getSide() == SIDE_RIGHT ) ;}/*! This method checks whether the play mode indicates that there is (or    will be) a before kick off situation. This is the case when the play mode    equals PM_BEFORE_KICK_OFF or either PM_GOAL_LEFT or PM_GOAL_RIGHT since     after the goal the play mode will go to PM_BEFORE_KICK_OFF.    When the specified PlayModeT equals PM_ILLEGAL (default), the     current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether there is a before kick off situation. */bool WorldModel::isBeforeKickOff( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return pm == PM_BEFORE_KICK_OFF  || pm == PM_GOAL_LEFT  ||         pm == PM_GOAL_RIGHT ; // || isKickOffUs( pm ) || isKickOffThem( pm );}/*! This method checks whether the play mode indicates that there is    a dead ball situation and our team is allowed to perform the action.    That is our team has either a free kick, kick in, corner kick or a kick in.    When the specified PlayModeT equals PM_ILLEGAL (default), the     current play mode is used.      \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether we have a dead ball situation. */bool WorldModel::isDeadBallUs( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return isKickInUs  ( pm ) || isFreeKickUs  ( pm ) || isCornerKickUs     ( pm )       || isKickOffUs ( pm ) || isOffsideThem ( pm ) || isFreeKickFaultThem( pm )      || isGoalKickUs( pm ) || isBackPassThem( pm ) ;}/*! This method checks whether the current play mode indicates that there is    a dead ball situation and their team is allowed to perform the action.    That is their team has either a free kick, kick in, corner kick or a kick    in. When the specified PlayModeT equals PM_ILLEGAL (default), the     current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether they have a dead ball situation. */bool WorldModel::isDeadBallThem( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return isFreeKickThem( pm ) || isKickInThem  ( pm ) || isCornerKickThem ( pm )      ||  isKickOffThem ( pm ) || isGoalKickThem( pm ) || isFreeKickFaultUs( pm )     || isOffsideUs    ( pm ) || isBackPassUs  ( pm ) ; }/*! This method checks whether the current play mode indicates that we have    a corner kick. When the specified PlayModeT equals PM_ILLEGAL (default),     the current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether we have a corner kick. */bool WorldModel::isCornerKickUs( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return ( pm == PM_CORNER_KICK_LEFT  && getSide() == SIDE_LEFT  ) ||         ( pm == PM_CORNER_KICK_RIGHT && getSide() == SIDE_RIGHT ) ;}/*! This method checks whether the current play mode indicates that the other    team has a corner kick. When the specified PlayModeT equals PM_ILLEGAL     (default), the current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether the other team has a corner kick. */bool WorldModel::isCornerKickThem( PlayModeT pm ){  if( pm == PM_ILLEGAL )     pm = getPlayMode();  return ( pm == PM_CORNER_KICK_RIGHT  && getSide() == SIDE_LEFT  ) ||         ( pm == PM_CORNER_KICK_LEFT   && getSide() == SIDE_RIGHT ) ;}/*! This method checks whether the current play mode indicates that we stood    offside. When the specified PlayModeT equals PM_ILLEGAL (default), the     current play mode is used.    \param pm play mode to check. In default case (PM_ILLEGAL) the current play           mode is used.     \return bool indicating whether we stood offside. */bool WorldModel::isOffsideUs( PlayModeT pm ){

⌨️ 快捷键说明

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