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

📄 soccertypes.cpp

📁 robocup 3d, a 3d base team similar to UvA 2d
💻 CPP
📖 第 1 页 / 共 2 页
字号:
          if( ptrStr[1] == '2' )    // Goal_2_l            o = (ptrStr[2] == 'L') ? OBJECT_GOAL_L_B : OBJECT_GOAL_R_B;          break;    case 'T': //  case 't': //    {      switch( ptrStr[3] )     // get team number      {        case '1': if( ptrStr[4] == '0' )                    o = OBJECT_TEAMMATE_10;                  else if( ptrStr[4] == '1' )                    o = OBJECT_TEAMMATE_11;                  else                    o = OBJECT_TEAMMATE_1;                  break;     // and find team member        case '2':  o = OBJECT_TEAMMATE_2;  break;        case '3':  o = OBJECT_TEAMMATE_3;  break;        case '4':  o = OBJECT_TEAMMATE_4;  break;        case '5':  o = OBJECT_TEAMMATE_5;  break;        case '6':  o = OBJECT_TEAMMATE_6;  break;        case '7':  o = OBJECT_TEAMMATE_7;  break;        case '8':  o = OBJECT_TEAMMATE_8;  break;        case '9':  o = OBJECT_TEAMMATE_9;  break;        case 'o':  o = OBJECT_TEAMMATE_UNKNOWN;        case 'g':  o = OBJECT_TEAMMATE_GOALIE;        default: o = OBJECT_ILLEGAL;      }    }    break;  case 'O': //  case 'o': //    {      switch( ptrStr[3] )     // get team number      {        case '1': if( ptrStr[4] == '0' )                    o = OBJECT_OPPONENT_10;                  else if( ptrStr[4] == '1' )                    o = OBJECT_OPPONENT_11;                  else                    o = OBJECT_OPPONENT_1;                  break;     // and find team member        case '2':  o = OBJECT_OPPONENT_2;  break;        case '3':  o = OBJECT_OPPONENT_3;  break;        case '4':  o = OBJECT_OPPONENT_4;  break;        case '5':  o = OBJECT_OPPONENT_5;  break;        case '6':  o = OBJECT_OPPONENT_6;  break;        case '7':  o = OBJECT_OPPONENT_7;  break;        case '8':  o = OBJECT_OPPONENT_8;  break;        case '9':  o = OBJECT_OPPONENT_9;  break;        case 'o':  o = OBJECT_OPPONENT_UNKNOWN;        case 'g':  o = OBJECT_OPPONENT_GOALIE;        default: o = OBJECT_ILLEGAL;      }    }  default:    cerr << "(SoccerTypes::getObjectFromStr) Unknown msg: " <<  ptrStr << "\n";    o = OBJECT_ILLEGAL;    break;  }  return o;}/*! This method returns the index of an object relative to the first object    in that set.    The index is always 1 smaller than its number, so OBJECT_OPPONENT_1    will become 0. This can be used for indexing an array of objects.    \param o ObjectT type of object of which the index has to be calculated    \return index of object or -1 when o was not a correct object */int SoccerTypes::getIndex( ObjectT o ){  if( o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_11 )    return o - OBJECT_OPPONENT_1;  else if( o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_11 )    return o - OBJECT_TEAMMATE_1;  else if( o >= OBJECT_GOAL_L_T && o <= OBJECT_GOAL_R_B )    return o - OBJECT_GOAL_L_T;  else if( o >= OBJECT_CORNER_L_T && o <= OBJECT_CORNER_R_B )    return o - OBJECT_CORNER_L_T;  else    return -1;}/*! This method returns the object type of a teammate with index iIndex. When    iIndex equals 3 for example OBJECT_TEAMMATE_4 is returned.    \param iIndex index of teammate range is [0..10]    \return object type corresponding to this index */ObjectT SoccerTypes::getTeammateObjectFromIndex( int iIndex ){  return (ObjectT) ( OBJECT_TEAMMATE_1 + iIndex );}/*! This method returns the object type of an opponent with index iIndex. When    iIndex equals 9 for example OBJECT_OPPONENT_10 is returned.    \param iIndex index of opponent range is [0..10]    \return object type corresponding to this index */ObjectT SoccerTypes::getOpponentObjectFromIndex( int iIndex ){  return (ObjectT) ( OBJECT_OPPONENT_1 + iIndex );}/*! This method returns a boolean indicating whether the object o is    part of the object set o_s. OBJECT_TEAMMATE_1 as o and    OBJECT_SET_TEAMMATES will return for example the value true.    \param o ObjectT of which should be checked whether it is a part of o_s    \param o_g ObjectSetT to check for object is in    \param objGoalie ObjectSet in which o should be    \return true when o is included in set o_g, false otherwise */bool SoccerTypes::isInSet( ObjectT o, ObjectSetT o_g, ObjectT objGoalie ){  switch( o_g )  {    case OBJECT_SET_TEAMMATES: return isTeammate( o ) && isKnownPlayer( o );    case OBJECT_SET_OPPONENTS: return isOpponent( o ) && isKnownPlayer( o );    case OBJECT_SET_PLAYERS:   return isPlayer  ( o ) && isKnownPlayer( o );    case OBJECT_SET_TEAMMATES_NO_GOALIE:                                return isTeammate( o ) && isKnownPlayer( o ) &&                                      o != objGoalie;        case OBJECT_SET_ILLEGAL:    default:                   break;  }  return false;}/*! This method returns a boolean value which indicates whether a given player    type belongs to a specific set. The set PS_DEFENDERS for example contains    both the defender sweeper and the wing defenders. */bool SoccerTypes::isPlayerTypeInSet( PlayerT p, PlayerSetT p_s ){  switch( p_s )  {    case PS_DEFENDERS:       return p == PT_DEFENDER_CENTRAL || p == PT_DEFENDER_WING;    case PS_MIDFIELDERS:      return p == PT_MIDFIELDER_CENTER || p ==  PT_MIDFIELDER_WING;    case PS_ATTACKERS:      return p == PT_ATTACKER_WING || p == PT_ATTACKER;    case PS_ALL:      return true;    default:       break;  }  return false;}/*! This method determines whether object o is a teammate    \param o an object type    \return bool indicating whether o is a teammate (true) or not (false) */bool SoccerTypes::isTeammate( ObjectT o ){  return ( o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_UNKNOWN );}/*! This method determines whether object o is an opponent    \param o an object type    \return bool indicating whether o is an opponent (true) or not (false) */bool SoccerTypes::isOpponent( ObjectT o ){  return ( o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_UNKNOWN );}/*! This method determines whether object o is a player without checking    whether its number or side is available.    \param o an object type    \return bool indicating whether o is a known player (true) or not    (false) */bool SoccerTypes::isPlayer( ObjectT o ){  return isKnownPlayer( o )           || o == OBJECT_TEAMMATE_UNKNOWN ||         o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_PLAYER_UNKNOWN;}/*! This method determines whether object o is a known player, thus    containing a number    \param o an object type    \return bool indicating whether o is a known player (true) or not    (false) */bool SoccerTypes::isKnownPlayer( ObjectT o ){  return (o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_11) ||         (o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_11);}/*! This method determines whether object o is a goalie = teammate number is 1    (for now)    \param o an object type    \return bool indicating whether o is a goalie (true) or not (false) */bool SoccerTypes::isGoalie( ObjectT o ){  return o == OBJECT_TEAMMATE_1 || o == OBJECT_OPPONENT_1;}/*! This method determines whether object o is the in set of flags or not    \param o an object type    \return bool indicating whether o is the flag (true) or not (false) */bool SoccerTypes::isFlag( ObjectT o ){  return ( o >= OBJECT_CORNER_L_T && o <= OBJECT_CORNER_R_B ) ? true : false;}/*! This method determines whether object o is in set of goals or not    \param o an object type    \return bool indicating whether o is the goal (true) or not (false) */bool SoccerTypes::isGoal( ObjectT o ){  return ( o >= OBJECT_GOAL_L_T && o <= OBJECT_GOAL_R_B ) ? true : false;}/*! This method determines whether object o is the ball    \param o an object type    \return bool indicating whether o is the ball (true) or not (false) */bool SoccerTypes::isBall( ObjectT o ){  return o == OBJECT_BALL;}/*! This method returns the string representation of a PlayModeT as is used    in the Robocup Soccer Simulation and also said by the referee.    \param pm PlayModeT which should be converted    \return  pointer to the string (enough memory has to be allocated) */const char* SoccerTypes::getPlayModeStr( PlayModeT pm ){  return PlayModeNames[(int)pm];}/*! This method parses the string given for a playmode message and extracts    it to a PlayModeT enumeration    \param str String that contains playmode information    \return PlayModeT PlayMode residing in the given string */PlayModeT SoccerTypes::getPlayModeFormStr( const char *str ){  for( unsigned i = 0; i < PM_ILLEGAL; i++ )    if( strncmp( PlayModeNames[i], str, strlen( PlayModeNames[i] ) ) == 0 )      return PlayModeT( i );  return PM_ILLEGAL;}/*! This method returns the string representation of a SideT as is used in the    Robocup Soccer Simulation (r or l).    \param s SideT which should be converted    \return pointer to the string */const char* SoccerTypes::getSideStr( SideT s ){  return SideNames[ (int)s ];}/*! This method returns the SideT from the string that is passed as the first    argument.    \param str pointer to a string that contains side info string at index 0    \return SideT of string representation, SIDE_ILLEGAL if it is not known */SideT SoccerTypes::getSideFromStr( char* str ){  if( str[0] == 'l' )    return SIDE_LEFT;  else if( str[0] == 'r' )    return SIDE_RIGHT;  else if( str[0] == 'o')    return SIDE_NONE;  else    return SIDE_ILLEGAL;}/*! This method extracts a joint id from a string    \param str string containing the joint name    \return JointID joint name as an enumeration */JointT SoccerTypes::getJointFromStr( const char * str ){  for( int i = 0; i < MAX_JOINTS; i++ )    if( strcmp( str, JointNames[i] ) == 0 )      return (JointT)i;  return JID_ILLEGAL;}/*! This method creates a text containing name of a joint    \param joint name of a joint to convert to string    \return const char * the name of the joint as a string */const char * SoccerTypes::getJointStr( JointT joint ){  return JointNames[(int)joint];}/*! This method creates a server command name for joint    \param joint the joint to convert into server command    \return const char * server command name of the joint */const char * SoccerTypes::getJointServerMsg( JointT joint ){  return JointCommands[(int)joint];}/*! This method returns string converted of the name of the supplied sensor    \param sense The sensor name    \return const char * String containing the name of sensor */const char * SoccerTypes::getSensorString( SensorT sense ){  return SenseNames[ (int)sense ];}/*! This method returns the sensor object form the supplied string    \param str String containing the sensor name    \return SensorT Sensor name derived from the string */const SensorT SoccerTypes::getSensorFromString( const char *str ){  if( strcmp( str, SenseNames[0] ) == 0 )    return SENSE_FOOT_LEFT;  else if( strcmp( str, SenseNames[1] ) == 0 )    return SENSE_FOOT_RIGHT;  else    return SENSE_ILLEGAL;}/*************************************************************************//**************************  Testing Purposes  ***************************//*************************************************************************//*int main(){  SoccerCommand cmd( CMD_JOINT, JID_LLEG_5_6, 12, 13);  cout << cmd << endl;    return 0;}*/

⌨️ 快捷键说明

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