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

📄 soccertypes.c

📁 uva trilearn的robocup源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
}/*! This method makes a catch command from a SoccerCommand and puts the result    in str. Resulting string looks like: (catch dAngle). Enough space    should be allocated for str.    \param command SoccerCommand that is a catch command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeCatchCommand( char *str  ){  if( SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )    sprintf( str, "(catch %d)", (int)dAngle );  else  {    fprintf(stderr,     "(SoccerCommand::makeCatchCommand) angle %f out of bounds\n",dAngle);    return false;  }  return true;}/*! This method makes a change view command from a SoccerCommand and puts the    result in str. Resulting string looks like: (change_view va vq).    Enough space should be allocated for str.    \param command SoccerCommand that is a change view command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeChangeViewCommand( char *str  ){  if( va != VA_ILLEGAL && vq != VQ_ILLEGAL )    sprintf( str,"(change_view %s %s)", SoccerTypes::getViewAngleStr  ( va ),                                        SoccerTypes::getViewQualityStr( vq ) );  else  {    fprintf( stderr,       "(SoccerCommand::makeChangeViewCommand) wrong arguments %s %s\n",                             SoccerTypes::getViewAngleStr  ( va ),                             SoccerTypes::getViewQualityStr( vq )  );    return false;  }  return true;}/*! This method makes a dash command from a SoccerCommand and puts the result    in str. Resulting string looks like: (dash dPower). Enough space    should be allocated for str.    \param command SoccerCommand that is a dash command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeDashCommand( char *str  ){  if( SS->getMinPower() <= dPower && dPower <= SS->getMaxPower() )    sprintf( str,"(dash %d)", (int)dPower );  else  {    fprintf( stderr,         "(SoccerCommand::makeDashCommand) power %d out of bounds (%d,%d)\n",        (int)dPower, SS->getMinPower(), SS->getMaxPower() );    dPower = 0.0;    sprintf( str, "(dash 0)" );    return false;  }  return true;}/*! This method makes a kick command from a SoccerCommand and puts the result    in str. Resulting string looks like: (kick dPower dAngle).    Enough space should be allocated for str.    \param command SoccerCommand that is a kick command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeKickCommand( char *str  ){  if( SS->getMinPower( )  <= dPower && dPower <= SS->getMaxPower( ) &&      SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )    sprintf( str,"(kick %d %d)", (int)dPower, (int)dAngle );  else  {    fprintf(stderr,           "(SoccerCommand::makeKickCommand) one argument %d or %d is wrong\n",                    (int)dPower, (int)dAngle );    return false;  }  return true;}/*! This method makes a move command from a SoccerCommand and puts the result    in str. Resulting string looks like: (move dX dY).    Enough space should be allocated for str.    \param command SoccerCommand that is a move command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeMoveCommand( char *str  ){  if( -PITCH_LENGTH/2 - PITCH_MARGIN <= dX &&       PITCH_LENGTH/2 + PITCH_MARGIN >= dX &&      -PITCH_WIDTH/2  - PITCH_MARGIN <= dY &&       PITCH_WIDTH/2  + PITCH_MARGIN >= dY   )    sprintf( str,"(move %d %d)", (int)dX, (int)dY);  else  {    fprintf( stderr,          "(SoccerCommand::makeMoveCommand) one argument %d or %d is wrong\n",                  (int)dX, (int)dY) ;    return false;  }  return true;}/*! This method makes a say command from a SoccerCommand and puts the result    in str. Resulting string looks like: (say str). Enough space    should be allocated for str.    \param command SoccerCommand that is a say command    \param str_com string that will be filled with corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeSayCommand( char *str_com  ){  if( str != NULL && str[0] != '\0' )    sprintf( str_com, "(say %s)", str );  else  {    fprintf( stderr, "(SoccerCommand::makeSayCommand) no string filled in\n" );    return false;  }  return true;}/*! This method makes a sense_body command from a SoccerCommand and puts the    result in str. Resulting string looks like: (sense_body). Enough space    should be allocated for str.    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeSenseBodyCommand( char *str  ){  sprintf( str,"(sense_body)" );  return true;}/*! This method makes a turn command from a SoccerCommand and puts the result    in str. Resulting string looks like: (turn dAngle). Enough space    should be allocated for str.    \param command SoccerCommand that is a turn command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeTurnCommand( char *str  ){  if( SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )    sprintf( str,"(turn %d)", (int)dAngle );  else  {    fprintf( stderr,      "(SoccerCommand::makeTurnCommand) argument %d incorrect (%d, %d)\n",      (int)dAngle, SS->getMinMoment( ), SS->getMaxMoment( ) );    dAngle = 0.0;    sprintf( str, "(turn 0)" );    return false;  }  return true;}/*! This method makes a turn_neck command from a SoccerCommand and puts the    result in str. Resulting string looks like: (turn_neck dAngle).    Enough space should be allocated for str.    \param command SoccerCommand that is a turn_neck command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeTurnNeckCommand( char *str  ){  if( SS->getMinNeckMoment( ) <= (int)dAngle &&      (int)dAngle             <= SS->getMaxNeckMoment( ) )    sprintf( str,"(turn_neck %d)", (int)dAngle );  else  {    fprintf( stderr,       "(SoccerCommand::makeTurnNeckCommand) argument %d is wrong\n",                                                     (int)dAngle );    dAngle = 0.0;    sprintf( str, "(turn_neck 0)" );    return false;  }  return true;}/*! This method makes a change_player_type command from a SoccerCommand and    puts the result in str. Resulting string looks like:    (change_player_type dX dY). Where dX stands for the    teammate that should be changed and dY for the heterogenous player that    it should become.    Enough space should be allocated for str.    \param command SoccerCommand that is a turn_neck command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeChangePlayerCommand( char *str  ){  if( (int)dX > 0  && (int)dX <= MAX_TEAMMATES &&      (int)dY >= 0 && (int)dY < MAX_HETERO_PLAYERS  )    sprintf( str,"(change_player_type %d %d)", (int)dX, (int)dY );  else  {    fprintf( stderr,    "(SoccerCommand::makeChangePlayerCommand) argument %d or %d is wrong\n",                                               (int)dX, (int)dY  );    return false;  }  return true;}/*! This method makes a attentionto command from a SoccerCommand and    puts the result in str. Resulting string looks like:    (attentionto opp|our dY). Where 'opp' is used when dX < 0 and    'our' otherwise. dY stands for the player number of the team    we want to pay attention to. When dY equals -1.0 the command    (attentionto off) is created.    Enough space should be allocated for str.    \param command SoccerCommand that is a attentionto command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeAttentionToCommand( char *str  ){  char strTeam[10];  if( dY < 0 )  {    sprintf( str, "(attentionto off)" );    return true;  }      if( dX < 0 )    strcpy( strTeam, "opp" );  else    strcpy( strTeam, "our" );      if( (int)dY > 0  && (int)dY <= MAX_TEAMMATES )    sprintf( str,"(attentionto %s %d)", strTeam, (int)dY );  else  {    fprintf( stderr,     "(SoccerCommand::makeAttentionToCommand) argument %s or %d is wrong\n",                                               strTeam, (int)dY  );    return false;  }  return true;}/******************************************************************************//********************** CLASS SOCCERTYPES *************************************//******************************************************************************//*! This constant defines the string names corresponding to the ObjectT names,    defined in SoccerTypes.h. Players are not added since they depend on the    team name. Note that the order is important, since the names are in the same    order as the ObjectT enumeration. */const char * ObjectNames[] ={"(b)", "(g l)", "(g r)", "(g ?)", "(l l)", "(l r)", "(l b)", "(l t)", "(f l t)",    "(f t l 50)", "(f t l 40)", "(f t l 30)", "(f t l 20)", "(f t l 10)", "(f t 0)","(f c t)",    "(f t r 10)", "(f t r 20)", "(f t r 30)", "(f t r 40)","(f t r 50)", "(f r t)"   , "(f r t 30)", "(f r t 20)", "(f r t 10)","(f g r t)" , "(f r 0)"   , "(f g r b)" , "(f r b 10)", "(f r b 20)","(f r b 30)", "(f r b)"   , "(f b r 50)", "(f b r 40)", "(f b r 30)","(f b r 20)", "(f b r 10)", "(f c b)"   , "(f b 0)"   , "(f b l 10)","(f b l 20)", "(f b l 30)", "(f b l 40)", "(f b l 50)", "(f l b)","(f l b 30)", "(f l b 20)", "(f l b 10)", "(f g l b)" , "(f l 0)","(f g l t)" , "(f l t 10)", "(f l t 20)", "(f l t 30)", "(f p l t)","(f p l c)", "(f p l b)",   "(f p r t)",  "(f p r c)",  "(f p r b)", "(f c)" } ;/*! This method returns the string that corresponds to a specific object. This    string name is exactly the same as the (short) name of the RoboCup    Simulation.    \param strBuf is the string in which the string representation is stored    \param o ObjectT that has to be converted to the string representation    \param strTeamName teamname that should be placed in case of player object    \return pointer to strBuf, which contains the string representation */char* SoccerTypes::getObjectStr( char* strBuf, ObjectT o, const char *strTeamName ){  if( o >= OBJECT_BALL && o <=   OBJECT_FLAG_C )    sprintf( strBuf, ObjectNames[(int)o] );  else if( isKnownPlayer( o ) )    sprintf( strBuf, "(p %s %d)", strTeamName, getIndex( o ) + 1);  else if( o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_TEAMMATE_UNKNOWN )    sprintf( strBuf, "(p %s)", strTeamName );  else if( o == OBJECT_PLAYER_UNKNOWN )    sprintf( strBuf, "(p)" );  else if( o == OBJECT_UNKNOWN )    sprintf( strBuf, "(unknown)" );  else    sprintf( strBuf, "illegal: %d", (int)o );  return strBuf;}/*! This method returns an ObjectT that corresponds to the string passed as    the first argument. The string representation equals the representation    used in the Soccer Server. Format is with parenthesis, so possible arguments    for str are (ball), (p Team_L 1), etc.    \param str pointer to string containing string representation of object    \param isGoalie bool representing the fact whether object is a goalie    \param strMyTeamName in case of player or opponent object, own teamname           has to be matched, when it matches it is teammate otherwise opponent    \return return the corresponding ObjectT, OBJECT_ILLEGAL in case of error */ObjectT SoccerTypes::getObjectFromStr( char** str, bool *isGoalie,                                       const char* strMyTeamName ){  ObjectT o = OBJECT_ILLEGAL;  char* ptrStr = *str;  *isGoalie = false;  switch( ptrStr[1] )  {    case 'b':                       // (ball)    case 'B':                       // (B) in case of ball very close       o = OBJECT_BALL; break;    case 'G':       o = OBJECT_GOAL_UNKNOWN;      // (G) in case of goal very close, ignored      break;                        // (g l) or (g r) goal left or goal right    case 'g': o = (ptrStr[3] == 'l') ? OBJECT_GOAL_L : OBJECT_GOAL_R; break;    case 'l':                       // (l l), (l r), (l b) or (l t)      switch( ptrStr[3] )      {        case 'l': o = OBJECT_LINE_L;  break;        case 'r': o = OBJECT_LINE_R;  break;        case 'b': o = OBJECT_LINE_B;  break;        case 't': o = OBJECT_LINE_T;  break;        default:  o = OBJECT_ILLEGAL; break;      }

⌨️ 快捷键说明

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