📄 goaliebehavior.cpp.svn-base
字号:
#include "GoalieBehavior.h"/*!This method is a simple goalie based on the goalie of the simple Team of FC Portugal. It defines a rectangle in its penalty area and moves to the position on this rectangle where the ball intersects if you make a line between the ball position and the center of the goal. If the ball can be intercepted in the own penalty area the ball is intercepted and catched.*/SoccerCommand GoalieBehavior::primaryAction(){ cuncurrentSoc.commandType = CMD_ILLEGAL; primarySoc.commandType = CMD_ILLEGAL; int i; VecPosition posAgent = WM->getAgentGlobalPosition(); AngDeg angBody = WM->getAgentGlobalBodyAngle(); //Variaveis utilizadas para analise da confiabilidade /*double v1,v2; ObjectT bestPlayerToPass; VecPosition posgoleiro;*/ // define the top and bottom position of a rectangle in which keeper moves static const VecPosition posLeftTop( -PITCH_LENGTH/2.0 + 0.7*PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/4.0 ); static const VecPosition posRightTop( -PITCH_LENGTH/2.0 + 0.7*PENALTY_AREA_LENGTH, +PENALTY_AREA_WIDTH/4.0 ); // define the borders of this rectangle using the two points. static Line lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop); static Line lineLeft = Line::makeLineFromTwoPoints( VecPosition( -50.0, posLeftTop.getY()), posLeftTop ); static Line lineRight = Line::makeLineFromTwoPoints( VecPosition( -50.0, posRightTop.getY()),posRightTop ); if( WM->isBeforeKickOff( ) ) { if( formations->getFormation() != FT_INITIAL || // not in kickoff formation posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 ) { formations->setFormation( FT_INITIAL ); // go to kick_off formation primarySoc = teleportToPos(WM->getStrategicPosition()); } else // else turn to center { primarySoc = turnBodyToPoint( VecPosition( 0, 0 ), 0 ); cuncurrentSoc = alignNeckWithBody( ); } return primarySoc; } //Regra para o goleiro se posicionar no centro do gol nas jogadas do adversário /*if( WM->isDeadBallThem( WM->getPlayMode() ) ) { primarySoc = moveToPos( VecPosition( -50 , 0 ) , PS->getPlayerWhenToTurnAngle() ); return primarySoc; }*/ if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() ) { // confidence ball too low primarySoc = searchBall(); // search ball cuncurrentSoc = alignNeckWithBody( ); } else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() || WM->isCornerKickThem() ) { if( WM->isBallCatchable() ) { primarySoc = catchBall(); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else if( WM->isBallKickable() ) { primarySoc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) && WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) == WM->getAgentObjectType() ) { primarySoc = intercept( true ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else { // make line between own goal and the ball VecPosition posMyGoal = ( WM->getSide() == SIDE_LEFT ) ? SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_L, SIDE_LEFT ) : SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_R, SIDE_RIGHT); Line lineBall = Line::makeLineFromTwoPoints( WM->getBallPos(),posMyGoal); // determine where your front line intersects with the line from ball VecPosition posIntersect = lineFront.getIntersection( lineBall ); // outside rectangle, use line at side to get intersection if (posIntersect.isRightOf( posRightTop ) ) posIntersect = lineRight.getIntersection( lineBall ); else if (posIntersect.isLeftOf( posLeftTop ) ) posIntersect = lineLeft.getIntersection( lineBall ); if( posIntersect.getX() < -49.0 ) posIntersect.setX( -49.0 ); // and move to this position if( posIntersect.getDistanceTo( WM->getAgentGlobalPosition() ) > 0.5 ) { primarySoc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else { primarySoc = turnBodyToObject( OBJECT_BALL ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } } } else if( WM->isFreeKickUs() == true || WM->isGoalKickUs() == true ) { if( WM->isBallKickable() ) { if( WM->getTimeSinceLastCatch() == 25 && WM->isFreeKickUs() ) { // move to position with lesser opponents. if( WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, Circle(posRightTop, 15.0 )) < WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, Circle(posLeftTop, 15.0 )) ) primarySoc.makeCommand( CMD_MOVE,posRightTop.getX() ,posRightTop.getY(),0.0); else primarySoc.makeCommand( CMD_MOVE,posLeftTop.getX() ,posLeftTop.getY(), 0.0);//Adapta��o da regra, o goleiro, analiza entre os teammates o mais confi�vel para tocar. /*v1= getSafetyToPass(WM->getGlobalPosition(OBJECT_TEAMMATE_1),WM->getGlobalPosition(OBJECT_TEAMMATE_2)); bestPlayerToPass=OBJECT_TEAMMATE_2; v2= getSafetyToPass(WM->getGlobalPosition(OBJECT_TEAMMATE_1),WM->getGlobalPosition(OBJECT_TEAMMATE_3)); if( v1 < v2 ) { v1=v2; bestPlayerToPass=OBJECT_TEAMMATE_3; } v2= getSafetyToPass(WM->getGlobalPosition(OBJECT_TEAMMATE_1),WM->getGlobalPosition(OBJECT_TEAMMATE_4)); if( v1 < v2 ) { v1=v2; bestPlayerToPass=OBJECT_TEAMMATE_4; } v2 = getSafetyToPass(WM->getGlobalPosition(OBJECT_TEAMMATE_1),WM->getGlobalPosition(OBJECT_TEAMMATE_5)); if( v1 < v2 ) { v1=v2; bestPlayerToPass=OBJECT_TEAMMATE_5; } //Bugado... posgoleiro = (WM->getGlobalPosition(OBJECT_TEAMMATE_1).operator + (WM->getGlobalPosition(bestPlayerToPass))).operator /(2);*/ //cout<<posgoleiro.getX()<<endl<<posgoleiro.getY()<<endl; //primarySoc.makeCommand(CMD_MOVE,posgoleiro.getX(),posgoleiro.getY(),0.0); } else if( WM->getTimeSinceLastCatch() > 28 ) { // primarySoc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 ); //primarySoc = kickTo( VecPosition((-WM->getGlobalPosition(bestPlayerToPass)).getX(),0) , 2.0 ); } else if( WM->getTimeSinceLastCatch() < 25 ) { VecPosition posSide( 0.0, posAgent.getY() ); if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 ) { primarySoc = turnBodyToPoint( posSide ); } cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } } else if( WM->isGoalKickUs() ) { primarySoc = intercept( true ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } else { primarySoc = turnBodyToObject( OBJECT_BALL ); cuncurrentSoc = turnNeckToObject( OBJECT_BALL, primarySoc ); } return primarySoc;}SoccerCommand GoalieBehavior::cuncurrentAction(){ return cuncurrentSoc;}void GoalieBehavior::setFormations(Formations* _fs){ formations = _fs;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -