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

📄 aeolus3d05.cpp

📁 RoboCup 3D 仿真组清华大学2005的源代码
💻 CPP
字号:
/*************************************************************************** *   Copyright (C) 2005 by Rujia Liu                                       * *   rujialiu@hotmail.com                                                  * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <iostream>#include <cstdlib>#include <oxygen/oxygen.h>#include "agent.h"#include "wmbuilder.h"#include "worldmodel.h"#include "skill.h"#include "decision.h"#include "formation.h"#include "situation.h"Agent      agent;WorldModel wm;WMBuilder  wmb;Skill      skill;Decision   decision;Formation  formation;Situation  situation;using namespace std;using namespace zeitgeist;using namespace oxygen;Zeitgeist zg(".", PACKAGE_NAME);Oxygen og(zg);const int max_str_length = 1000;AgentParam param;// read from param.txt to get parametersint ReadParamFile(char *fname){    FILE *fp = fopen(fname, "r");    if(fp == NULL) return 0;        // default parameters    agent.SetTeamName("Aeolus3D");    wm.SetTeamName("Aeolus3D");    agent.SetCycleStep(1);        // physics parameters    wm.physics.SetMaxLRV(8);    wm.physics.SetSpeedPrecision(0.1);        // log files    param.action_log = false;    param.wmb_log  = false;    param.wm_log = false;    param.wm_logvision = false;    param.wm_logcur = false;    param.decision_log = false;    param.skill_log = false;    param.formation_log = false;        // offclient module    param.offclient_rec = false;    param.offclient_do = false;    strcpy(param.offclient_file, "");        // formation    strcpy(formation.SBPFile, "playertype.sbp");    strcpy(formation.FMTFile, "aeolus3d05.fmt");        // read parameter file    char line[max_str_length];    char paramName[max_str_length], assign[max_str_length], value[max_str_length];            while(!feof(fp))    {        // read a line and skips commented ones        fgets(line, max_str_length, fp);        if(line[0] == '#' || line[0] == ';') continue;        if(sscanf(line, "%s%s%s", paramName, assign, value) != 3) continue; // invalid line format        fprintf(stderr, "(Param) Setting %s to %s...\n", paramName, value);        // basic        if(strcmp(paramName, "TeamName") == 0)            { agent.SetTeamName(value); wm.SetTeamName(value); }           // offclient        if(strcmp(paramName, "OffClient_Rec") == 0)            param.offclient_rec = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "OffClient_Do") == 0)            param.offclient_do = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "OffClient_File") == 0)            strcpy(param.offclient_file, value);        if(strcmp(paramName, "OffClient_Time") == 0)            param.offclient_time = atof(value);            // formation        if(strcmp(paramName, "SBP_File") == 0)            strcpy(formation.SBPFile, value);        if(strcmp(paramName, "FMT_File") == 0)            strcpy(formation.FMTFile, value);        // time control            if(strcmp(paramName, "CycleStep") == 0)            agent.SetCycleStep(atoi(value));        if(strcmp(paramName, "max_lrv") == 0)            wm.physics.SetMaxLRV(atoi(value));        if(strcmp(paramName, "speed_precision") == 0)            wm.physics.SetSpeedPrecision(atof(value));            // log system        if(strcmp(paramName, "action_log") == 0)            param.action_log = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "wmb_log") == 0)            param.wmb_log = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "wm_log") == 0)            param.wm_log = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "wm_logvision") == 0)            param.wm_logvision = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "wm_logcur") == 0)            param.wm_logcur = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "decision_log") == 0)            param.decision_log = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "skill_log") == 0)            param.skill_log = (value[0] == 'y' || value[0] == 'Y');        if(strcmp(paramName, "formation_log") == 0)            param.formation_log = (value[0] == 'y' || value[0] == 'Y');        }        // check offclient parameters    if(param.offclient_do)    {        if(param.offclient_rec)        {            fprintf(stderr, "Error: cannot enable both offclient_rec and offclient_do, \                            disbling offclient_do.\n");            param.offclient_do = false;        }        agent.offclient_fp = fopen(param.offclient_file, "r");        if(agent.offclient_fp == NULL)        {            fprintf(stderr, "Error: cannot open offclient_log file %s, disabling offclient_do\n",                            param.offclient_file);            param.offclient_do = false;        }    }          return 1;}int main(int argc, char *argv[]){      // set parameter filename    char paramFileName[max_str_length];        if(argc > 1)        strcpy(paramFileName, argv[1]);    else        strcpy(paramFileName, "param.txt");    if(!ReadParamFile(paramFileName))        fprintf(stderr, "Fatal Error: cannot find %s, aborting...\n", paramFileName);    else if(!zg.GetCore()->GetScriptServer()->RunInitScript("aeolus3d05.rb", "."))        fprintf(stderr, "Fatal Error: cannot find aeolus3d05.rb, aborting...\n");    else    {        if(!param.offclient_rec)        {            printf("************************************\n");            printf("*   RoboCup Simulation 3D League   *\n");            printf("*       Team TsinghuAeolus3D       *\n");            printf("*                                  *\n");            printf("*      source code release         *\n");            printf("*                                  *\n");            printf("*       Author: Rujia Liu          *\n");            printf("*                                  *\n");            printf("*   Tsinghua University, China     *\n");            printf("*                                  *\n");            printf("************************************\n");            printf("\n");        }        agent.SetTeamUnum(0);        bool result = agent.Behave();        if(result && !param.offclient_rec)            printf("TsinghuAeolus3D 2005 exited normally.\n");      }    return 0;}

⌨️ 快捷键说明

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