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

📄 bodydecision.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: 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 <Logger.h>#include <Defines.h>#include <BodyDecision.h>#include <AdvancedAgent.h>using namespace std;BodyDecision::BodyDecision(const WorldModel *worldModel):		worldModel(worldModel){	command = NULL;}BodyDecision::~BodyDecision(){}void BodyDecision::addAdvancedAction(AdvancedAction *advancedAction,		AdvancedActionWeights weight, int quickLevel){	advancedActions.push_back(advancedAction);	weights.push_back(weight);	quickLevels.push_back(quickLevel);	values.push_back(NOVALUE);}void BodyDecision::decide(int quickLevel, Form &form, const Library &library){	float curWeight;	float max = -0xFFFF;	unsigned maxer = NOVALUE;//	form.sayForm.decideReset();	LOG << "Decide weighting:" << endl;	for (unsigned i = 0; i < advancedActions.size(); i++)	{		if (quickLevels[i] == -1) // this advanced action is turned off.			continue;		if (quickLevels[i] >= quickLevel) // we have enough time.			values[i] = advancedActions[i]->getValue(library);		else if (values[i] == NOVALUE)			continue;		LOG << "\tAdvancedAction[" << i << "]:"			<< " Value:" << values[i];		curWeight = weights[i].rate * pow(values[i], weights[i].power) +				weights[i].alpha;		LOG << " Weight:" << curWeight << endl;		if (quickLevels[i] >= 2 && values[i] >= AD_ALWAYS_RUN_VALUE) // quick levels more than 2 are quantomic.		{			maxer = i;			break;		}		if (curWeight > max)		{			maxer = i;			max = curWeight;		}	}	if (maxer != NOVALUE)	{		advancedActions[maxer]->execute(form, library);		command = advancedActions[maxer]->getCommand();		return;	}	command = NULL;}Command *BodyDecision::getCommand(){	return command;}void BodyDecision::resetWeights(){	for (unsigned i = 0; i < advancedActions.size(); i++)	{		weights[i].rate = 1;		weights[i].power = 1;		weights[i].alpha = 0;	}}void BodyDecision::resetValues(){	for (unsigned i = 0; i < advancedActions.size(); i++)		values[i] = NOVALUE;}void BodyDecision::resetQuickLevels(){	for (unsigned i = 0; i < advancedActions.size(); i++)		quickLevels[i] = -1; // turning all advanced actions off.}void BodyDecision::updateAfterSenseBody(){	resetValues();}

⌨️ 快捷键说明

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