📄 goalieplayondecision.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: Meisam Vosoughpour * and is modified by: Mostafa Rokooey * * Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. * For more information please read README file.*/#include <AdvancedAgent.h>#include <GoalieIntercept.h>#include <GoaliePositioning.h>#include <Intercept.h>#include <GoaliePlayOnDecision.h>#include <Clear.h>#include <BasicKick.h>#include <Circle.h>#include <cmath>#define GOALIE_CATCH_NUM 0#define CLEAR_NUM 1#define GOALIE_INTERCEPT_NUM 2#define INTERCEPT_NUM 3#define GOALIE_POSITIONING_NUM 4#define PASS_NUM 5#define DRIBBLE_NUM 6using namespace std;GoaliePlayOnDecision::GoaliePlayOnDecision( const WorldModel *worldModel): BodyDecision(worldModel){ addAdvancedAction(new GoalieCatch(worldModel), AdvancedActionWeights(0, 1, 1), 2); addAdvancedAction(new Clear(worldModel), AdvancedActionWeights(0, 1, 1), 2); addAdvancedAction(new GoalieIntercept(worldModel), AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Intercept(worldModel), AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new GoaliePositioning(worldModel), AdvancedActionWeights(0, 1, 1), 1); addAdvancedAction(new Pass(worldModel), AdvancedActionWeights(0, 1, 1), 0); addAdvancedAction(new Dribble(worldModel), AdvancedActionWeights(0, 1, 1), 0); dynamic_cast<Pass *>(advancedActions[PASS_NUM])-> setCurKickCalculate(&worldModel->getCurKickCalculate());}GoaliePlayOnDecision::~GoaliePlayOnDecision(){}bool GoaliePlayOnDecision::isBallOppKickable(float minExtra, float maxExtra){ register int i; float kickableArea, virtualKickableArea; kickableArea = worldModel->getBall().getSize() + worldModel->getBody().getKickableMargin() + worldModel->getBody().getSize(); virtualKickableArea = kickableArea + minExtra; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (worldModel->getFullPlayer(TID_OPPONENT, i).isValid()) if(worldModel->getFullPlayer(TID_OPPONENT, i). getDistance(worldModel->getBall()) <= (virtualKickableArea + min((float)(worldModel->getFullPlayer( TID_OPPONENT, i).getDistance(worldModel->getBody()) * .08), maxExtra) )) return true; for (i = 0; i < HALF_PLAYERS_NUM; i++) if (worldModel->getHalfPlayer(TID_OPPONENT, i).isValid()) if(worldModel->getHalfPlayer(TID_OPPONENT, i). getDistance(worldModel->getBall()) <= (virtualKickableArea + min((float)(worldModel->getHalfPlayer( TID_OPPONENT, i).getDistance(worldModel->getBody()) * .08), maxExtra) )) return true; return false;}void GoaliePlayOnDecision::decide(int quickLevel, Form &form, const Library &library){ resetQuickLevels(); float passValue; bool isPlayerInSafeCircle; int i; if (worldModel->getBall().getPos().getX() < -36.4 && worldModel->getBody().getPos().getX() < -36.4 && abs(worldModel->getBall().getPos().getY()) < 19.6 && abs(worldModel->getBody().getPos().getY()) < 19.6) { } else if (worldModel->isBallKickable()) { passValue = advancedActions[PASS_NUM]->getValue(library); if (passValue >= 25) { advancedActions[PASS_NUM]->execute(form, library); command = advancedActions[PASS_NUM]->getCommand(); } else { Circle safeDribbleCircle; safeDribbleCircle.setByCenterRadius(worldModel->getBody().getPos(), 3); isPlayerInSafeCircle = false; for (i = 0; i <= 10; i++) { if (worldModel->getFullPlayer(TID_OPPONENT, i).isAlive()) if (safeDribbleCircle.checkPointInArea( worldModel->getFullPlayer( TID_OPPONENT, i).getPos())) isPlayerInSafeCircle = true; } advancedActions[DRIBBLE_NUM]->getValue(library); if (!isPlayerInSafeCircle && worldModel->getBody().getPos().getX() <= -25.) { advancedActions[DRIBBLE_NUM]->execute(form, library); command = advancedActions[DRIBBLE_NUM]->getCommand(); } else { if (worldModel->getBall().getPos().getY() > 0) command = FastKickToDir(AT_GOALIE_CLEAR, 90, worldModel->getBall(), worldModel->getBody()).getCommand(); else command = FastKickToDir(AT_GOALIE_CLEAR, -90, worldModel->getBall(), worldModel->getBody()).getCommand(); } } return; } quickLevels[GOALIE_CATCH_NUM] = 2; quickLevels[CLEAR_NUM] = 2; if (worldModel->getCurInterCalculate().existFastestTmmPlayer() && ( (worldModel->getCurInterCalculate().getFastestTmmPlayer().isBody() && !isBallOppKickable(.2,1.5)) || (worldModel->isOppBallShooted(worldModel->getBall()) && !worldModel->isBallInOppKickable()))) { // Intercept quickLevels[GOALIE_INTERCEPT_NUM] = 1; quickLevels[INTERCEPT_NUM] = 1; } else { // Positioning quickLevels[GOALIE_POSITIONING_NUM] = 1; } if (worldModel->getBall().getAbsVec().getMagnitude() < 20) form.headForm.tnMode = TNM_LOOK_CAREFULLY_TO_BALL; else form.headForm.tnMode = TNM_LOOK_NORMALLY_TO_BALL; BodyDecision::decide(quickLevel, form, library);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -