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

📄 start.cpp

📁 robocup 3d, a 3d base team similar to UvA 2d
💻 CPP
字号:
/***********************************************************************************                            In the name of Almighty                            **                                                                               **            start.cpp : Robocup 3D Soccer Simulation Team Zigorat              **                     (This team was previously named Gcyrus)                   **                                                                               **  Date: 03/20/2007                                                             **  Author: Mahdi Hamdarsi                                                       **  Comments: This file contains start script to run the team                    **                                                                               ***********************************************************************************//*! \file start.cpp<pre><b>File:</b>          start.cpp<b>Project:</b>       Robocup Soccer Simulation Team: Zigorat<b>Authors:</b>       Mahdi Hamdarsi<b>Created:</b>       03/20/2007<b>Last Revision:</b> $ID$<b>Contents:</b>      This file contains start script to run the team<hr size=2><h2><b>Changes</b></h2><b>Date</b>             <b>Author</b>          <b>Comment</b>03/20/2007       Mahdi           Initial version created</pre>*/#include <iostream>#include <stdlib.h>const int ERROR_SUCCESS      = 0;  /*!< Tells that no error were found */const int ERROR_SHOW_OPTIONS = 1;  /*!< Tells to show the options      */const int ERROR_ERROR        = 2;  /*!< Tells that unknonw err occured */using namespace std;char fconf  [ 180 ] = "";      /*!< Formation configuration file */char aconf  [ 180 ] = "";      /*!< Agent configuration file (weights & etc.) */char host   [ 180 ] = "";      /*!< host name to connect to */char player [ 180 ] = "";      /*!< player executable */bool PlayerAllowed[ 11 ] =     /*!< Maximum player allowed to start */{ false, false, false, false, false, false, false, false, false, false};char team[ 180 ] = "Zigorat";  /*!< Team name to start agent with */bool FileExists( const char strFileName[] );int  InitVars( int argc, char *argv[] );void StartTeam();void ShowOptions();/*! This is the main part, I don't think it needs any clarifications!    \param argc Argument count of the application    \param argv Arguments of application    \return int Exit status */int main(int argc, char *argv[]){  int result = InitVars( argc, argv );  if( result == ERROR_SUCCESS )    StartTeam();  else  {    if( result == ERROR_SHOW_OPTIONS )      ShowOptions();    return 1;  }  return ( EXIT_SUCCESS );}/*! This function checks for a file to exist    \param strFileName filename to check existing    \return bool if file exists true, else not */bool FileExists( const char strFileName[] ){  FILE *f = fopen( strFileName, "r" );  if( !f )    return ( false );  fclose( f );  return ( true );}/*! This function checks the arguments given to the     application and determines what to do    \param argc number of arguments    \param argv arguments of program to handle    \return int Indicating error number - 0 = successfull */int InitVars( int argc, char *argv[] ){  int i;  bool Allow;  strcpy( host, "localhost" );  /*********************  Initializing using run time arguments  *********************/  for( i = 1; i < argc; i++ )  {    if( argv[ i ][ 0 ] == 'h' )    {      ShowOptions();      return ( ERROR_SHOW_OPTIONS );    }    /******************  Initializing Executable Files  ******************/    else if( argv[ i ][ 0 ] == '/' )    {      if( argc == ( i + 1 ) )      {        cout << "Need argument for option: " << argv[ i ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( !FileExists( argv[ i + 1 ] ) )      {        cout << "File doesn't exists: " << argv[ i + 1 ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( argv[ i ][ 1 ] == 'p' )        strcpy( player, argv[ i + 1 ] );      i++;    }    /**********************  Initializing params  *************************/    else if( argv[ i ][ 0 ] == '-' )    {      char ch = argv[ i ][ 1 ];      if( ch != 'v' && ch != 'h' && ch != 't' && ch != 'p' &&          ch != 'a' && ch != 'g' && ch != 'f' && ch != '-' )      {        cout << "Invalid argument: " << argv[ i ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( argv[ i ][ 1 ] == '-' )      {        if( argv[ i ][ 2 ] == 'h' )          ShowOptions();        else          cout << "Invlaid argument: " << argv[ i ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( argv[ i ][ 1 ] == 'h' && argv[ i ][ 2 ] == 'e' )      {        ShowOptions();        return ( ERROR_SHOW_OPTIONS );      }      if( argc == ( i + 1 ) )      {        cout << "Need argument for option: " << argv[ i ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( argv[ i + 1 ][ 0 ] == '-' )      {        cout << "Illegal argument: " << argv[ i + 1 ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      if( argv[ i ][ 1 ] == 'h' )        strcpy( host, argv[ i + 1 ] );      else if( argv[ i ][ 1 ] == 't' )        strcpy( team, argv[ i + 1 ] );      else if( !FileExists( argv[ i + 1 ] ) )      {        cout << "File doesn't exists: " << argv[ i + 1 ] << endl;        return ( ERROR_ERROR );      }      else if( argv[ i ][ 1 ] == 'a' )        strcpy( aconf, argv[ i + 1 ] );      else if( argv[ i ][ 1 ] == 'f' )        strcpy( fconf, argv[ i + 1 ] );      else      {        cout << "Option unrecognized: " << argv[ i ] << endl;        return ( ERROR_SHOW_OPTIONS );      }      i++;    }    else if( argv[ i ][ 0 ] >= '0' && argv[ i ][ 0 ] <= '9' )    {      int num = ( int )( argv[ i ][ 0 ] - '0' );      if( argv[ i ][ 1 ] )        num = 10 * num + ( int )( argv[ i ][ 1 ] - '0' );      if( num < 2 || num > 11 )      {        cout << "Number out of legal range: " << num << endl;        return ( ERROR_ERROR );      }      PlayerAllowed[ num - 2 ] = 1;    }    else      return false;  }  /************  Initializing using current directory params  ************/  if( !FileExists( aconf ) )    strcpy( aconf, "./agent.conf" );  if( !FileExists( fconf ) )    strcpy( fconf, "./formations.conf" );  if( !FileExists( player ) )    strcpy( player, "./zigorat_player" );  /*************  Initializing using abstract directory params  *************/  if( !FileExists( aconf ) )    strcpy( aconf, "/root/Zigorat/agent.conf" );  if( !FileExists( fconf ) )    strcpy( fconf, "/root/Zigorat/formations.conf" );  if( !FileExists( player ) )    strcpy( player, "/root/Zigorat/zigorat_player" );  /*********************  Files were not found  ***********************/  if( !FileExists( player ) )    cout << "Player executable is not found" << endl;  if( !FileExists( aconf ) )    cout << "Unable to locate agent configuration file" << endl;  if( !FileExists( fconf ) )    cout << "Unable to locate formation configuration file" << endl;  if( !FileExists( aconf )  || !FileExists( fconf ) || !FileExists( player ) )    return ( ERROR_ERROR );  /********************  All Files were Found.  **********************/  Allow = false;  for( i = 1; i <= 11; i++ )    if( PlayerAllowed[ i ] )      Allow = true;  if( !Allow )    for( i = 1; i <= 11; i++ )      PlayerAllowed[ i ] = true;  cout << endl << "Good. All Needed Files were found." << endl;  return ERROR_SUCCESS;}/*! This function starts the team after it has been initialized */void StartTeam(){  char strExec[ 180 ];  int  i;  cout << endl;  cout << "**********************************************************************" << endl;  cout << "*                                                                    *" << endl;  cout << "*  Robocup 3D Soccer Simulation Team : Zigorat                       *" << endl;  cout << "*                                                                    *" << endl;  cout << "*  Date: 03/20/2007                                                  *" << endl;  cout << "*  Main Members:                                                     *" << endl;  cout << "*    - Mohammadi, Amin  : Islamic Azad University, Iran              *" << endl;  cout << "*        <amin.mohammadi@gmail.com>                                  *" << endl;  cout << "*    - Hamdarsi, Mahdi : Shahid Beheshti University of Tehran, Iran  *" << endl;  cout << "*        <hamdarsi@gmail.com>                                        *" << endl;  cout << "*                                                                    *" << endl;  cout << "**********************************************************************" << endl;  cout << endl;  for( i = 1; i <= 11; i++ )  {    if( !PlayerAllowed[ i - 1 ] )       continue;    sprintf( strExec, "%s -number %d -host %s -team %s  -f %s -a %s &", player, i, host, team, fconf, aconf );    system( strExec );  }}/*! So visible */void ShowOptions(){  cout << "Here is the list of options to start this team:                     " << endl << endl;  cout << "  -h(ost)                    : Host to connect to                   " << endl;  cout << "  -t(eam)                    : Team name                            " << endl;  cout << "  -a(gent conf. file)        : Agent conf. file to use              " << endl;  cout << "  -f(ormation settings file) : Formation settings file to load form " << endl;  cout << "  /p(layer executable)       : Player executable file               " << endl;  cout << "  1..11                      : Executes only the players mentioned  " << endl << endl;}

⌨️ 快捷键说明

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