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

📄 advancedcoach.cpp

📁 RoboCup 2D 仿真组老牌强队Mersad 2005的完整源代码
💻 CPP
字号:
/* *  Copyright 2002-2005, Mersad Team, Allameh Helli High School (NODET). * *  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. * *  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 Library General Public License for more details. * *  This file is created by: Mohammad Salehe *  and is modified by: Darioush Jalali * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <iostream>#include <cassert>#include "Logger.h"#include "OppTypes.h"#include "OurTypes.h"#include "AdvancedCoach.h"#include "SampleScenario.h"using namespace std;AdvancedCoach::AdvancedCoach(int argc, char **argv):		SyncedCoach(argc, argv){	tasksNum = 0;	numSentFreeForm = 0;	addTask(new OppTypes(worldModel, worldModelHistory), -1, 0);	addTask(new OurTypes(worldModel, worldModelHistory), 11, 0);}AdvancedCoach::~AdvancedCoach(){	if (isTrainer) {		assert (trainer);		delete trainer;	}}void AdvancedCoach::addTask(Task *task, int runCount, int runInterval){	tasks.push_back(task);	runCounts.push_back(runCount);	curCounts.push_back(runCount);	runIntervals.push_back(runInterval);	curIntervals.push_back(runInterval);	tasksNum++;}bool AdvancedCoach::processTasks(){	int i;	bool allowSendFreeForm; 	string freeFormQueue;	worldModel->getServerParam();	LOG << "AdvancedCoach::processTasks" << endl;		changePlayerCycleCommand = new EmptyCommand(AT_ADVANCED_COACH);		allowSendFreeForm = false;	freeFormQueue = "";		if (worldModel->getPlayMode() != PM_PLAY_ON)	{		LOG << "allowSFF - 1" << endl;		allowSendFreeForm = true;	}	else	{		LOG << "allowSFF - 2" << endl;		if (worldModel->getPlayOnPastCycles() > (unsigned)worldModel->				getServerParam()["freeform_wait_period"].asInt())		{		LOG << "allowSFF - 3" << endl;			if ((worldModel->getPlayOnPastCycles() % worldModel->					getServerParam()["freeform_send_period"].asInt()) <=				(unsigned)worldModel->					getServerParam()["freeform_wait_period"].asInt())			{				LOG << "allowSFF - 4" << endl;				allowSendFreeForm = true;			}		}	}			LOG << "allowSFF - 45 check : numSentFreeForm = " << numSentFreeForm << endl;	LOG << "allowSFF - 45 check : curCycle = " << worldModel->getCurCycle() << endl;	if (((((float)worldModel->getCurCycle()) / 6000) * 			worldModel->getServerParam()["say_coach_cnt_max"].asInt()) >= 			numSentFreeForm)	{		LOG << "allowSFF - 5" << endl;	}	else	{		LOG << "allowSFF - 6( no allow )" << endl;		allowSendFreeForm = false;	}	for (i = 0; i < tasksNum; i++)	{		if (curIntervals[i] == 0 && curCounts[i] != 0)		{			if (tasks[i]->execute(isTrainer))			{				LOG << "AdvancedCoach::task[" << i << "] execute = true" << endl; 				if (curCounts[i] > 0)				   	curCounts[i]--;				curIntervals[i] = runIntervals[i];				if (tasks[i]->hasChangePlayerCommand())				{					LOG << "AdvancedCoach::task[" << i << "] changePlayer = true" << endl; 					delete changePlayerCycleCommand;					changePlayerCycleCommand = 						tasks[i]->getChangePlayerCommand();					tasks[i]->setChangePlayerCommandSent();				}				if (allowSendFreeForm)				{					if (tasks[i]->isFreeFormReady())					{						freeFormQueue += tasks[i]->getFreeFormString();						tasks[i]->setFreeFormSent();					}				}			}		}		else if (curCounts[i] != 0)		{//			LOG << "AdvancedCoach::curCounts != 0" << endl;			curIntervals[i]--;		}		else		{//			LOG << "AdvancedCoach::else" << endl;		}	}//	LOG << "AdvancedCoach::out" << endl;//	freeFormQueue = "a";		if (allowSendFreeForm && freeFormQueue != "")	{//		LOG << "AdvancedCoach::newFreeFormCommand" << endl;		numSentFreeForm++;		freeFormCycleCommand = new FreeFormCommand(AT_ADVANCED_COACH, freeFormQueue);	}	else	{		freeFormCycleCommand = new EmptyCommand(AT_ADVANCED_COACH);	}//	LOG << "AdvancedCoach::returning true" << endl;	if (isTrainer) {		assert(trainer);		LOG << "Trainer OK, calling execute method" << endl;		trainer->execute(true);	}	return true;}void AdvancedCoach::changePlayerType(const SExpression &exp){	SyncedCoach::changePlayerType(exp);	informChangePlayerType(exp);}void AdvancedCoach::informChangePlayerType(const SExpression &exp){	SExpAtomic *at;	unsigned playerNum;	int i;//	LOG << "AdvancedCoach::informChangePlayerType:/" << exp.toString() << "/" << endl; 		if (exp.size() == 3) // teammate change player type	{	}	else // opponent change player type	{		assert(exp.size() == 2);		at = dynamic_cast<SExpAtomic *>(exp[1]);		assert(at);		playerNum = at->asInt();		assert(playerNum > 0 && playerNum <= FULL_PLAYERS_NUM);//		LOG << "AdvancedCoach::informOppChangePlayerType:" << playerNum << endl; 		for (i = 0; i < tasksNum; i++)			tasks[i]->informOppChangePlayerType(playerNum);	}}

⌨️ 快捷键说明

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