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

📄 saydecision.cpp

📁 mersad源码 03年robocup 季军 可以研究一下大家
💻 CPP
字号:
/* *  Copyright 2002-2004, Mersad Team, Allame 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. * *  Created by: Ahmad Boorghany *  Released on Friday 1 April 2005 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 SayDecisionFlagsSayDecisionFlags::SayDecisionFlags(){	reset();}void SayDecisionFlags::reset(){	beforePassSay = false;	suggestPassSay = false;	interceptNum = 0;	attentionNum = 0;	requestPassSayNum = 0;	freeKickSay = false;}void SayDecisionFlags::decideReset(){	beforePassSay = false;	suggestPassSay = false;	interceptNum = 0;	requestPassSayNum = 0;	freeKickSay = false;}// class SayDecisionSayDecision::SayDecision(const WorldModel *worldModel):		worldModel(worldModel){}SayDecision::~SayDecision(){}SayDecisionFlags &SayDecision::setSayFlags(){	return sayFlags;}SayDecisionFlags &SayDecision::getSayFlags(){	return sayFlags;}void SayDecision::decide(const Command *bodyCycleCommand,		unsigned gwInterceptNum){	LOG << "SayDecision::decide" << endl;	unsigned attentionNum;	if (sayFlags.attentionNum)		attentionNum = sayFlags.attentionNum;	else if (gwInterceptNum != 0 &&		gwInterceptNum != worldModel->getBody().getUniNum())	{		if (gwInterceptNum <= FULL_PLAYERS_NUM)			attentionNum = gwInterceptNum;		else			attentionNum = (gwInterceptNum - FULL_PLAYERS_NUM);	}	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(TID_TEAMMATE, attentionNum);	if (sayFlags.freeKickSay)	{		sayFreeKick();	}		else if (sayFlags.beforePassSay)	{		unsigned playerNum = sayFlags.interceptNum;		if (playerNum > 11)			playerNum -= 11;/*		if (playerNum !=  0 &&			worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).					getPosDeviation() < 4 &&			fabs(worldModel->getBall().getPos().getX() -				worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).						getPos().getX()) < RELATED_PLAYER_X_RANGE &&			fabs(worldModel->getBall().getPos().getY() -				worldModel->getFullPlayer(TID_TEAMMATE, playerNum - 1).						getPos().getY()) < RELATED_PLAYER_Y_RANGE)			sayBeforePassRelated(bodyCycleCommand);		else*/			sayBeforePass(bodyCycleCommand);	}	else if (sayFlags.suggestPassSay)		saySuggestPass();	else if (getSayRoutinBallPermission())	{		sayFlags.interceptNum = gwInterceptNum;		sayRoutinBall(bodyCycleCommand);	}	else if (sayFlags.requestPassSayNum)	{		sayFlags.interceptNum = gwInterceptNum;		sayRequestPassSayWithoutBall(bodyCycleCommand);	}	else		sayCommand = new EmptyCommand();}void SayDecision::sayBeforePass(const Command *bodyCycleCommand){	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[sayFlags.interceptNum];	sayCommand = new SayCommand(str);}void SayDecision::sayBeforePassRelated(const Command *bodyCycleCommand){	string str = "B"; // BeforePass say flag	unsigned playerNum = sayFlags.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[sayFlags.interceptNum];	sayCommand = new SayCommand(str);}void SayDecision::sayRoutinBall(const Command *bodyCycleCommand){	string str = "Z"; // RoutinBall 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[sayFlags.interceptNum];	str += SayEncoding::sayCodeKey[sayFlags.requestPassSayNum];	if (worldModel->isBallKickable())		str += SayEncoding::sayCodeKey[1];	else		str += SayEncoding::sayCodeKey[0];	sayCommand = new SayCommand(str);}void SayDecision::sayRequestPassSayWithoutBall(const Command *bodyCycleCommand){	string str = "Y"; // RoutinBall say without ball flag	str += SayEncoding::sayCodeKey[sayFlags.interceptNum];	str += SayEncoding::sayCodeKey[sayFlags.requestPassSayNum];	if (worldModel->isBallKickable())		str += SayEncoding::sayCodeKey[1];	else		str += SayEncoding::sayCodeKey[0];	sayCommand = new SayCommand(str);}bool SayDecision::getSayRoutinBallPermission(){	if (worldModel->getBall().getSeeTime() == worldModel->getCurTime() &&		worldModel->getBall().getVelSeeTime() == worldModel->getCurTime())		return true;	return false;}void SayDecision::saySuggestPass(){	string str = "C"; // SuggestPass say flag	SayEncoding::encodeObjectVelocity(sayFlags.passSpeed,			sayFlags.passDir, str);	SayEncoding::encodeWeight(sayFlags.passWeight, -50, 150, str);	str += SayEncoding::sayCodeKey[sayFlags.passPlayerNum];	sayCommand = new SayCommand(str);}void SayDecision::sayFreeKick(){	string str = "F"; // freeKick say flag//	LOG << "SayDecision:: sayFreeKick advice number=" << sayFlags.freeKickAdviceNumber << endl;		str += SayEncoding::sayCodeKey[sayFlags.freeKickAdviceNumber];	sayCommand = new SayCommand(str);}Command *SayDecision::getSayCommand(){	return sayCommand;}Command *SayDecision::getAttentionCommand(){	return attentionCommand;}

⌨️ 快捷键说明

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