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

📄 advancedagent.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 *  Modified by: Mohammad Salehe *  Released on Friday 1 April 2005 by Mersad RoboCup Team. *  For more information please read README file.*/#include <cassert>#include <Pass.h>#include <Shoot.h>#include <Logger.h>#include <Offense.h>#include <Defense.h>#include <Dribble.h>#include <Command.h>#include <Intercept.h>#include <SRPDribble.h>#include <AdvancedAgent.h>#define GOALIE_UNIFORM_NUM 1using namespace std;AdvancedAgent::AdvancedAgent(int argc, char **argv): SyncedAgent(argc, argv),		positioning(worldModel),		headDecision(this), sayDecision(worldModel),		pointToDecision(worldModel),		groupWorks(worldModel, sayDecision.setSayFlags(),			headDecision.getModeRef(), positioning),		nonPlayOnDecision(worldModel, positioning,			sayDecision.setSayFlags(), headDecision.getModeRef()),		penaltyDecision(worldModel, sayDecision.setSayFlags(),			headDecision.getModeRef(), positioning),		goaliePlayOnDecision(worldModel, sayDecision.setSayFlags(),			headDecision.getModeRef()),		withBallPlayOnDecision(worldModel, sayDecision.setSayFlags(),			headDecision.getModeRef()),		withoutBallPlayOnDecision(worldModel, sayDecision.setSayFlags(),			headDecision.getModeRef(), positioning){}AdvancedAgent::~AdvancedAgent(){}void AdvancedAgent::senseBody(const SExpression &exp){	SyncedAgent::senseBody(exp);	nonPlayOnDecision.updateAfterSenseBody();	withBallPlayOnDecision.updateAfterSenseBody();	withoutBallPlayOnDecision.updateAfterSenseBody();	groupWorks.updateAfterSenseBody();	lastDecide = curDecide;	curDecide = DT_NONE;	sayDecision.setSayFlags().reset();/*	if (lastDecide == DT_BLOCK ||		lastDecide == DT_INTERCEPT ||		lastDecide == DT_DRIBBLE_INTERCEPT ||		lastDecide == DT_GOALIE_INTERCEPT)		worldModel->setBall().setUpdateByHearPermitted(false);	else*/		worldModel->setBall().setUpdateByHearPermitted(true);}void AdvancedAgent::see(const SExpression &exp){	SyncedAgent::see(exp);	worldModel->updateCurInterCalculate();	worldModel->updateBallStatus();}void AdvancedAgent::hear(const SExpression &exp){	SyncedAgent::hear(exp);	SExpAtomic *at;	at = dynamic_cast<SExpAtomic *>(exp[2]);	assert(at);	if (at->toString() == "referee")	{		groupWorks.resetByChangePlayMode();		if (penaltyDecision.checkPlayMode() == 1)		{			LOG << "AdvancedAgent.PENALTY: Reversing Field" << endl;			if (!worldModel->getBody().isGoalie())			{				LOG << "Reverse. You are player" << endl;				worldModel->setFieldData().setPenaltySideRate(-1);			}			else				LOG << "NO! Don't Reverse. You are goalie" << endl;  		}		else if (penaltyDecision.checkPlayMode() == 2)		{			LOG << "AdvancedAgent.PENALTY: -1 Reversing Field" << endl;			if (worldModel->getBody().isGoalie())			{				LOG << "Reverse. You are goalie" << endl;  				worldModel->setFieldData().setPenaltySideRate(-1);			}			else				LOG << "NO! Don't Reverse. You are player" << endl;   		}	}	if (worldModel->getHearedHeader() == 'A' ||		worldModel->getHearedHeader() == 'B')		groupWorks.setInterceptNum(worldModel->getHearedInterceptNum());	else if (worldModel->getHearedHeader() == 'Y' ||			worldModel->getHearedHeader() == 'Z')	{		groupWorks.changeInterceptNumByHear(				worldModel->getHearedSender(),				worldModel->getHearedInterceptNum());		groupWorks.setHearedRequestPassNum(				worldModel->getHearedRequestPassNum());		groupWorks.setHearedRequestPassSender(				worldModel->getHearedSender());		groupWorks.setHearedRequestPassTime(worldModel->getCurTime());	}	if ((worldModel->getHearedHeader() == 'A' ||		 worldModel->getHearedHeader() == 'B') &&		worldModel->getHearedSender() == GOALIE_UNIFORM_NUM &&		worldModel->getHearedInterceptNum() != GOALIE_UNIFORM_NUM &&	    worldModel->getPlayMode() == PM_GOAL_KICK)	{		if (worldModel->getPlayModeRemainCycle() < 199)		{			LOG << "GOAL_KICK --> GOAL_KICK_TAKEN" << endl;			worldModel->setVirtualPlayMode(VPM_GOAL_KICK_TAKEN);		}		else		{			LOG << "GOAL_KICK --> NO CHANGE TO PLAY MODE" << endl;		}	}	if (worldModel->getMustAttention())	{		sayDecision.setSayFlags().attentionNum =				worldModel->getHearedInterceptNum();	}}bool AdvancedAgent::bodyDecide(int quickLevel){	LOG << "AdvancedAgent::bodyDecide" << endl;	worldModel->updateCurInterCalculate();	worldModel->updateBallStatus();	groupWorks.updateInterceptNum();	positioning.setHomePoints();	bool kickPermission = true;	if (worldModel->getBallStatus() == BS_KICKABLE_BODY_TMM &&		(lastDecide == DT_NONE ||		 lastDecide == DT_OFFENSE ||		 lastDecide == DT_DEFENSE ||		 lastDecide == DT_INTERCEPT ||		 lastDecide == DT_DRIBBLE_INTERCEPT ||		 lastDecide == DT_LOOK_FOR_BALL ||		 lastDecide == DT_BLOCK))		kickPermission = false;	if (worldModel->getPlayMode() == PM_PLAY_ON ||		(worldModel->getPlayMode() == PM_GOAL_KICK &&		 worldModel->getVirtualPlayMode() == VPM_GOAL_KICK_TAKEN))	{		if (!worldModel->getBall().isValid())		{			LOG << "Looking for ball." << endl;			headDecision.setMode(TNM_LOOK_NORMALLY);			curDecide = DT_LOOK_FOR_BALL;			bodyCycleCommand = new TurnCommand(45);		}		else if (worldModel->getBody().isGoalie())		{			curDecide = goaliePlayOnDecision.decide(quickLevel, lastDecide);			bodyCycleCommand = goaliePlayOnDecision.getCommand();		}		else if (worldModel->isBallKickable() && kickPermission)		{			if (quickLevel <= 0)				worldModel->updateCurKickCalculate();			curDecide = withBallPlayOnDecision.decide(quickLevel, lastDecide);			bodyCycleCommand = withBallPlayOnDecision.getCommand();			groupWorks.setLastWithBallDecideValid(true);		}		else		{			groupWorks.checkForLastWithBallDecideValid();			curDecide = withoutBallPlayOnDecision.decide(quickLevel,					lastDecide, groupWorks.getWithoutBallSelection(					withBallPlayOnDecision.getLastWithBallDecide()));			bodyCycleCommand = withoutBallPlayOnDecision.getCommand();		}		groupWorks.decide();	}	else if (worldModel->getPlayMode() == PM_PENALTY_SETUP ||			worldModel->getPlayMode() == PM_PENALTY_SETUP_OPP ||			worldModel->getPlayMode() == PM_PENALTY_READY ||			worldModel->getPlayMode() == PM_PENALTY_READY_OPP)	{		if (!worldModel->getBall().isValid())		{			LOG << "Looking for ball." << endl;			headDecision.setMode(TNM_LOOK_NORMALLY);			curDecide = DT_LOOK_FOR_BALL;			bodyCycleCommand = new TurnCommand(45);		}		else		{				if (quickLevel <= 0 && worldModel->isBallKickable())			{				LOG << "PENALTY: updateCurKickCalculate() ..." << endl;				worldModel->updateCurKickCalculate();				LOG << "PENALTY: updated." << endl;			}			curDecide = penaltyDecision.decide(quickLevel, lastDecide);			bodyCycleCommand = penaltyDecision.getCommand();		}	}	else	{		if (!worldModel->getBall().isValid())		{			LOG << "Looking for ball." << endl;			headDecision.setMode(TNM_LOOK_NORMALLY);			curDecide = DT_LOOK_FOR_BALL;			bodyCycleCommand = new TurnCommand(45);		}		else		{			if (quickLevel <= 0 && worldModel->isBallKickable())				worldModel->updateCurKickCalculate();			curDecide = nonPlayOnDecision.decide(quickLevel);			bodyCycleCommand = nonPlayOnDecision.getCommand();		}	}	if (!bodyCycleCommand)	{		curDecide = DT_NONE;		bodyCycleCommand = new EmptyCommand();	}	if (worldModel->getBall().getAbsVec().getMagnitude() < 7.5)		return true;	return false;}void AdvancedAgent::headDecide(){	headDecision.decide(bodyCycleCommand);	headCycleCommand = headDecision.getTurnNeckCommand();	changeViewCycleCommand = headDecision.getChangeViewCommand();}void AdvancedAgent::sayDecide(){	groupWorks.updateInterceptNum();	sayDecision.decide(bodyCycleCommand,			groupWorks.getInterceptNumForSay());	sayCycleCommand = sayDecision.getSayCommand();	attentionCycleCommand = sayDecision.getAttentionCommand();}void AdvancedAgent::pointToDecide(){	pointToDecision.decide(headCycleCommand);	pointToCycleCommand = pointToDecision.getPointToCommand();}

⌨️ 快捷键说明

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