📄 ourtypes.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: Mostafa Rokooey * * Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. * For more information please read README file.*/// LOG << fixed << setprecision(3);#include <OurTypes.h>#include <Defines.h>#include <cassert>#include <Basics.h>#include <Logger.h>using namespace Basics;using namespace std;OurTypes::OurTypes(const CoachWorldModel *worldModel, const CoachWorldModelHistory &worldModelHistory): Task(worldModel, worldModelHistory){ int i; graph = new AssignmentGraph(21); lastChangedTypePlayer = 0; loadOurTypesRates(); for (i = 0; i < 11; i++) changePlayerTypeArray[i] = NOVALUE; ourTypesChangedFlag = false;}bool OurTypes::execute(bool isTrainer){ int i; if (!ourTypesChangedFlag) { setOurTypes(); ourTypesChangedFlag = true; } for (i = 0; i < 11; i++) { if (changePlayerTypeArray[i] == NOVALUE) { if (worldModel->getFullPlayer(TID_TEAMMATE, i).isAlive()) if ((i + 1) != GOALIE_UNIFORM_NUM) { changePlayerTypeArray[i] = getPlayerType(i + 1); changePlayerCommand = getChangeCommand(i + 1, isTrainer); hasChangePlayerCommandFlag = true; LOG << "Player " << i + 1 << "'s type changed to type " << changePlayerTypeArray[i] << " ." << endl; break; } } } if (hasChangePlayerCommandFlag) return true; else return false;}Command *OurTypes::getChangeCommand(int uniNum, bool isTrainer){ Command *cpc; if (isTrainer) { string ourTeam = config["Agent"]["Public"]["TeamName"].asString(); assert(ourTeam != "NULL"); assert(ourTeam != ""); if ((worldModel->getLeftTeam() == ourTeam ) || (worldModel->getRightTeam()== ourTeam)) cpc = new TrainerChangePlayerCommand(AT_ADVANCED_COACH, ourTeam, uniNum, getPlayerType(uniNum)); else { cpc = new EmptyCommand(AT_ADVANCED_COACH); LOG << "Warning: Empty command sent as change command for trainer" << endl; LOG << " Left team: " << worldModel->getLeftTeam() << " Right Team: " << worldModel->getRightTeam() << " OurTeam: " << ourTeam << endl; } } else cpc = new ChangePlayerCommand(AT_ADVANCED_COACH, uniNum, getPlayerType(uniNum)); return cpc;}void OurTypes::setOurTypes(void){ int i; for (i = 0;i <= 10; i++) if (i < 11 && i != (GOALIE_UNIFORM_NUM - 1)) setPlayerGraphs(i); graph->prepareMaximum(); graph->solve(); for (i = 0;i <= 10; i++) playerTypes[i] = (int)(graph->getAnswerRow(i) / 3);}int OurTypes::getPlayerType(int uniNum){ return playerTypes[uniNum - 1];}void OurTypes::setPlayerGraphs(int uniNum){ int i, j; for(i = 0; i <= 20; i++) { j = (int)(i / 3); graph->setWeight(uniNum, i, (int)getPlayerWeight(uniNum, j)); }}void OurTypes::loadOurTypesRates(void){ config.add("OurTypes"); config["OurTypes"].setByFile("./Configs/OurTypesRates.conf"); playerSpeedMaxRate.main = config["OurTypes"]["MainRates"]["PlayerSpeedMax"][0].asFloat(); staminaIncMaxRate.main = config["OurTypes"]["MainRates"]["StaminaIncMax"][0].asFloat(); playerDecayRate.main = config["OurTypes"]["MainRates"]["PlayerDecay"][0].asFloat(); inertiaMomentRate.main = config["OurTypes"]["MainRates"]["InertiaMoment"][0].asFloat(); dashPowerRateRate.main = config["OurTypes"]["MainRates"]["DashPowerRate"][0].asFloat(); playerSizeRate.main = config["OurTypes"]["MainRates"]["PlayerSize"][0].asFloat(); kickableMarginRate.main = config["OurTypes"]["MainRates"]["KickableMargin"][0].asFloat(); kickRandRate.main = config["OurTypes"]["MainRates"]["KickRand"][0].asFloat(); extraStaminaRate.main = config["OurTypes"]["MainRates"]["ExtraStamina"][0].asFloat(); effortMaxRate.main = config["OurTypes"]["MainRates"]["EffortMax"][0].asFloat(); effortMinRate.main = config["OurTypes"]["MainRates"]["EffortMin"][0].asFloat(); playerSpeedMaxRate.postCB = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][0].asFloat(); staminaIncMaxRate.postCB = config["OurTypes"]["PostRates"]["StaminaIncMax"][0].asFloat(); playerDecayRate.postCB = config["OurTypes"]["PostRates"]["PlayerDecay"][0].asFloat(); inertiaMomentRate.postCB = config["OurTypes"]["PostRates"]["InertiaMoment"][0].asFloat(); dashPowerRateRate.postCB = config["OurTypes"]["PostRates"]["DashPowerRate"][0].asFloat(); playerSizeRate.postCB = config["OurTypes"]["PostRates"]["PlayerSize"][0].asFloat(); kickableMarginRate.postCB = config["OurTypes"]["PostRates"]["KickableMargin"][0].asFloat(); kickRandRate.postCB = config["OurTypes"]["PostRates"]["KickRand"][0].asFloat(); extraStaminaRate.postCB = config["OurTypes"]["PostRates"]["ExtraStamina"][0].asFloat(); effortMaxRate.postCB = config["OurTypes"]["PostRates"]["EffortMax"][0].asFloat(); effortMinRate.postCB = config["OurTypes"]["PostRates"]["EffortMin"][0].asFloat(); playerSpeedMaxRate.postWB = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][1].asFloat(); staminaIncMaxRate.postWB = config["OurTypes"]["PostRates"]["StaminaIncMax"][1].asFloat(); playerDecayRate.postWB = config["OurTypes"]["PostRates"]["PlayerDecay"][1].asFloat(); inertiaMomentRate.postWB = config["OurTypes"]["PostRates"]["InertiaMoment"][1].asFloat(); dashPowerRateRate.postWB = config["OurTypes"]["PostRates"]["DashPowerRate"][1].asFloat(); playerSizeRate.postWB = config["OurTypes"]["PostRates"]["PlayerSize"][1].asFloat(); kickableMarginRate.postWB = config["OurTypes"]["PostRates"]["KickableMargin"][1].asFloat(); kickRandRate.postWB = config["OurTypes"]["PostRates"]["KickRand"][1].asFloat(); extraStaminaRate.postWB = config["OurTypes"]["PostRates"]["ExtraStamina"][1].asFloat(); effortMaxRate.postWB = config["OurTypes"]["PostRates"]["EffortMax"][1].asFloat(); effortMinRate.postWB = config["OurTypes"]["PostRates"]["EffortMin"][1].asFloat(); playerSpeedMaxRate.postCM = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][2].asFloat(); staminaIncMaxRate.postCM = config["OurTypes"]["PostRates"]["StaminaIncMax"][2].asFloat(); playerDecayRate.postCM = config["OurTypes"]["PostRates"]["PlayerDecay"][2].asFloat(); inertiaMomentRate.postCM = config["OurTypes"]["PostRates"]["InertiaMoment"][2].asFloat(); dashPowerRateRate.postCM = config["OurTypes"]["PostRates"]["DashPowerRate"][2].asFloat(); playerSizeRate.postCM = config["OurTypes"]["PostRates"]["PlayerSize"][2].asFloat(); kickableMarginRate.postCM = config["OurTypes"]["PostRates"]["KickableMargin"][2].asFloat(); kickRandRate.postCM = config["OurTypes"]["PostRates"]["KickRand"][2].asFloat(); extraStaminaRate.postCM = config["OurTypes"]["PostRates"]["ExtraStamina"][2].asFloat(); effortMaxRate.postCM = config["OurTypes"]["PostRates"]["EffortMax"][2].asFloat(); effortMinRate.postCM = config["OurTypes"]["PostRates"]["EffortMin"][2].asFloat(); playerSpeedMaxRate.postWM = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][3].asFloat(); staminaIncMaxRate.postWM = config["OurTypes"]["PostRates"]["StaminaIncMax"][3].asFloat(); playerDecayRate.postWM = config["OurTypes"]["PostRates"]["PlayerDecay"][3].asFloat(); inertiaMomentRate.postWM = config["OurTypes"]["PostRates"]["InertiaMoment"][3].asFloat(); dashPowerRateRate.postWM = config["OurTypes"]["PostRates"]["DashPowerRate"][3].asFloat(); playerSizeRate.postWM = config["OurTypes"]["PostRates"]["PlayerSize"][3].asFloat(); kickableMarginRate.postWM = config["OurTypes"]["PostRates"]["KickableMargin"][3].asFloat(); kickRandRate.postWM = config["OurTypes"]["PostRates"]["KickRand"][3].asFloat(); extraStaminaRate.postWM = config["OurTypes"]["PostRates"]["ExtraStamina"][3].asFloat(); effortMaxRate.postWM = config["OurTypes"]["PostRates"]["EffortMax"][3].asFloat(); effortMinRate.postWM = config["OurTypes"]["PostRates"]["EffortMin"][3].asFloat(); playerSpeedMaxRate.postCF = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][4].asFloat(); staminaIncMaxRate.postCF = config["OurTypes"]["PostRates"]["StaminaIncMax"][4].asFloat(); playerDecayRate.postCF = config["OurTypes"]["PostRates"]["PlayerDecay"][4].asFloat(); inertiaMomentRate.postCF = config["OurTypes"]["PostRates"]["InertiaMoment"][4].asFloat(); dashPowerRateRate.postCF = config["OurTypes"]["PostRates"]["DashPowerRate"][4].asFloat(); playerSizeRate.postCF = config["OurTypes"]["PostRates"]["PlayerSize"][4].asFloat(); kickableMarginRate.postCF = config["OurTypes"]["PostRates"]["KickableMargin"][4].asFloat(); kickRandRate.postCF = config["OurTypes"]["PostRates"]["KickRand"][4].asFloat(); extraStaminaRate.postCF = config["OurTypes"]["PostRates"]["ExtraStamina"][4].asFloat(); effortMaxRate.postCF = config["OurTypes"]["PostRates"]["EffortMax"][4].asFloat(); effortMinRate.postCF = config["OurTypes"]["PostRates"]["EffortMin"][4].asFloat(); playerSpeedMaxRate.postWF = config["OurTypes"]["PostRates"]["PlayerSpeedMax"][5].asFloat(); staminaIncMaxRate.postWF = config["OurTypes"]["PostRates"]["StaminaIncMax"][5].asFloat(); playerDecayRate.postWF = config["OurTypes"]["PostRates"]["PlayerDecay"][5].asFloat(); inertiaMomentRate.postWF = config["OurTypes"]["PostRates"]["InertiaMoment"][5].asFloat(); dashPowerRateRate.postWF = config["OurTypes"]["PostRates"]["DashPowerRate"][5].asFloat(); playerSizeRate.postWF = config["OurTypes"]["PostRates"]["PlayerSize"][5].asFloat(); kickableMarginRate.postWF = config["OurTypes"]["PostRates"]["KickableMargin"][5].asFloat(); kickRandRate.postWF = config["OurTypes"]["PostRates"]["KickRand"][5].asFloat(); extraStaminaRate.postWF = config["OurTypes"]["PostRates"]["ExtraStamina"][5].asFloat(); effortMaxRate.postWF = config["OurTypes"]["PostRates"]["EffortMax"][5].asFloat(); effortMinRate.postWF = config["OurTypes"]["PostRates"]["EffortMin"][5].asFloat();}float OurTypes::getPlayerWeight(int uniNum, int playerType){ float weight = 0; if (uniNum == 5 - 1) { if (playerType == 0) return 10000; else return -10000; } uniNum = getStandardUniNum(uniNum + 1); weight += (getPlayerSpeedMaxWeight(uniNum, playerType) * playerSpeedMaxRate.main); weight += (getStaminaIncMaxWeight(uniNum, playerType) * staminaIncMaxRate.main); weight += (getPlayerDecayWeight(uniNum, playerType) * playerDecayRate.main); weight += (getInertiaMomentWeight(uniNum, playerType) * inertiaMomentRate.main); weight += (getDashPowerRateWeight(uniNum, playerType) * dashPowerRateRate.main); weight += (getPlayerSizeWeight(uniNum, playerType) * playerSizeRate.main); weight += (getKickableMarginWeight(uniNum, playerType) * kickableMarginRate.main); weight += (getKickRandWeight(uniNum, playerType) * kickRandRate.main); weight += (getExtraStaminaWeight(uniNum, playerType) * extraStaminaRate.main); weight += (getEffortMaxWeight(uniNum, playerType) * effortMaxRate.main); weight += (getEffortMinWeight(uniNum, playerType) * effortMinRate.main); return weight;}int OurTypes::getStandardUniNum(int uniNum){ switch (Player::uniNumToPostNum(uniNum)) { case GOALIE_UNIFORM_NUM: assert(0); case 2: return 5; case 3: return 3; case 4: return 2; case 5: return 4; case 6: return 7; case 7: return 8; case 8: return 6; case 9: return 9; case 10: return 11; case 11: return 10; } assert(0); return 0;}float OurTypes::getPlayerSpeedMaxWeight(int uniNum, int playerType){ // Range : 1.0 - 1.2 // Type 0 value = 1.2 float weight; float rate = 5; ReRateMode reRateMode = RRM_DIRECT; float value = worldModel->getPlayerType(playerType)["player_speed_max"].asFloat(); float rangeFloor = 1.0; float rangeCeil = 1.2; weight = reRate(value, rangeFloor, rangeCeil, -100, 0, reRateMode); switch (uniNum) { case GOALIE_UNIFORM_NUM: assert(0); case 2: case 3: rate = playerSpeedMaxRate.postCB; break; case 4: case 5: rate = playerSpeedMaxRate.postWB; break; case 6: rate = playerSpeedMaxRate.postCM; break; case 7: case 8: rate = playerSpeedMaxRate.postWM; break; case 9: rate = playerSpeedMaxRate.postCF; break; case 10: case 11: rate = playerSpeedMaxRate.postWF; break; assert(0); } weight *= rate; return weight;}float OurTypes::getStaminaIncMaxWeight(int uniNum, int playerType){ // Range : 25.0 - 45.0 // Type 0 value = 45 float weight; float rate = 5; ReRateMode reRateMode = RRM_DIRECT; float value = worldModel->getPlayerType(playerType)["stamina_inc_max"].asFloat(); float rangeFloor = 25.0; float rangeCeil = 45.0; float badBorder = 30; if (uniNum >= 7 && uniNum <= 9) badBorder = 35; if (value <= badBorder) weight = reRate(value, rangeFloor, rangeCeil, -800, 0, reRateMode); else weight = reRate(value, rangeFloor, rangeCeil, -100, 0, reRateMode); switch (uniNum) { case GOALIE_UNIFORM_NUM: assert(0); case 2: case 3: rate = staminaIncMaxRate.postCB; break; case 4: case 5: rate = staminaIncMaxRate.postWB; break; case 6: rate = staminaIncMaxRate.postCM; break; case 7: case 8: rate = staminaIncMaxRate.postWM; break; case 9: rate = staminaIncMaxRate.postCF; break; case 10: case 11: rate = staminaIncMaxRate.postWF; break; assert(0); } weight *= rate; return weight;}float OurTypes::getPlayerDecayWeight(int uniNum, int playerType){ // Range : 0.4 - 0.6 // Type 0 value = 0.4 float weight; float rate = 5; ReRateMode reRateMode = RRM_DIRECT; float value = worldModel->getPlayerType(playerType)["player_decay"].asFloat(); float rangeFloor = 0.4; float rangeCeil = 0.6; float badBorder = 0.43; if (value <= badBorder) weight = reRate(value, rangeFloor, rangeCeil, -100, 0, reRateMode); else weight = reRate(value, rangeFloor, rangeCeil, 0, 100, reRateMode); switch (uniNum) { case GOALIE_UNIFORM_NUM: assert(0); case 2: case 3: rate = playerDecayRate.postCB; break; case 4: case 5: rate = playerDecayRate.postWB; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -