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

📄 saydecision.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: Ahmad Boorghany * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <cmath>#include <string>#include <Logger.h>#include <Command.h>#include <Defines.h>#include <SayEncoding.h>#include <SayDecision.h>using namespace std;// struct SayDecisionFlagsSayDecisionForm::SayDecisionForm(){	reset();}void SayDecisionForm::reset(){	doRoutinSay = false;	beforePassSay = false;	suggestPassSay = false;	planSay = false;	freeKickSay = false;	planHeader = "";	interceptNum = 0;	attentionNum = 0;	planStatus = 0;	gwInterceptNum = 0;	gwAttentionNum = 0;	planSay = false;	radarSay = false;}/*void SayDecisionForm::decideReset(){	beforePassSay = false;//	suggestPassSay = false; AHMAD	interceptNum = 0;	planStatus = 0;//	requestPassSayNum = 0;	freeKickSay = false;}*/// class SayDecisionSayDecision::SayDecision(const WorldModel *worldModel):		worldModel(worldModel){}SayDecision::~SayDecision(){}void SayDecision::decide(const Command *bodyCycleCommand,		SayDecisionForm &sayForm){	LOG << "SayDecision::decide" << endl;	unsigned attentionNum;	if (sayForm.attentionNum)		attentionNum = sayForm.attentionNum;	else if (sayForm.gwAttentionNum != 0 &&			sayForm.gwAttentionNum != worldModel->getBody().getUniNum())		attentionNum = sayForm.gwAttentionNum;	else	{		float min = 0xFFFF;		unsigned miner = NOVALUE;		for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++)			if (worldModel->getFullPlayer(TID_TEAMMATE, i).isValid() &&				!worldModel->getFullPlayer(TID_TEAMMATE, i).isBody())				if (miner == NOVALUE ||					worldModel->getFullPlayer(TID_TEAMMATE, i).getDistance(						worldModel->getBall()) < min)				{					miner = i;					min = worldModel->getFullPlayer(TID_TEAMMATE, i).getDistance(							worldModel->getBall());				}		if (miner == NOVALUE)			attentionNum = 9;		else			attentionNum = miner + 1;	}	attentionCommand = new AttentionToCommand(AT_SAY_DECISION, TID_TEAMMATE, attentionNum);	if (sayForm.planSay)		sayPlan(sayForm);	else if (sayForm.radarSay)		sayRadar(sayForm);	else if (sayForm.freeKickSay)	{		sayFreeKick(sayForm);	}		else if (sayForm.beforePassSay)	{		unsigned playerNum = sayForm.interceptNum;		if (playerNum > 11)			playerNum -= 11;/*		if (playerNum !=  0 &&			worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).					getPosDeviation() < 4 &&			abs(worldModel->getBall().getPos().getX() -				worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).						getPos().getX()) < RELATED_PLAYER_X_RANGE &&			abs(worldModel->getBall().getPos().getY() -				worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).						getPos().getY()) < RELATED_PLAYER_Y_RANGE)			sayBeforePassRelated(bodyCycleCommand);		else*/			sayBeforePass(bodyCycleCommand, sayForm);	}	else if (sayForm.suggestPassSay)		saySuggestPass(sayForm);	else if (getSayRoutinBallPermission(sayForm))	{		sayForm.interceptNum = sayForm.gwInterceptNum;		sayRoutinBall(bodyCycleCommand, sayForm);	}/*	else if (sayForm.requestPassSayNum)	{		sayForm.interceptNum = gwInterceptNum;		sayRequestPassSayWithoutBall(bodyCycleCommand);	}*/	else		sayCommand = new EmptyCommand(AT_SAY_DECISION);}void SayDecision::sayBeforePass(const Command *bodyCycleCommand,		const SayDecisionForm &sayForm){	string str = "A"; // BeforePass say flag	Body nextBody(worldModel->getBody());	nextBody.simulateByAction(bodyCycleCommand);	nextBody.simulateByDynamics();	Ball nextBall(worldModel->getBall());	nextBall.simulateByAction(worldModel->getBody(), bodyCycleCommand);	nextBall.simulateByDynamics(nextBody, 1);	SayEncoding::encodeObjectPosition(nextBall.getPos().getX(),			nextBall.getPos().getY(), str);	SayEncoding::encodeObjectVelocity(nextBall.getVel().getMagnitude(),			nextBall.getVel().getDirection(), str);		str += SayEncoding::sayCodeKey[sayForm.interceptNum];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}void SayDecision::sayBeforePassRelated(const Command *bodyCycleCommand,		const SayDecisionForm &sayForm){	string str = "B"; // BeforePass say flag	unsigned playerNum = sayForm.interceptNum;	if (playerNum > 11)		playerNum -= 11;	Player nextPlayer(worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1));	nextPlayer.simulateByDynamics(worldModel->getBody());	Ball nextBall(worldModel->getBall());	nextBall.simulateByAction(worldModel->getBody(), bodyCycleCommand);	nextBall.simulateByDynamics(worldModel->getBody());	SayEncoding::encodeObjectPosition(			nextBall.getPos().getX() - nextPlayer.getPos().getX(),			nextBall.getPos().getY() - nextPlayer.getPos().getY(), str);	SayEncoding::encodeObjectVelocity(nextBall.getVel().getMagnitude(),			nextBall.getVel().getDirection(), str);	str += SayEncoding::sayCodeKey[sayForm.interceptNum];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}void SayDecision::sayRoutinBall(const Command *bodyCycleCommand,		const SayDecisionForm &sayForm){	string str = "Z"; // RoutinBall say flag	Body nextBody(worldModel->getBody());	nextBody.simulateByAction(bodyCycleCommand);	Body speedBody(nextBody); // I need this copy.	nextBody.simulateByDynamics();	Ball nextBall(worldModel->getBall());	nextBall.simulateByAction(worldModel->getBody(), bodyCycleCommand);	nextBall.simulateByDynamics(nextBody, 1);	SayEncoding::encodeObjectPosition(nextBall.getPos().getX(),			nextBall.getPos().getY(), str);	if (worldModel->isBallKickable() && sayForm.interceptNum != 0 &&		worldModel->getBall().getPosDeviation() < 5)	{		SayEncoding::encodeObjectVelocity(				speedBody.getVel().getMagnitude(),				speedBody.getVel().getDirection(), str); // When I have the ball, it's velocity has no meaning.		str += SayEncoding::sayCodeKey[sayForm.interceptNum +					SAY_UPPER_CASE_NUM]; // It means "Khow that I have the ball."	}	else	{		SayEncoding::encodeObjectVelocity(nextBall.getVel().getMagnitude(),				nextBall.getVel().getDirection(), str);		str += SayEncoding::sayCodeKey[sayForm.interceptNum];	}	str += SayEncoding::sayCodeKey[sayForm.planStatus];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}/*void SayDecision::sayRequestPassSayWithoutBall(const Command *bodyCycleCommand){	string str = "Y"; // RoutinBall say without ball flag	str += SayEncoding::sayCodeKey[sayForm.interceptNum];	str += SayEncoding::sayCodeKey[sayForm.requestPassSayNum];	if (worldModel->isBallKickable())		str += SayEncoding::sayCodeKey[1];	else		str += SayEncoding::sayCodeKey[0];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}*/bool SayDecision::getSayRoutinBallPermission(const SayDecisionForm &sayForm){	if ((worldModel->getBall().getSeeTime() == worldModel->getCurTime() &&		 worldModel->getBall().getVelSeeTime() == worldModel->getCurTime()) ||		(worldModel->isBallKickable() &&		 worldModel->getBall().getPosDeviation() < 5) ||		(sayForm.doRoutinSay &&		 worldModel->getBall().getPosDeviation() < 5))		return true;	return false;}void SayDecision::saySuggestPass(const SayDecisionForm &sayForm){	string str = "C"; // SuggestPass say flag	LOG << "A SayDecision::saySuggestPass" << endl;	LOG << "A speed dir weight num: "		<< sayForm.passSpeed << " "		<< sayForm.passDir << " "		<< sayForm.passWeight << " "		<< sayForm.passPlayerNum << endl;	SayEncoding::encodeObjectVelocity(sayForm.passSpeed,			sayForm.passDir, str);	SayEncoding::encodeWeight(sayForm.passWeight, -50, 150, str);	str += SayEncoding::sayCodeKey[sayForm.passPlayerNum];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}void SayDecision::sayFreeKick(const SayDecisionForm &sayForm){	string str = "F"; // freeKick say flag//	LOG << "SayDecision:: sayFreeKick advice number=" << sayForm.freeKickAdviceNumber << endl;	str += SayEncoding::sayCodeKey[sayForm.freeKickAdviceNumber];	sayCommand = new SayCommand(AT_SAY_DECISION, str);}void SayDecision::sayPlan(const SayDecisionForm &sayForm){	string str = sayForm.planHeader; // Plan say flag	LOG << "SayDecision::sayPlan" << endl;	str += sayForm.planInfo;	sayCommand = new SayCommand(AT_SAY_DECISION, str);}void SayDecision::sayRadar(const SayDecisionForm &sayForm){	LOG << "SayDecision::sayRadar" << endl;	string str = "R"; // Radar say flag	for (int i = 0; i < sayForm.radarPlayersNum; i++)	{		LOG << "\tPlayer " << i << " ID: " << sayForm.ids[i]			<< " Mag: " << sayForm.radarPlayers[i].getMagnitude()			<< " Dir: " << sayForm.radarPlayers[i].getDirection() << endl;		SayEncoding::encodeRadarObject(sayForm.ids[i],			sayForm.radarPlayers[i].getMagnitude(),			sayForm.radarPlayers[i].getDirection(),  str);	}		sayCommand = new SayCommand(AT_SAY_DECISION, str);}Command *SayDecision::getSayCommand(){	return sayCommand;}Command *SayDecision::getAttentionCommand(){	return attentionCommand;}

⌨️ 快捷键说明

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