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

📄 basiccoach.cpp

📁 IRAN mesard_2d 2005源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			playerType(exp);		else if (header == "init")			init(exp);		else if (header == "think")			think(exp);		else if (header == "change_player_type")			changePlayerType(exp);		else if (header == "ok")			ok(exp);		else			LOG << "Skipping message with unknown header: "				<< exp.toString() << endl;	}		decide();	return true;}bool BasicCoach::sigKillHandler(){	LOG << "Kill Handler." << endl;	cout << "Kill Handler." << endl;	return false;}bool BasicCoach::sigQuitHandler(){	LOG << "Quit Handler." << endl;	cout << "Quit Handler." << endl;	return false;}bool BasicCoach::sigSegVHandler(){	LOG << "Segmentation Violation Handler." << endl;	cout << "Segmentation Violation Handler." << endl;	exit(1);	return false;}bool BasicCoach::sigTermHandler(){	LOG << "Termination Handler." << endl;	cout << "Termination Handler." << endl;	return false;}SignalsMask BasicCoach::signalsMask(){	SignalsMask result = SIG_INT | SIG_KILL | SIG_QUIT | SIG_SEGV | SIG_TERM;	// if (online)		result |= SIG_ALRM | SIG_IO;	return result;}void BasicCoach::sigAlrmTiming(long &begin, long &interval){	begin = interval = 10;}void BasicCoach::setConfigDefaults(){	config.add("Agent");	config["Agent"].addGroup("Server");	config["Agent"]["Server"].add("HostName","localhost");	config["Agent"]["Server"].add("CoachPort","6000");	config["Agent"]["Server"].add("Version","9.4.5");	config["Agent"]["Server"].add("OfflinePlayer","False");	config["Agent"].addGroup("Public");	config["Agent"]["Public"].add("TeamName","Mersad");	config["Agent"]["Public"].add("IsGoalie","False");	config["Agent"]["Public"].add("UniformNum","0");	config["Agent"].addGroup("AgentLog");	config["Agent"]["AgentLog"].add("LogToFile","False");	config["Agent"]["AgentLog"].add("OffLogToFile","False");	config["Agent"]["AgentLog"].add("InputLogAddress",".");	config["Agent"]["AgentLog"].add("OutputLogAddress",".");}/*void BasicCoach::offlinePlayerManager(){	bool breakWhile = false;	unsigned logHistoryNum = 0;	ifstream inputLog;	LogHistory logHistories[MAX_LOG_HOSTORY];	VirtualConnection *virtualConnection =			dynamic_cast<VirtualConnection *>(connection);	assert(virtualConnection);	VirtualTimer *virtualTimer =			dynamic_cast<VirtualTimer *>(&worldModel->setTimer());	if (config["Agent"]["Public"]["UniformNum"].asInt() <= 0)	{		cout << "Offline Player Manager : you must specify player number." << endl			 << "Type \"--number pnum\" after command." << endl;		return;	}	if (!initOfflinePlayerInputLog(inputLog))	{		cout << "Offline Player Manager : can not open input log file for player "			 << config["Agent"]["Public"]["UniformNum"].asInt() << endl;		return;	}	long prevCycleSizeMS, cycleSizeMS = 0;	while (!breakWhile)	{		// Finding "EndInf" title and making logHistory		logHistoryNum = 0;		prevCycleSizeMS = cycleSizeMS;		while (1)		{			logHistories[logHistoryNum].milliSecond =					parseOfflinePlayerLogLine(inputLog,							logHistories[logHistoryNum].title,							logHistories[logHistoryNum].message);			if (logHistories[logHistoryNum].milliSecond == -1) // end of file			{				setBodyCycleCommandDecidePermitted(true);				setBodyCycleCommandSendPermitted(true);				setHeadCycleCommandDecidePermitted(true);				setHeadCycleCommandSendPermitted(true);				breakWhile = true;				break;			}			else if (logHistories[logHistoryNum].title == "EndInf")			{				if (logHistories[logHistoryNum].message[0] - '0')					setBodyCycleCommandDecidePermitted(true);				else					setBodyCycleCommandDecidePermitted(false);				if (logHistories[logHistoryNum].message[1] - '0')					setBodyCycleCommandSendPermitted(true);				else					setBodyCycleCommandSendPermitted(false);				if (logHistories[logHistoryNum].message[2] - '0')					setHeadCycleCommandDecidePermitted(true);				else					setHeadCycleCommandDecidePermitted(false);				if (logHistories[logHistoryNum].message[3] - '0')					setHeadCycleCommandSendPermitted(true);				else					setHeadCycleCommandSendPermitted(false);				cycleSizeMS = logHistories[logHistoryNum].milliSecond;				break;			}			else				logHistoryNum++;		}		// Running LogHistory		unsigned i;		for (i = 0; i < logHistoryNum; i++)		{			if (logHistories[i].title == "RecStr")			{				virtualConnection->addMessage(logHistories[i].message);				if (logHistories[i].message.substr(1, 10) == "sense_body")					virtualTimer->setCurMS(prevCycleSizeMS);				else					virtualTimer->setCurMS(logHistories[i].milliSecond);				for (i = i + 1; i < logHistoryNum; i++)					if (logHistories[i].title == "RecStr" &&						logHistories[i].message.substr(1, 4) == "hear" &&						logHistories[i].message.find("referee") >							logHistories[i].message.size())							virtualConnection->addMessage(logHistories[i].message);					else					{						i--; // This message is not Hear so I fix my change.						break;					}				sigIOHandler();			}			else if (logHistories[i].title == "EmgSend")			{				virtualTimer->setCurMS(logHistories[i].milliSecond);				sigAlrmHandler();			}		}	}	inputLog.close();	LOG << "End of input offline log." << endl;}bool BasicCoach::initOfflinePlayerInputLog(ifstream &inputLog){	ostringstream ss;		if (config["Agent"]["Public"]["UniformNum"].asInt() < 10)		ss << config["Agent"]["AgentLog"]["InputLogAddress"].asString()			<< "/" << config["Agent"]["Public"]["TeamName"].asString()			<< config["Agent"]["Public"]["UniformNum"].asInt()			<< ".log.off.in";	else		ss << config["Agent"]["AgentLog"]["InputLogAddress"].asString()			<< "/" << config["Agent"]["Public"]["TeamName"].asString()			<< (char)(config["Agent"]["Public"]["UniformNum"].asInt() - 10 + 'A')			<< ".log.off.in";		inputLog.open(ss.str().c_str());	return inputLog;}int BasicCoach::parseOfflinePlayerLogLine(ifstream &inputLog,		string &title, string &message){	string line;	string temp;	int milliSecond;		if (getline(inputLog, line))	{		unsigned colon = line.find(':');		istringstream ss(line.substr(0, colon));		ss >> milliSecond >> temp >> title;		message = line.substr(colon + 2);		return milliSecond;	}	return -1;}*/void BasicCoach::initOnlineConnection(){	Command * init = NULL;	int port = -1;	if (isTrainer) {//		cerr << "Running as trainer...";		init = new TrainerInitCommand (AT_BASIC_COACH, config["Agent"]["Server"]["Version"].asString()) ;		port = config["Agent"]["Server"]["TrainerPort"].asInt();//		cerr << " .. Attempting connection on port "  << port << " .. ";	} else {//		cerr << "Running as ONLINE coach...";		port = config["Agent"]["Server"]["CoachPort"].asInt();	 	init = new InitCommand(AT_BASIC_COACH,			config["Agent"]["Public"]["TeamName"].asString(), 			config["Agent"]["Server"]["Version"].asString(), false);//		cerr << " .. Attempting connection on port " << port << " .. ";	};	connection = new OnlineConnection(		config["Agent"]["Server"]["HostName"].asString(), port);	connection->send(init);	delete init;}void BasicCoach::closeOnlineConnection(){	Command *bye = new ByeCommand(AT_BASIC_COACH);	connection->send(bye);	delete bye;	delete connection;	connection = NULL;}/*void BasicCoach::initVirtualConnection(){	connection = new VirtualConnection();}void BasicCoach::closeVirtualConnection(){	delete connection;	connection = NULL;}*/// Getting functions/*bool BasicCoach::isBodyCycleCommandDecidePermitted() const{	return bodyCycleCommandDecidePermittedFlag;}bool BasicCoach::isBodyCycleCommandSendPermitted() const{	return bodyCycleCommandSendPermittedFlag;}bool BasicCoach::isHeadCycleCommandDecidePermitted() const{	return headCycleCommandDecidePermittedFlag;}bool BasicCoach::isHeadCycleCommandSendPermitted() const{	return headCycleCommandSendPermittedFlag;}*/const WorldModel &BasicCoach::getWorldModel() const{	return *worldModel;}// Setting functions/*void BasicCoach::setBodyCycleCommandDecidePermitted(bool bodyCycleCommandDecidePermittedFlagArg){	bodyCycleCommandDecidePermittedFlag = bodyCycleCommandDecidePermittedFlagArg;}void BasicCoach::setBodyCycleCommandSendPermitted(bool bodyCycleCommandSendPermittedFlagArg){	bodyCycleCommandSendPermittedFlag = bodyCycleCommandSendPermittedFlagArg;}void BasicCoach::setHeadCycleCommandDecidePermitted(bool headCycleCommandDecidePermittedFlagArg){	headCycleCommandDecidePermittedFlag = headCycleCommandDecidePermittedFlagArg;}void BasicCoach::setHeadCycleCommandSendPermitted(bool headCycleCommandSendPermittedFlagArg){	headCycleCommandSendPermittedFlag = headCycleCommandSendPermittedFlagArg;}*/

⌨️ 快捷键说明

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