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

📄 sensehandler.cpp

📁 2003年RoboCup仿真组世界冠军源代码 足球机器人 仿真组 的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{  Parse::gotoFirstNonSpace( &strMsg );            // skip space  if( WM->getPlayerNumber() == 0 )                // if i am coach    return false;                                 //   skip message  if( strlen( strMsg ) < 2 || strMsg[0] == 'o' )  // skip message since no dir.    return false;                                 // thus no content  Parse::parseFirstInt( &strMsg );                // skip direction  Parse::gotoFirstNonSpace( &strMsg );            // skip space  if( strlen( strMsg ) < 2 || strMsg[1] == 'p' )  // skip message when from opp    return false;  int iPlayer = Parse::parseFirstInt( &strMsg );  // get player number  Parse::gotoFirstNonSpace( &strMsg );            // skip space  strMsg++;                                       // skip " (=quote)  if( strlen( strMsg ) < 4 )              // < 2 + two ending charactres ")  {    Log.log( 600, "communication string too small" );    return false;  }  // get the cycle number from the encoding  int iModCycle = (int)(strMsg[0] - 'a');  if( iModCycle < 0 || iModCycle > 9 )  {    Log.log( 600, "communication cycle nr out of bounds: %d", iModCycle );    return false;  }  // get the time difference between the current time and the send time  int iDiff = (iTime % 10) - iModCycle;  if( iDiff < 0 )    iDiff += 10;  // if it is too old; skip parsing; otherwise determine actual send time  if( iDiff > 2  )  {    Log.log( 600, "communication string too old time %d mod %d diff %d",                        iTime, iModCycle, iDiff);    return false;  }  iTime -= iDiff;  Log.log( 600, "process comm msg, diff %d time %d, %s", iDiff, iTime, strMsg);  WM->storePlayerMessage( iPlayer, strMsg, iTime );  return true;}bool SenseHandler::analyzeCoachMessage( char *strMsg ){  Log.log( 605, "received coach messages: %s" , strMsg );  return true;}/*! This method analyzes the check_ball message that is only received by the    coach. It sets the information in the Worldmodel what the status of the    ball is.    The format is as follows (check_ball <time> <status>).    \param strMsg string that contains the check_ball message    \return bool indicating whether update succeeded. */bool SenseHandler::analyzeCheckBall( char *strMsg ){  WM->setTimeCheckBall( Parse::parseFirstInt( &strMsg ) );  strMsg++;  WM->setCheckBallStatus( SoccerTypes::getBallStatusFromStr( strMsg ) );  return true;}/*! This method analyzes the change player type message. This method checks    whether the player that changed type equals the agent. When this is the    case, it adjust the ServerSettings according to the values associated    with this player type.    \param strMsg string that contains the player type message.    \return bool indicating whether player type of agent changed. */bool SenseHandler::analyzeChangePlayerTypeMessage( char *strMsg ){  Log.log( 999, "%s", strMsg );  int iPlayer = Parse::parseFirstInt( &strMsg );  if( *strMsg != ')' ) // we are dealing with player of own team  {    int      iType = Parse::parseFirstInt( &strMsg );    ObjectT  obj   = SoccerTypes::getTeammateObjectFromIndex( iPlayer - 1 );    Log.log( 605, "change player from message %d -> %d", obj, iType );    WM->setHeteroPlayerType( obj, iType );    Log.log( 605, "changed player from message %d -> %d", obj,               WM->getHeteroPlayerType( obj ) );    return true;  }  else  {    ObjectT  obj   = SoccerTypes::getOpponentObjectFromIndex( iPlayer - 1 );    return WM->setSubstitutedOpp( obj );  }  return false;}/*! This method analyzes the server_param message. This message contains all    the server parameters. All settings of the ServerSettings are changed    according to the supplied values. This makes the reading from a server    configuration file obsolete.    \param strMsg string message with all the server parameters    \return booli indicating whether string was parsed. */bool SenseHandler::analyzeServerParamMessage( char *strMsg ){  Log.log( 4, "%s", strMsg );  readServerParam( "goal_width",               strMsg );  readServerParam( "player_size",              strMsg );  readServerParam( "player_decay",             strMsg );  readServerParam( "player_rand",              strMsg );  readServerParam( "player_weight",            strMsg );  readServerParam( "player_speed_max",         strMsg );  readServerParam( "player_accel_max",         strMsg );  readServerParam( "stamina_max",              strMsg );  readServerParam( "stamina_inc_max",          strMsg );  readServerParam( "recover_dec_thr",          strMsg );  readServerParam( "recover_min",              strMsg );  readServerParam( "recover_dec",              strMsg );  readServerParam( "effort_dec_thr",           strMsg );  readServerParam( "effort_min",               strMsg );  readServerParam( "effort_dec",               strMsg );  readServerParam( "effort_inc_thr",           strMsg );  readServerParam( "effort_inc",               strMsg );  readServerParam( "kick_rand",                strMsg );  readServerParam( "ball_size",                strMsg );  readServerParam( "ball_decay",               strMsg );  readServerParam( "ball_rand",                strMsg );  readServerParam( "ball_weight",              strMsg );  readServerParam( "ball_speed_max",           strMsg );  readServerParam( "ball_accel_max",           strMsg );  readServerParam( "dash_power_rate",          strMsg );  readServerParam( "kick_power_rate",          strMsg );  readServerParam( "kickable_margin",          strMsg );  readServerParam( "catch_probability",        strMsg );  readServerParam( "catchable_area_l",         strMsg );  readServerParam( "catchable_area_w",         strMsg );  readServerParam( "goalie_max_moves",         strMsg );  readServerParam( "maxpower",                 strMsg );  readServerParam( "minpower",                 strMsg );  readServerParam( "maxmoment",                strMsg );  readServerParam( "minmoment",                strMsg );  readServerParam( "maxneckmoment",            strMsg );  readServerParam( "minneckmoment",            strMsg );  readServerParam( "maxneckang",               strMsg );  readServerParam( "minneckang",               strMsg );  readServerParam( "visible_angle",            strMsg );  readServerParam( "visible_distance",         strMsg );  readServerParam( "audio_cut_dist",           strMsg );  readServerParam( "quantize_step",            strMsg );  readServerParam( "quantize_step_l",          strMsg );  readServerParam( "ckick_margin",             strMsg );  readServerParam( "wind_dir",                 strMsg );  readServerParam( "wind_force",               strMsg );  readServerParam( "wind_rand",                strMsg );  readServerParam( "wind_random",              strMsg );  readServerParam( "inertia_moment",           strMsg );  readServerParam( "half_time",                strMsg );  readServerParam( "drop_ball_time",           strMsg );  readServerParam( "port",                     strMsg );  readServerParam( "coach_port",               strMsg );  readServerParam( "olcoach_port",             strMsg );  readServerParam( "say_coach_cnt_max",        strMsg );  readServerParam( "say_coach_msg_size",       strMsg );  readServerParam( "simulator_step",           strMsg );  readServerParam( "send_step",                strMsg );  readServerParam( "recv_step",                strMsg );  readServerParam( "sense_body_step",          strMsg );  readServerParam( "say_msg_size",             strMsg );  readServerParam( "clang_win_size",           strMsg );  readServerParam( "clang_define_win",         strMsg );  readServerParam( "clang_meta_win",           strMsg );  readServerParam( "clang_advice_win",         strMsg );  readServerParam( "clang_info_win",           strMsg );  readServerParam( "clang_mess_delay",         strMsg );  readServerParam( "clang_mess_per_cycle",     strMsg );  readServerParam( "hear_max",                 strMsg );  readServerParam( "hear_inc",                 strMsg );  readServerParam( "hear_decay",               strMsg );  readServerParam( "catch_ban_cycle",          strMsg );  readServerParam( "send_vi_step",             strMsg );  readServerParam( "use_offside",              strMsg );  readServerParam( "offside_active_area_size", strMsg );  readServerParam( "forbid_kick_off_offside",  strMsg );  readServerParam( "verbose",                  strMsg );  readServerParam( "offside_kick_margin",      strMsg );  readServerParam( "slow_down_factor",         strMsg );  readServerParam( "synch_mode",               strMsg );  readServerParam( "fullstate_l",              strMsg );  readServerParam( "fullstate_r",              strMsg );  readServerParam( "pen_dist_x",               strMsg );  readServerParam( "pen_max_goalie_dist_x",    strMsg );  readServerParam( "pen_allow_mult_kicks",     strMsg );  readServerParam( "tackle_dist",              strMsg );  readServerParam( "tackle_back_dist",         strMsg );  readServerParam( "tackle_width",             strMsg );  readServerParam( "tackle_cycles",            strMsg );  readServerParam( "tackle_power_rate",        strMsg );  readServerParam( "tackle_exponent",          strMsg );  SS->setMaximalKickDist      ( SS->getKickableMargin() +                                SS->getPlayerSize()     +                                SS->getBallSize()          );// SS->show( cerr, ":" );  return true;}bool SenseHandler::readServerParam( char *strParam, char *strMsg ){  char strFormat[128];  char strValue[128] = "";  sprintf( strValue, "none" );  sprintf( strFormat, "%s ", strParam );        // add space after parameters  char *str = strstr( strMsg, strFormat );      // and find param definition  sprintf( strFormat, "%s %%[^)]", strParam );  // read till closing bracket  if( str == NULL )  {    cerr << "(SenseHandler::readServerParam) " << WM->getPlayerNumber() <<            "  error finding " << strParam <<endl;    return false;  }  int ret = sscanf( str, strFormat, strValue ); // read in values  if( ret == 1 )    SS->setValue( strParam, strValue );  else    cerr << "(SenseHandler::readServerParam) error reading " <<strParam <<endl;  return (ret == 1 ) ? true : false ;}/*! This method analyze a player type message. This message contains the    values associated with a specific heterogeneous player type. The values    are parsed from the message and supplied to the WorldModel method    processNewHeteroPlayer.    \param strMsg string that contains the player type information    \return bool indicating whether the message was parsed correctly. */bool SenseHandler::analyzePlayerTypeMessage ( char *strMsg ){  Log.log( 999, "%s", strMsg );// cerr << strMsg << endl;  // analyze all heterogeneous player information  int    iIndex           = Parse::parseFirstInt( &strMsg );  double dPlayerSpeedMax  = Parse::parseFirstDouble( &strMsg );  double dStaminaIncMax   = Parse::parseFirstDouble( &strMsg );  double dPlayerDecay     = Parse::parseFirstDouble( &strMsg );  double dInertiaMoment   = Parse::parseFirstDouble( &strMsg );  double dDashPowerRate   = Parse::parseFirstDouble( &strMsg );  double dPlayerSize      = Parse::parseFirstDouble( &strMsg );  double dKickableMargin  = Parse::parseFirstDouble( &strMsg );  double dKickRand        = Parse::parseFirstDouble( &strMsg );  double dExtraStamina    = Parse::parseFirstDouble( &strMsg );  double dEffortMax       = Parse::parseFirstDouble( &strMsg );  double dEffortMin       = Parse::parseFirstDouble( &strMsg );  WM->processNewHeteroPlayer( iIndex, dPlayerSpeedMax, dStaminaIncMax,      dPlayerDecay,    dInertiaMoment, dDashPowerRate, dPlayerSize,      dKickableMargin, dKickRand,      dExtraStamina,  dEffortMax,      dEffortMin );  return true;}/*! This method analyzes the player_param message that indicates the ranges of    the possible values for the heterogeneous player types. Nothing is done    with this information.    \param strMsg string that contains the player_param message.    \bool will always be true. */bool SenseHandler::analyzePlayerParamMessage( char *strMsg ){//  cout << strMsg << endl;  Log.log( 999, "%s", strMsg );  readServerParam( "player_types",                     strMsg );  readServerParam( "subs_max",                         strMsg );  readServerParam( "player_speed_max_delta_min",       strMsg );  readServerParam( "player_speed_max_delta_max",       strMsg );  readServerParam( "stamina_inc_max_delta_factor",     strMsg );  readServerParam( "player_decay_delta_min",           strMsg );  readServerParam( "player_decay_delta_max",           strMsg );  readServerParam( "inertia_moment_delta_factor",      strMsg );  readServerParam( "dash_power_rate_delta_min",        strMsg );  readServerParam( "dash_power_rate_delta_max",        strMsg );  readServerParam( "player_size_delta_factor",         strMsg );  readServerParam( "kickable_margin_delta_min",        strMsg );  readServerParam( "kickable_margin_delta_max",        strMsg );  readServerParam( "kick_rand_delta_factor",           strMsg );  readServerParam( "extra_stamina_delta_min",          strMsg );  readServerParam( "extra_stamina_delta_max",          strMsg );  readServerParam( "effort_max_delta_factor",          strMsg );  readServerParam( "effort_min_delta_factor",          strMsg );  readServerParam( "new_dash_power_rate_delta_min",    strMsg );  readServerParam( "new_dash_power_rate_delta_max",    strMsg );  readServerParam( "new_stamina_inc_max_delta_factor", strMsg );  return true;}/*****************************************************************************//********************* TESTING PURPOSES **************************************//*****************************************************************************//*int main( void ){  Connection c( "localhost", 6000 );  WorldModel wm;  SenseHandler i( &c,  &wm );  i.analyzeMessage( "(see 0 ((g r) 64.1 13) ((f r t) 65.4 -16) ((f r b) 79 38) ((f p r t) 46.1 -6) ((f p r c) 48.4 18) ((f p r b) 58 37) ((f g r t) 62.8 7) ((f g r b) 66 19) ((f t r 20) 38.5 -38) ((f t r 30) 46.5 -30) ((f t r 40) 55.7 -25) ((f t r 50) 64.7 -21) ((f b r 50) 80.6 41) ((f r t 30) 69.4 -12) ((f r t 20) 67.4 -4) ((f r t 10) 67.4 4) ((f r 0) 69.4 12) ((f r b 10) 72.2 20) ((f r b 20) 75.9 27) ((f r b 30) 81.5 33) ((l r) 62.8 -89))" );   cout << "2" << endl;  i.analyzeMessage( "(see 0 ((g l) 49.9 -24) ((f l t) 50.9 14) ((f p l t) 31.5 1 0 0) ((f p l c) 34.5 -33) ((f g l t) 47.9 -17) ((f g l b) 52.5 -32) ((f t l 50) 50.9 20) ((f t l 40) 42.5 26) ((f t l 30) 34.8 36) ((f l t 30) 54.6 8) ((f l t 20) 53 -2) ((f l t 10) 53 -12) ((f l 0) 54.6 -23) ((f l b 10) 58 -32) ((f l b 20) 62.8 -41) ((p \"l\" 2) 5 -7 0 0 172 172) ((l l) 47.9 82))" );  c.disconnect();  cout << "exit" << endl ;}*/

⌨️ 快捷键说明

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