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

📄 soccertypes.cpp

📁 2003年RoboCup仿真组世界冠军源代码 足球机器人 仿真组 的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}/*! 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;}/*! This method makes a tackle command from a SoccerCommand and puts the result    in str. Resulting string looks like: (tackle dPower). Enough space    should be allocated for str.    \param command SoccerCommand that is a tackle command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makeTackleCommand( char *str  ){  if( SS->getMinPower() <= dPower && dPower <= SS->getMaxPower() )    sprintf( str,"(tackle %d)", (int)dPower );  else  {    fprintf( stderr,        "(SoccerCommand::makeTackleCommand) power %d out of bounds (%d,%d)\n",        (int)dPower, SS->getMinPower(), SS->getMaxPower() );    return false;  }  return true;}/*! This method makes a pointto command from a SoccerCommand and    puts the result in str. Resulting string looks like:    (pointto dist dir | off)). When dX is smaller than  -1.0 the command    (pointto off) is created.    Enough space should be allocated for str.    \param command SoccerCommand that is a pointto command    \param str string that will be filled with the corresponding SoccerCommand    \return bool indicating whether string is filled or not  */bool SoccerCommand::makePointToCommand( char *str  ){  if( dX < 0 )  {    sprintf( str, "(pointto off)" );    return true;  }  if( dY >= SS->getMinMoment() && dY <= SS->getMaxMoment()  )    sprintf( str,"(pointto %1.2f %1.2f)", dX, dY );  else  {    fprintf( stderr,     "(SoccerCommand::makePointToCommand) arg %f or %f is wrong\n", dX, dY  );    return false;  }  return true;}/*****************************************************************************//********************* CLASS FEATURE *****************************************//*****************************************************************************//*! This is the constructor for the Feature class. A feature (specific    information that applies to the current time can be stored here. */Feature::Feature( ){  setFeature( Time(UnknownTime, 0), Time(UnknownTime, 0),Time(UnknownTime, 0),              OBJECT_ILLEGAL, UnknownDoubleValue );}/*! This is the constructor for the Feature class. A feature (specific    information that applies to the current time can be stored here.    For example, when the information about the fastest player to the ball    is calculated, this can be stored in a feauture. This information can    then be used for another calculation in the same cycle.    \param timeSee time of see message to which this feature applies.    \param timeSense time of sense message to which this feature applies.    \param object object to which this feature applies    \param dInfo specific information that can be stored about this feature.    \param soc soccercommand stored with this feature     \param pos position information stored with this feature */Feature::Feature( Time timeSee, Time timeSense, Time timeHear, ObjectT object,                  double dInfo, SoccerCommand soc, VecPosition pos ){  setFeature( timeSee, timeSense, timeHear, object, dInfo, soc, pos );}/*! This methods sets the values of the Feature class. A feature (specific    information that applies to the current time can be stored here.    For example, when the information about the fastest player to the ball    is calculated, this can be stored in a feauture. This information can    then be used for another calculation in the same cycle.    \param timeSee time of see message to which this feature applies.    \param timeSense time of sense message to which this feature applies.    \param timeSense time of hear message to which this feature applies.    \param object object to which this feature applies    \param dInfo specific information that can be stored about this feature.    \param soc command stored with this feature    \param pos position information stored with this feature     \return boolean indicating whether update was successful. */bool Feature::setFeature( Time timeSee,  Time timeSense, Time timeHear,                          ObjectT object, double  dInfo, SoccerCommand soc,                          VecPosition pos ){  bool b;  b  = setTimeSee( timeSee );  b &= setTimeSense( timeSense );  b &= setTimeHear( timeHear );  b &= setObject( object );  b &= setInfo( dInfo );  b &= setCommand( soc );  b &= setVec( pos );  return b;}/*! This method sets the see time for a feature.    \param time see time that applies to this feature. */bool Feature::setTimeSee( Time time ){  m_timeSee = time;  return true;}/*! This method returns the see time for a feature.     \return time that is related to this feature. */Time Feature::getTimeSee( ){  return m_timeSee;}

⌨️ 快捷键说明

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