📄 groupworks.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 * and is modified by: Meisam Vosoughpour, 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 <Degree.h>#include <Logger.h>#include <Defines.h>#include <GroupWorks.h>#include <SyncedAgent.h>#include <AdvancedAgent.h>#include <Basics.h>#include <cassert>using namespace std;using namespace Basics;ostream &operator<<(ostream &stream, const WithoutBallSelection &var){ switch (var) { case WOBS_LOOKFORBALL: stream << "WOBS_LOOKFORBALL"; break; case WOBS_BLOCK: stream << "WOBS_BLOCK"; break; case WOBS_INTERCEPT: stream << "WOBS_INTERCEPT"; break; case WOBS_POSITIONING: stream << "WOBS_POSITIONING"; break; case WOBS_OFFENSE: stream << "WOBS_OFFENSE"; break; case WOBS_DEFENSE: stream << "WOBS_DEFENSE"; break; default: assert(0); } return stream;}// class GroupWorksGroupWorks::GroupWorks(const WorldModel *worldModel): worldModel(worldModel){ interceptNum = 0; interceptBlock = false; lastPassHearTime = 0; lastSRPDribbleTime = 0;// virtualKickCalc.init();// virtualPass.setCurKickCalculate(&virtualKickCalc);}void GroupWorks::updateInterceptNum(Library &library){ if (library.lastBodyCycleCommand && library.lastBodyCycleCommand->getCreator() == AT_SRPDRIBBLE) lastSRPDribbleTime = worldModel->getCurTime() - 1; if (worldModel->getBallStatus() == BS_KICKABLE_BODY || worldModel->getBallStatus() == BS_KICKABLE_BODY_TMM || worldModel->getBallStatus() == BS_KICKABLE_BODY_OPP) { LOG << "I have the ball now !" << endl; interceptBlock = false; interceptSay = true; interceptNum = worldModel->getBody().getUniNum(); LOG << "final interceptNum (Bl, Sy, Pn):" << " " << interceptBlock << " " << interceptSay << " " << interceptNum << endl; return; } if (!getChangeInterceptNumPermission()) { LOG << "Changing interceptNum is not permitted." << endl; LOG << "final interceptNum (Bl, Sy, Pn):" << " " << interceptBlock << " " << interceptSay << " " << interceptNum << endl; return; } bool halfPlayerFlag; float maxBlockWeight = 0; float curBlockWeight = 0; unsigned blocker; unsigned checkedTmmNum; unsigned checkedOppNum; unsigned defenserPlayer; Point ballStopPoint; const Player *checkPlayer; LOG << "GroupWorks::updateInterceptNum" << endl; checkedTmmNum = worldModel->getCurInterCalculate().getTmmCheckedPlayersNum(); checkedOppNum = worldModel->getCurInterCalculate().getOppCheckedPlayersNum(); if (checkedTmmNum > 0 || checkedOppNum > 0) ballStopPoint = worldModel->getCurInterCalculate().getFastestInterPlayer().getInterPoint(); // cleaning interceptNum // intercept conditions // condition 1 if (interceptNum && !interceptBlock) { if (interceptNum == worldModel->getBody().getUniNum()) { if (worldModel->getCurInterCalculate().getCheckedListNum( worldModel->getBody()) == NOVALUE) { interceptNum = 0; LOG << "interceptNum reset 1.1" << endl; } } else if (worldModel->getFullPlayer(TID_TEAMMATE, interceptNum - 1).getPosDeviation() <= 3 && worldModel->getCurInterCalculate().getCheckedListNum( worldModel->getFullPlayer(TID_TEAMMATE, interceptNum - 1)) == NOVALUE) { interceptNum = 0; LOG << "interceptNum reset 1.2" << endl; } } // block and intercept conditions // condition 2 if (worldModel->getBall().getPosDeviation() > 5) { interceptNum = 0; LOG << "interceptNum reset 2" << endl; } // block conditions // condition 3 if (interceptNum && interceptBlock && checkedTmmNum > 0) { if (interceptNum == worldModel->getBody().getUniNum() && worldModel->getCurInterCalculate().getCheckedListNum( worldModel->getBody()) == NOVALUE) { interceptNum = 0; LOG << "interceptNum reset 3.1" << endl; } else if (worldModel->getFullPlayer(TID_TEAMMATE, interceptNum - 1).getPosDeviation() <= 3 && worldModel->getCurInterCalculate().getCheckedListNum( worldModel->getFullPlayer(TID_TEAMMATE, interceptNum - 1)) == NOVALUE) { interceptNum = 0; LOG << "interceptNum reset 3.2" << endl; } } // Condition 4 if (interceptNum && interceptBlock && (checkedTmmNum > 0 || checkedOppNum > 0)) { if (interceptNum == worldModel->getBody().getUniNum()) checkPlayer = &worldModel->getBody(); else checkPlayer = &worldModel->getFullPlayer(TID_TEAMMATE, interceptNum - 1); // Checking Teammates for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) { if (!worldModel->getFullPlayer(TID_TEAMMATE, i).isValid()) continue; if (worldModel->getFullPlayer(TID_TEAMMATE, i).isGoalie()) continue; if (abs(getBlockWeight(ballStopPoint, worldModel->getFullPlayer(TID_TEAMMATE, i)) - getBlockWeight(ballStopPoint, *checkPlayer)) > 10 && getBlockWeight(ballStopPoint, worldModel->getFullPlayer(TID_TEAMMATE, i)) > getBlockWeight(ballStopPoint, *checkPlayer)) { interceptNum = 0; LOG << "interceptNum reset 4.1" << endl; break; } } // Checking Body if (interceptNum && !worldModel->getBody().isGoalie() && abs(getBlockWeight(ballStopPoint, worldModel->getBody()) - getBlockWeight(ballStopPoint, *checkPlayer)) > 10 && getBlockWeight(ballStopPoint, worldModel->getBody()) > getBlockWeight(ballStopPoint, *checkPlayer)) { interceptNum = 0; LOG << "interceptNum reset 4.2" << endl; } } // making interceptNum if (worldModel->getBall().getPosDeviation() > 10) { LOG << "I have not enough information to make a choice." << endl; return; } // intercept conditions // condition 1 if (interceptNum == 0 && checkedTmmNum == 1 && worldModel->getCurInterCalculate().getFastestPlayer().getTeamId() == TID_TEAMMATE && worldModel->getCurInterCalculate().getFastestPlayer().getModel() == PLM_FULL) { // somebody is the one Fastest. interceptNum = worldModel->getCurInterCalculate().getFastestPlayer().getUniNum(); interceptBlock = false; interceptSay = true; LOG << "interceptNum set 1" << endl; } // condition 2 if (interceptNum == 0 && checkedTmmNum > 1 && worldModel->getCurInterCalculate().getFastestPlayer().getTeamId() == TID_TEAMMATE) { // A few Tmms are Fastest. defenserPlayer = NOVALUE; halfPlayerFlag = false; for (unsigned i = 0; i < worldModel->getCurInterCalculate().getCheckedPlayersNum(); i++) { if (worldModel->getCurInterCalculate().getCheckedInterPlayer(i).getPlayer().getTeamId() == TID_OPPONENT) continue; if (checkedOppNum != 0 && worldModel->getCurInterCalculate().getCheckedInterPlayer(i).getInterTime() > worldModel->getCurInterCalculate().getFastestOppInterPlayer().getInterTime()) continue; if (worldModel->getCurInterCalculate().getCheckedInterPlayer(i).getPlayer().getModel() == PLM_HALF) halfPlayerFlag = true; else { if (defenserPlayer == NOVALUE) defenserPlayer = i; else if (worldModel->getCurInterCalculate().getCheckedInterPlayer(i).getPlayer().getPostNum() < worldModel->getCurInterCalculate().getCheckedInterPlayer(defenserPlayer).getPlayer().getPostNum()) defenserPlayer = i; } } // setting results if (defenserPlayer != NOVALUE) { if (halfPlayerFlag == false) { interceptNum = worldModel->getCurInterCalculate().getCheckedInterPlayer(defenserPlayer).getPlayer().getUniNum(); interceptBlock = false; interceptSay = true; LOG << "interceptNum set 2.1" << endl; } else if (worldModel->getCurInterCalculate().getCheckedInterPlayer( defenserPlayer).getPlayer().getUniNum() == worldModel->getBody().getUniNum()) // I think I must go to ball but I am not sure. { interceptNum = worldModel->getBody().getUniNum(); interceptBlock = false; interceptSay = false; LOG << "interceptNum set 2.2" << endl; } } } // block Conditions // condition 3 if (interceptNum == 0 && (worldModel->getBallStatus() == BS_KICKABLE_OPP || worldModel->getBallStatus() == BS_FREE_BALL_OPP)) { blocker = NOVALUE; halfPlayerFlag = false; // Checking Teammates for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) { if (!worldModel->getFullPlayer(TID_TEAMMATE, i).isValid()) continue; if (worldModel->getFullPlayer(TID_TEAMMATE, i).isGoalie()) continue; curBlockWeight = getBlockWeight(ballStopPoint, worldModel->getFullPlayer(TID_TEAMMATE, i)); if (blocker == NOVALUE || curBlockWeight > maxBlockWeight) { blocker = i; maxBlockWeight = curBlockWeight; } } // Checking Body if (!worldModel->getBody().isGoalie()) { curBlockWeight = getBlockWeight(ballStopPoint, worldModel->getBody()); if (blocker == NOVALUE || curBlockWeight > maxBlockWeight) { blocker = worldModel->getBody().getUniNum() - 1; maxBlockWeight = curBlockWeight; } } // Checking Half Players if (blocker != NOVALUE) for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) { if (!worldModel->getHalfPlayer(TID_TEAMMATE, i).isValid()) continue; if (getBlockWeight(ballStopPoint, worldModel->getHalfPlayer(TID_TEAMMATE, i)) > maxBlockWeight) { halfPlayerFlag = true; break; } } // Setting results if (blocker == NOVALUE) { interceptNum = 0; interceptBlock = true; interceptSay = false; } else if (halfPlayerFlag == false) { interceptNum = blocker + 1; interceptBlock = true; interceptSay = true; LOG << "interceptNum set 3.1" << endl; } else if (blocker + 1 == worldModel->getBody().getUniNum()) // I think I must block but I am not sure. { interceptNum = worldModel->getBody().getUniNum(); interceptBlock = true; interceptSay = false; LOG << "interceptNum set 3.2" << endl; } } LOG << "final interceptNum (Bl, Sy, Pn):" << " " << interceptBlock << " " << interceptSay << " " << interceptNum << endl;}float GroupWorks::getBlockWeight(const Point &ballStopPoint, const Player &player) const{ Vector playerVec; Vector goalVec; float dirFactor; float distFactor; playerVec.setByPoints(player.getPos(), ballStopPoint); goalVec.setByPoints(Point(-52.5, 0), ballStopPoint); distFactor = playerVec.getMagnitude(); dirFactor = abs(Degree::getDeltaAngle(goalVec.getDirection(), playerVec.getDirection())); return 100 - 0.15 * dirFactor - 1 * distFactor;}void GroupWorks::setInterceptNumByPassSay(unsigned uniNum){ interceptSay = true; lastPassHearTime = worldModel->getCurTime(); if (uniNum <= 11) // GoToBall Mode { interceptBlock = false; interceptNum = uniNum; } else // Block Mode { interceptBlock = true; interceptNum = uniNum - 11; } LOG << "setting interceptNum (Bl, Sy, Pn):" << " " << interceptBlock << " " << interceptSay << " " << interceptNum << endl;}void GroupWorks::resetByChangePlayMode(){ interceptNum = 0; interceptBlock = false; interceptSay = false; lastPassHearTime = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -