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

📄 movetoforwardplan.cpp

📁 2006年世界杯足球赛2D仿真组第16名的源代码。在此代码上随便改改
💻 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: Sassan Haradji * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <cmath>#include <AdvancedAgent.h>#include <MoveToForwardPlan.h>#include <DribblePlan.h>#include <SRPDribblePlan.h>#include <PassPlan.h>#include <InterceptPlan.h>#include <OffensePosPlan.h>#include <Logger.h>#include <Basics.h>using namespace std;using namespace Basics;MoveToForwardPlan::MoveToForwardPlan(const WorldModel *wm, Form &form,		const Library &library, float security):		Plan("MoveToForward", wm, form, library), security(security){}MoveToForwardPlan::~MoveToForwardPlan(){}void MoveToForwardPlan::decide(){	LOG << "MoveToForwardPlan::decide" << endl;	Plan::decide();	if (wm->isBallKickable())	{		vector<float> successRates;		vector<Plan*> tempPlans;		successRates.push_back(reRate(wm->getSecurityStatus(wm->getBody(), .55, .65),				0, security * 3, 0, .13));		LOG << "Dribble has " << wm->getSecurityStatus(wm->getBody(), .55, 65)				<< " security" << endl;		tempPlans.push_back(new DribblePlan(wm, form, library));		successRates.push_back(reRate(wm->getSecurityStatus(wm->getBody(), .06, 1),				0, security * 6, -.3, .00));		LOG << "SRPDribble has " << wm->getSecurityStatus(wm->getBody(), .06, 1)				<< " security" << endl;		tempPlans.push_back(new SRPDribblePlan(wm, form, library));		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .5, .5), 0,					security * 3.5, 0, .1));			if (i > 4 && i < 10)				successRates[i] -= .02;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_SECUREBALL, i, -180, 180, -180, 180));			LOG << "Secure Pass To Player " << i << " has "					<< wm->getSecurityStatus(wm->getFullPlayer(TID_TEAMMATE, i - 1))					<< " security" << endl;		}		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .35, .6), 0,					security * 5, 0, .12));			if (i > 4 && i < 10)				successRates[i + 10] -= .07;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_OFFENSE, i, -180, 180, -180, 180));			LOG << "Offense Pass To Player " << i << " has "					<< wm->getSecurityStatus(wm->getFullPlayer(TID_TEAMMATE, i - 1))					<< " security" << endl;		}		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .2, .6), 0,					security * 7, 0, .09));			if (i > 4 && i < 10)				successRates[i + 20] -= .1;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_BREAKOFFSIDE, i, -180, 180, -180, 180));			LOG << "BreakOffside Pass To Player " << i << " has "					<< wm->getSecurityStatus(wm->getFullPlayer(TID_TEAMMATE, i - 1))					<< " security" << endl;		}		Plan * bestPlan = NULL;		double bestSuccessRate = .24;		for (unsigned i = 0; i < tempPlans.size(); i++)		{			LOG << "Plan " << tempPlans[i]->getName() << " has "					<< tempPlans[i]->successRate() + successRates[i] << " successRate"					<< "(" << tempPlans[i]->successRate() << " real successRate, "					<< successRates[i] << " added successRate)"					<< endl;			if (tempPlans[i]->successRate() + successRates[i] >					bestSuccessRate || bestPlan == NULL)			{				bestPlan = tempPlans[i];				bestSuccessRate = tempPlans[i]->successRate() + successRates[i];			}		}			Plan* j;		for (vector<Plan*>::iterator i = tempPlans.begin(); i != tempPlans.end();)		{			j = *i;			i++;			if (bestPlan != j)				delete j;		}		startPlan(bestPlan);		LOG << name << " Plan WARNING!!! : "				<< "All WithBall Plans Finished Without Return Any Command." << endl;		LOG << name << " Plan : "				<< "Now Run Dribble Plan Without Check SuccessRate or isFinished"				<< "(Urgent State)." << endl;		DribblePlan dribblePlan(wm, form, library);		dribblePlan.decide();	}	else	{		if (library.gwSelection == WOBS_INTERCEPT)			startPlan(new InterceptPlan(wm, form, library));		startPlan(new OffensePosPlan(wm, form, library));	}}double MoveToForwardPlan::successRate(){	return 1.0;}bool MoveToForwardPlan::isFinished(){	if (!wm->isBallKickable()) return false;	vector<float> successRates;	vector<Plan*> tempPlans;	successRates.push_back(reRate(wm->getSecurityStatus(wm->getBody(), .55, .65),			0, security * 3, 0, .13));	tempPlans.push_back(new DribblePlan(wm, form, library));	successRates.push_back(reRate(wm->getSecurityStatus(wm->getBody(), .06, .1),			0, security * 5, -.03, .06));	tempPlans.push_back(new SRPDribblePlan(wm, form, library));		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .5, .5), 0,					security * 3.5, 0, .1));			if (i > 4 && i < 10)				successRates[i] -= .02;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_SECUREBALL, i, -180, 180, -180, 180));		}		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .35, .6), 0,					security * 5, 0, .12));			if (i > 4 && i < 10)				successRates[i + 10] -= .07;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_OFFENSE, i, -180, 180, -180, 180));		}		for (unsigned i = 2; i < 12; i++)		{			successRates.push_back(reRate(wm->getSecurityStatus(					wm->getFullPlayer(TID_TEAMMATE, i - 1), .2, .6), 0,					security * 7, 0, .09));			if (i > 4 && i < 10)				successRates[i + 20] -= .1;			tempPlans.push_back(new PassPlan(wm, form, library,					BPM_BREAKOFFSIDE, i, -180, 180, -180, 180));		}	Plan * bestPlan = NULL;	double bestSuccessRate = .24;		for (unsigned i = 0; i < tempPlans.size(); i++)	{		if (tempPlans[i]->successRate() + successRates[i] >				bestSuccessRate || bestPlan == NULL)		{			bestPlan = tempPlans[i];			bestSuccessRate = tempPlans[i]->successRate() + successRates[i];		}	}		bool finished = true;	if (bestPlan != NULL)		finished = false;	Plan* j;	for (vector<Plan*>::iterator i = tempPlans.begin(); i != tempPlans.end();)	{		j = *i;		i++;		delete j;	}	return finished;}

⌨️ 快捷键说明

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