📄 nonplayondecision.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: Mohammad Salehe * * Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. * For more information please read README file.*/#include <cassert>#include <cmath>#include <Logger.h>#include <Types.h>#include <Command.h>#include <BasicTurn.h>#include <BasicKick.h>#include <BasicDash.h>#include <Pass.h>#include <Shoot.h>#include <NonPlayOn.h>#include <Offense.h>#include <Defense.h>#include <NonPlayOnDecision.h>#include <Intercept.h>#include <GoaliePositioning.h>#include <AdvancedAgent.h>using namespace std;#define NON_PLAY_ON_DECISION_LOG1#define NON_PLAY_ON_DECISION_LOG2#define FREE_KICK_ADVICER 5#define GOTOKICK_NUM 0#define BACKBALL_NUM 1#define BEFOREKICKOFF_NUM 2#define DEFENSE_NUM 3#define OFFENSE_NUM 4 #define PASS_NUM 5#define SHOOT_NUM 6#define INTERCEPT_NUM 7#define GOALIE_POSITIONING_NUM 8#define GOALIE_CATCH_OFFENSE_NUM 9// NOTE : All of player numbers in this file are Uniform Numbers (not Post Numbers)NonPlayOnDecision::NonPlayOnDecision(const WorldModel *worldModel): BodyDecision(worldModel){ addAdvancedAction(new NonPlayOnGotoKick(worldModel), //0 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new NonPlayOnBackBall(worldModel), //1 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new NonPlayOnBeforeKickOff(worldModel), //2 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Defense(worldModel), //3 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Offense(worldModel), //4 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Pass(worldModel), //5 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Shoot(worldModel), //6 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Intercept(worldModel), //7 AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new GoaliePositioning(worldModel), //8 AdvancedActionWeights(0, 1, 1), 0); addAdvancedAction(new GoalieCatchOffense(worldModel), //9 AdvancedActionWeights(0, 1, 1), 0); dynamic_cast<Pass *>(advancedActions[PASS_NUM])-> setCurKickCalculate(&worldModel->getCurKickCalculate());}NonPlayOnDecision::~NonPlayOnDecision(){}void NonPlayOnDecision::decide(int quickLevel, Form &form, const Library &library){ Point positions[11];#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NonPlayOnDecision" << endl;#endif form.headForm.tnMode = TNM_LOOK_NORMALLY; form.sayForm.reset(); if (DefenseOffenseChoice() == 0) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NonPlayOnDecision Returning empty" << endl;#endif command = new EmptyCommand(AT_NONE); return; } resetQuickLevels(); command = NULL; getCurrentHomePoints(positions, library); switch (worldModel->getPlayMode()) { case PM_BEFORE_KICK_OFF: case PM_GOAL: case PM_GOAL_OPP:#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE1" << endl;#endif if (selectBallKicker(positions) == 1) dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(false); else dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(true); advancedActions[BEFOREKICKOFF_NUM]->getValue(library); advancedActions[BEFOREKICKOFF_NUM]->execute(form, library); command = advancedActions[BEFOREKICKOFF_NUM]->getCommand(); return; case PM_KICK_OFF: #ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2" << endl;#endif if (selectBallKicker(positions) == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2 1" << endl;#endif if (selectBallKicker(positions) == 1) dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(false); else dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(true); advancedActions[BEFOREKICKOFF_NUM]->getValue(library); advancedActions[BEFOREKICKOFF_NUM]->execute(form, library); command = advancedActions[BEFOREKICKOFF_NUM]->getCommand(); return; } else { form.headForm.tnMode = TNM_LOOK_CAREFULLY;#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2 2" << endl;#endif advancedActions[GOTOKICK_NUM]->getValue(library); if (dynamic_cast<NonPlayOnGotoKick *>(advancedActions[GOTOKICK_NUM]) ->getStatus() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2 3" << endl;#endif advancedActions[GOTOKICK_NUM]->execute(form, library); command = advancedActions[GOTOKICK_NUM]->getCommand(); return; } else if (backBallChoice() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2 4" << endl;#endif // No need to the following line if (advancedActions[GOTOKICK_NUM]->getCommand()) delete advancedActions[GOTOKICK_NUM]->getCommand(); quickLevels[PASS_NUM] = 1; quickLevels[SHOOT_NUM] = 1; form.sayForm.reset(); BodyDecision::decide(quickLevel, form, library); return; } else {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE2 5" << endl;#endif // No need to the following line if (advancedActions[GOTOKICK_NUM]->getCommand()) delete advancedActions[GOTOKICK_NUM]->getCommand(); advancedActions[BACKBALL_NUM]->getValue(library); advancedActions[BACKBALL_NUM]->execute(form, library); command = advancedActions[BACKBALL_NUM]->getCommand(); return; } } break; case PM_KICK_OFF_OPP:#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE3" << endl;#endif if (selectBallKicker(positions) == 1) dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(false); else dynamic_cast<NonPlayOnBeforeKickOff *>(advancedActions[BEFOREKICKOFF_NUM])-> setIsKicker(true); advancedActions[BEFOREKICKOFF_NUM]->getValue(library); advancedActions[BEFOREKICKOFF_NUM]->execute(form, library); command = advancedActions[BEFOREKICKOFF_NUM]->getCommand(); return; break; case PM_FREE_KICK: case PM_KICK_IN: case PM_CORNER_KICK:#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4" << endl;#endif selectBallKickerSay(positions, form); if (selectBallKicker(positions) == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 1" << endl;#endif if (worldModel->getBody().isGoalie()) { advancedActions[GOALIE_POSITIONING_NUM]->getValue(library); advancedActions[GOALIE_POSITIONING_NUM]->execute(form, library); command = advancedActions[GOALIE_POSITIONING_NUM]->getCommand(); return; } else { if (!worldModel->getBody().isGoalie() && worldModel->getPlayMode() == PM_FREE_KICK && worldModel->getVirtualPlayMode() == VPM_GOALIE_CATCH_BALL) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 1 2" << endl;#endif advancedActions[GOALIE_CATCH_OFFENSE_NUM]->getValue(library); advancedActions[GOALIE_CATCH_OFFENSE_NUM]-> execute(form, library); command = advancedActions[GOALIE_CATCH_OFFENSE_NUM]-> getCommand(); return; } advancedActions[OFFENSE_NUM]->getValue(library); advancedActions[OFFENSE_NUM]->execute(form, library); command = advancedActions[OFFENSE_NUM]->getCommand(); return; } } else { form.headForm.tnMode = TNM_LOOK_CAREFULLY;#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 2" << endl;#endif if (worldModel->getBody().isGoalie() && worldModel->getPlayMode() == PM_FREE_KICK && worldModel->getVirtualPlayMode() == VPM_GOALIE_CATCH_BALL) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 3 1" << endl;#endif if (backBallChoice() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 3 1 1" << endl;#endif advancedActions[GOALIE_CATCH_OFFENSE_NUM]->getValue(library); advancedActions[GOALIE_CATCH_OFFENSE_NUM]->execute(form, library); if (dynamic_cast<GoalieCatchOffense *> (advancedActions[GOALIE_CATCH_OFFENSE_NUM])-> getStatus() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 3.2" << endl;#endif command = advancedActions[GOALIE_CATCH_OFFENSE_NUM]-> getCommand(); return; } else { if (worldModel->getPlayMode() == PM_FREE_KICK && worldModel->getVirtualPlayMode() == VPM_GOALIE_CATCH_BALL) { Point virtualPassPoint(-33, 28); LOG << "NPP FKick to " << virtualPassPoint << endl; command = FastKickToPoint(AT_PASS, virtualPassPoint, worldModel->getBall(), worldModel->getBody()). getCommand(); LOG << "NPO cmd:" << command->toString() << endl; form.sayForm.interceptNum = 6; form.sayForm.beforePassSay = true; form.sayForm.freeKickSay = false; return; } delete advancedActions[GOALIE_CATCH_OFFENSE_NUM]->getCommand(); quickLevels[PASS_NUM] = 1; form.sayForm.reset(); BodyDecision::decide(quickLevel, form, library); return; } } else {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 3 1 2" << endl;#endif advancedActions[BACKBALL_NUM]->getValue(library); advancedActions[BACKBALL_NUM]->execute(form, library); command = advancedActions[BACKBALL_NUM]->getCommand(); return; } break; } advancedActions[GOTOKICK_NUM]->getValue(library); if (dynamic_cast<NonPlayOnGotoKick *>(advancedActions[GOTOKICK_NUM]) ->getStatus() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 3" << endl;#endif advancedActions[GOTOKICK_NUM]->execute(form, library); command = advancedActions[GOTOKICK_NUM]->getCommand(); return; } else if (backBallChoice() == 1) {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 4" << endl;#endif // No need to the following line if (advancedActions[GOTOKICK_NUM]->getCommand()) delete advancedActions[GOTOKICK_NUM]->getCommand(); quickLevels[PASS_NUM] = 1; quickLevels[SHOOT_NUM] = 1; if (worldModel->getPlayMode() == PM_FREE_KICK && worldModel->getVirtualPlayMode() == VPM_INDIRECT_FREE_KICK) { quickLevels[SHOOT_NUM] = -1; } form.sayForm.reset(); BodyDecision::decide(quickLevel, form, library); return; } else {#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE4 5" << endl;#endif // No need to the following line if (advancedActions[GOTOKICK_NUM]->getCommand()) delete advancedActions[GOTOKICK_NUM]->getCommand(); advancedActions[BACKBALL_NUM]->getValue(library); advancedActions[BACKBALL_NUM]->execute(form, library); command = advancedActions[BACKBALL_NUM]->getCommand(); return; } } break; case PM_FREE_KICK_OPP: case PM_KICK_IN_OPP: case PM_CORNER_KICK_OPP:#ifdef NON_PLAY_ON_DECISION_LOG1LOG << "NONPLAYON: MODE5" << endl;#endif if (worldModel->getBody().isGoalie()) { advancedActions[GOALIE_POSITIONING_NUM]->getValue(library); advancedActions[GOALIE_POSITIONING_NUM]->execute(form, library); command = advancedActions[GOALIE_POSITIONING_NUM]->getCommand(); return; } else { advancedActions[DEFENSE_NUM]->getValue(library); advancedActions[DEFENSE_NUM]->execute(form, library); command = advancedActions[DEFENSE_NUM]->getCommand(); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -