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

📄 soccertypes.c

📁 uva trilearn的robocup源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
    these two time objects equals zero, true is returned, false otherwise    \param i actual time with which current time should be compared    \return bool indicating whether current time equals specified time */bool Time::operator == ( const int &i ){  return !( *this != i );}/*! This method returns a boolean indicating whether the current time equals    the time t. When the time difference returned by getTimeDifference between    these two time objects equals zero, true is returned, false otherwise    \param t time with which current time should be compared    \return bool indicating whether current time equals specified time */bool Time::operator == ( Time t ){  return !( *this != t );}/*! This method returns a boolean indicating whether the current time is smaller    than the time t. When the time difference returned by getTimeDifference    is smaller than zero, true is returned, false otherwise    \param t time with which current time should be compared    \return bool indicating whether current time is smaller than given time */bool Time::operator <  ( Time t ){  return getTimeDifference( t ) < 0;}/*! This method returns a boolean indicating whether the current time is smaller    than the time denoted by the integer 'i'. Herefore first a time object (i,0)    is created.    \param t time with which current time should be compared    \return bool indicating whether current time is smaller than given time */bool Time::operator <  ( const int  &i ){  return Time( i, 0 ) >= *this ;}/*! This method returns a boolean indicating whether the current time is smaller    than or equal to the time t.    \param t time with which current time should be compared    \return bool indicating whether current time is smaller to or equal     than 't' */bool Time::operator <= ( Time t ){  return ( *this < t ) || (*this == t );}/*! This method returns a boolean indicating whether the current time is smaller    than or equal to the time denoted by the integer 'i'. Herefore first a time    object (i,0) is created.    \param t time with which current time should be compared    \return bool indicating whether current time is smaller than or equal to    't' */bool Time::operator <= ( const int  &i ){  return ( *this < i ) || (*this == i );}/*! This method returns a boolean indicating whether the current time is larger    than the time t, that is it is not smaller than or equal to 't'.    \param t time with which current time should be compared    \return bool indicating whether current time is larger than 't' */bool Time::operator >  ( Time t ){  return !( *this <= t );}/*! This method returns a boolean indicating whether the current time is larger    than the time denoted by the integer 'i'. Herefore first a time    object (i,0) is created.    \param t time with which current time should be compared    \return bool indicating whether current time is larger than the given time*/bool Time::operator >  ( const int  &i ){  return !( *this <= i );}/*! This method returns a boolean indicating whether the current time is larger    than or equal to than the time t, that is it is not smaller than 't'.    \param t time with which current time should be compared    \return bool indicating whether current time is larger or equal than 't' */bool Time::operator >= ( Time t ){  return !( *this < t );}/*! This method returns a boolean indicating whether the current time is larger    than or equal to the time denoted by the integer 'i'. Herefore first a time    object (i,0) is created.    \param t time with which current time should be compared    \return bool indicating whether current time is larger than or equal to the     given time*/bool Time::operator >= ( const int  &i ){  return !( *this < i );}/*! Overloaded version of the C++ output operator for a Time class. This    operator makes it possible to use Time objects in output statements (e.g.    cout << t). The current cycle and the stopped time are printed in the    format (t1,t2).    \param os output stream to which information should be written    \param v a Time object which must be printed    \return output stream containing (x,y) */ostream& operator <<( ostream &os, Time t ){  return os << "(" << t.getTime() << "," << t.getTimeStopped() << ")";}/******************************************************************************//********************** CLASS SOCCERCOMMAND ***********************************//******************************************************************************//*! This is a constructor for the SoccerCommand class. It creates a command    using the passed arguments (with all default illegal values). Depending    on the specified CommandT the parameters are used in different ways. See    the method makeCommand for an explanation of these values.    \param com commandType for this SoccerCommand    \param d1 1st argument, meaning depends on com (default UnknownDoubleValue)    \param d2 2nd argument, meaning depends on com (default UnknownDoubleValue)    \param d3 3rd argument, meaning depends on com (default UnknownDoubleValue)    \return SoccerCommand with the specified parameters.*/SoccerCommand::SoccerCommand( CommandT com, double d1, double d2, double d3 ){  // first initialize variables  commandType = com;  dPower      = UnknownDoubleValue;  dAngle      = UnknownDoubleValue;  va          = VA_ILLEGAL;  vq          = VQ_ILLEGAL;  iTimes      = 1;  strcpy( str, "\0" );  if( com == CMD_CHANGEVIEW )    makeCommand( commandType, (ViewAngleT)d1, (ViewQualityT)d2 );  else if( com != CMD_SAY )    makeCommand( commandType, d1, d2, d3 );}/*! This is a constructor for the SoccerCommand when the commandType is a say    message.    \param com commandType for this SoccerCommand (must be CMD_SAY).    \param msg message for this SoccerCommand */SoccerCommand::SoccerCommand( CommandT com, char *msg ){  makeCommand( com, msg )  ;}/*! This method create a SoccerCommand from the specified command type and the    parameters. The parameters have a different meaning depending on the given    command type. Not all command types are listed, since the other command    types need different parameters. So see the other overloaded methods for    that.    - CMD_DASH:        d1 = power for dashing    - CMD_TURN:        d1 = angle body is turned    - CMD_TURNNECK     d1 = angle neck is turned    - CMD_KICK         d1 = power for kick command, d2 = angle for kick    - CMD_MOVE         d1 = x position, d2 = y position, d3 = body_angle    - CMD_CATCH        d1 = catch angle    - CMD_CHANGEPLAYER d1 = player number, d2 = nr of new player type    - CMD_ATTENTIONTO  d1 = which team, d2 = player number    \param com command type specifying the kind of command    \param d1 meaning depends on the specified command type (see above)    \param d2 meaning depends on the specified command type (see above)    \param d3 meaning depends on the specified command type (see above) */void SoccerCommand::makeCommand( CommandT com, double d1, double d2, double d3 ){  // set the variables that have a meaning for the specified command type  commandType = com;  if( com == CMD_TURN || com == CMD_TURNNECK )    dAngle = d1;  else if( com == CMD_DASH )    dPower = d1;  else if( com == CMD_KICK )  {    dPower = d1;    dAngle = d2;  }  else if( com == CMD_MOVE )  {    dX = d1;    dY = d2;    if( d3 != UnknownDoubleValue )      dAngle = d3;    else      dAngle = 0;  }  else if( com == CMD_CATCH )    dAngle = d1;  else if( com == CMD_CHANGEPLAYER )  {    dX = d1;    dY = d2;  }  else if( com == CMD_ATTENTIONTO )  {    dX = d1;    dY = d2;  }}/*! This method creates a SoccerCommand for the command type CMD_CHANGEVIEW.    \param com command type specifying the kind of command    \param v view angle for the change view command    \param q view quality for the change view command */void SoccerCommand::makeCommand( CommandT com, ViewAngleT v, ViewQualityT q ){  commandType = com;  if( com == CMD_CHANGEVIEW )  {    va = (ViewAngleT)  v;    vq = (ViewQualityT)q;  }}/*! This method creates a command for the command type CMD_SAY that accepts a    string as parameter.    \param com command type specifying the kind of command.    \param msg string message that is added to the say message. */void SoccerCommand::makeCommand( CommandT com, char* msg ){  commandType = com;  if( com == CMD_SAY )     strcpy( str, msg );}/*! This method prints the current command to the specified output stream.    \param os output stream to which information is printed. */void SoccerCommand::show( ostream& os ){  os << "time: " << time << " "; // can be illegal when not yet set in WM.  switch( commandType )  {    case CMD_ILLEGAL:      os << "illegal\n" ;      break;    case CMD_DASH:      os << "dash " << dPower << " times: " << iTimes << endl;      break;    case CMD_TURN:    case CMD_TURNNECK:      if( commandType == CMD_TURN )        os << "turn " << dAngle << endl;      else        os << "turn_neck " << " " << dAngle << endl;      break;     case CMD_CHANGEVIEW:      os << "change_view " <<              SoccerTypes::getViewAngleStr( va ) << " " <<              SoccerTypes::getViewQualityStr( vq ) << endl;      break;    case CMD_CATCH:      os << "catch " << dAngle << endl;      break;    case CMD_KICK:      os << "kick " << dPower << " " << dAngle << endl;      break;    case CMD_MOVE:      os << "move " << dX << " " << dY << " " << dAngle << endl;      break;    case CMD_SENSEBODY:      os << "sense_body" << endl;      break;    case CMD_SAY:      os << "say " << str << endl;      break;    case CMD_CHANGEPLAYER:      os << "change_player " << (int)dX << " " << (int)dY << endl;      break;    case CMD_ATTENTIONTO:      os << "attentionto " << (int)dX << " " << (int)dY << endl;    default:      os << "unknown" << endl;      break;  }}/*! This method returns whether this SoccerCommand is illegal, that is the    SoccerCommand hasn't been filled yet. This means that no command would be    performed when this command is sent to the server.    \return bool indicating whether the current Command is illegal */bool SoccerCommand::isIllegal( ){  return commandType == CMD_ILLEGAL;}/*! This method returns a command string that is understood by the server from a    SoccerCommand. The resulting string is put in the second argument and    returned by the method. A reference to ServerSettings is passed as the    second argument to check whether the values in the SoccerCommand are legal.    \param str resulting string (enough space for MAX_MSG should be allocated)    \param ss reference to serversettings class.    \return resulting string */char*  SoccerCommand::getCommandString( char *str, ServerSettings *ss ){  SS = ss;  bool b = false;  switch( commandType )  {    case CMD_DASH:        b = makeDashCommand(         str ); break;    case CMD_TURN:        b = makeTurnCommand(         str ); break;    case CMD_TURNNECK:    b = makeTurnNeckCommand(     str ); break;    case CMD_CHANGEVIEW:  b = makeChangeViewCommand(   str ); break;    case CMD_CATCH:       b = makeCatchCommand(        str ); break;    case CMD_KICK:        b = makeKickCommand(         str ); break;    case CMD_MOVE:        b = makeMoveCommand(         str ); break;    case CMD_SENSEBODY:   b = makeSenseBodyCommand(    str ); break;    case CMD_SAY:         b = makeSayCommand(          str ); break;    case CMD_CHANGEPLAYER:b = makeChangePlayerCommand( str ); break;    case CMD_ATTENTIONTO: b = makeAttentionToCommand(  str ); break;    case CMD_ILLEGAL:    str[0] = '\0';                       break;    default:      cerr << "(ActHandler::makeCommandString) Unkown command!"<<endl;    if( b == false )                       // if string could not be created    {      commandType = CMD_ILLEGAL;      str[0] = '\0';                       // create the empty string    }  }  return str;

⌨️ 快捷键说明

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