void ai09::penalty_their_simple ( void ) { float penalty_x = field_width - 85.0; int index = findKickerOpp(-1); if ( index == -1 ) { OwnRobot[gk].target.Angle = (1+side)*90.0f; Navigate2Point ( gk , Vec2 ( side*penalty_x , 0 ) ); } else { float gkp_y = Line::makeLineFromTwoPoints ( VecPosition ( OppRobot[index].Position.X , OppRobot[index].Position.Y ) , VecPosition ( ball.Position.X , ball.Position.Y ) ).getIntersection ( Line::makeLineFromTwoPoints ( VecPosition ( side * penalty_x , 100 ) , VecPosition ( side * penalty_x , -100 ) ) ).getY ( ); float max_reach_y = (goal_width/2.0) - 100.0; if(max_reach_y > 250) max_reach_y = 250; if(max_reach_y < -250) max_reach_y = -250; OwnRobot[gk].face(ball.Position); Navigate2Point ( gk , Vec2 ( side * penalty_x , gkp_y ) ); } ERRTSetObstacles ( def , true , true , true , true ); ERRTNavigate2Point ( def , Vec2 ( side*2000 , 500 ) ); ERRTSetObstacles ( dmf , true , true , true , true ); ERRTNavigate2Point ( dmf , Vec2 ( side*2000 , -500 ) ); ERRTSetObstacles ( mid1 , true , true , true , true ); ERRTNavigate2Point ( mid1, Vec2 ( side*2000 , -800 ) ); ERRTSetObstacles ( mid2 , true , true , true , true ); ERRTNavigate2Point ( mid2, Vec2 ( side*2000 , 800 ) ); ERRTSetObstacles ( attack , true , true , true , true ); ERRTNavigate2Point ( attack , Vec2 ( side*2000 , 0 ) ); }
void ai09::TwoDef ( int robot_num1 , int robot_num2 , TVec2 * defendTarget ) { if ( !defendTarget ) defendTarget = &(ball.Position); VecPosition* p1 = new VecPosition ( ); VecPosition* p2 = new VecPosition ( ); OwnRobot[robot_num1].face ( (*defendTarget)); OwnRobot[robot_num2].face ( (*defendTarget)); TVec2 num1Target , num2Target ; if ( ( Line::makeLineFromTwoPoints(VecPosition(side*field_width,-175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getCircleIntersectionPoints(Circle (VecPosition(side*field_width,-175.0f),750.0f),p1,p2) ) && ( (*defendTarget).Y < -175.0f ) ) { if ( p1->getY() <= -175.0f ) { num1Target = Vec2 ( p1->getX() , p1->getY() ); } else { num1Target = Vec2 ( p2->getX() , p2->getY() ); } } else if ( ( Line::makeLineFromTwoPoints(VecPosition(side*field_width,-175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getCircleIntersectionPoints(Circle (VecPosition(side*field_width,175.0f),750.0f),p1,p2) ) && ( ( p1->getY ( ) > 175.0f ) && ( fabs ( p1->getX() ) < field_width ) || ( p2->getY ( ) > 175.0f ) && ( fabs ( p2->getX() ) < field_width ) ) ) { if ( p1->getY() >= 175.0f ) { num1Target = Vec2 ( p1->getX() , p1->getY() ); } else { num1Target = Vec2 ( p2->getX() , p2->getY() ); } } else { *p1 = Line::makeLineFromTwoPoints(VecPosition(side*field_width,-175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getIntersection ( Line::makeLineFromTwoPoints ( VecPosition ( side*2275.0f , 175.0f ) , VecPosition ( side*2275.0f , -175.0f ) ) ); num1Target = Vec2 ( p1->getX() , p1->getY() ); } ERRTSetObstacles ( robot_num2 , 0 , true , true , false ); if ( ( Line::makeLineFromTwoPoints(VecPosition(side*3025.0f,175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getCircleIntersectionPoints(Circle (VecPosition(side*3025.0f,175.0f),750.0f),p1,p2) ) && ( (*defendTarget).Y > 175.0f ) ) { if ( p1->getY() >= 175.0f ) { num2Target = Vec2 ( p1->getX() , p1->getY() ); } else { num2Target = Vec2 ( p2->getX() , p2->getY() ); } } else if ( ( Line::makeLineFromTwoPoints(VecPosition(side*3025.0f,175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getCircleIntersectionPoints(Circle (VecPosition(side*3025.0f,-175.0f),750.0f),p1,p2) ) && ( ( p1->getY ( ) < -175.0f ) && ( fabs ( p1->getX() ) < 3025.0f ) || ( p2->getY ( ) < -175.0f ) && ( fabs ( p2->getX() ) < 3025.0f ) ) ) { if ( p1->getY() <= -175.0f ) { num2Target = Vec2 ( p1->getX() , p1->getY() ); } else { num2Target = Vec2 ( p2->getX() , p2->getY() ); } } else { *p1 = Line::makeLineFromTwoPoints(VecPosition(side*3025.0f,175.0f),VecPosition((*defendTarget).X , (*defendTarget).Y)).getIntersection ( Line::makeLineFromTwoPoints ( VecPosition ( side*2275.0f , 175.0f ) , VecPosition ( side*2275.0f , -175.0f ) ) ); num2Target = Vec2 ( p1->getX() , p1->getY() ); } float ballDis1 = DIS ( num1Target , (*defendTarget) ); float ballDis2 = DIS ( num2Target , (*defendTarget) ); if ( 0 )//( min ( ballDis1 , ballDis2 ) < 250 ) && ball.velocity.magnitude < 50 ) { if ( ( ballDis1 < ballDis2 ) || ((attackingDefHys>0)&&(lastAttackingDef==1)) ) { if ( ballDis1 < ballDis2 ) { attackingDefHys = 10; lastAttackingDef = 1; } else { lastAttackingDef = 1; attackingDefHys --; } ERRTSetObstacles ( robot_num1 , 0 , 1 , 1 , 0 , 0 ); tech_circle(robot_num1,sgn((*defendTarget).Y)*side*120.0f ,0,15); ERRTSetObstacles ( robot_num2 , 0 , true , true , false ); ERRTNavigate2Point ( robot_num2 , num2Target ); } else { if ( ballDis2 < ballDis1 ) { attackingDefHys = 10; lastAttackingDef = 2; } else { lastAttackingDef = 2; attackingDefHys --; } ERRTSetObstacles ( robot_num2 , 0 , 1 , 1 , 0 , 0 ); tech_circle(robot_num2,sgn((*defendTarget).Y)*side*120.0f ,0,15); ERRTSetObstacles ( robot_num1 , 0 , true , true , false ); ERRTNavigate2Point ( robot_num1 , num1Target ); } } else { ERRTSetObstacles ( robot_num1 , 0 , true , true , false ); ERRTNavigate2Point ( robot_num1 , num1Target ); ERRTSetObstacles ( robot_num2 , 0 , true , true , false ); ERRTNavigate2Point ( robot_num2 , num2Target ); } //OwnRobot[robot_num1].Chip ( 15 ); //OwnRobot[robot_num2].Chip ( 15 ); free ( p1 ); free ( p2 ); }
/*!This method is the first complete simple team and defines the actions taken by all the players on the field (excluding the goalie). It is based on the high-level actions taken by the simple team FC Portugal that it released in 2000. The players do the following: - if ball is kickable kick ball to goal (random corner of goal) - else if i am fastest player to ball intercept the ball - else move to strategic position based on your home position and pos ball */ SoccerCommand Player::deMeer5( ) { SoccerCommand soc(CMD_ILLEGAL); VecPosition posAgent = WM->getAgentGlobalPosition(); VecPosition posBall = WM->getBallPos(); int iTmp; if( WM->isBeforeKickOff( ) ) { if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 9 ) // 9 takes kick { if( WM->isBallKickable() ) { VecPosition posGoal( PITCH_LENGTH/2.0, (-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() ); soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal Log.log( 100, "take kick off" ); } else { soc = intercept( false ); Log.log( 100, "move to ball to take kick-off" ); } ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); return soc; } if( formations->getFormation() != FT_INITIAL || // not in kickoff formation posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 ) { formations->setFormation( FT_INITIAL ); // go to kick_off formation ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() )); } else // else turn to center { ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) ); ACT->putCommandInQueue( alignNeckWithBody( ) ); } } else { formations->setFormation( FT_433_OFFENSIVE ); soc.commandType = CMD_ILLEGAL; if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() ) { ACT->putCommandInQueue( soc = searchBall() ); // if ball pos unknown ACT->putCommandInQueue( alignNeckWithBody( ) ); // search for it } else if( WM->isBallKickable()) // if kickable { VecPosition posGoal( PITCH_LENGTH/2.0, (-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() ); soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maxima ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); Log.log( 100, "kick ball" ); } else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp ) == WM->getAgentObjectType() && !WM->isDeadBallThem() ) { // if fastest to ball Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp ); soc = intercept( false ); // intercept the ball if( soc.commandType == CMD_DASH && // if stamina low WM->getAgentStamina().getStamina() < SS->getRecoverDecThr()*SS->getStaminaMax()+200 ) { soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // if stamina high { ACT->putCommandInQueue( soc ); // dash as intended ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } else if( posAgent.getDistanceTo(WM->getStrategicPosition()) > 1.5 + fabs(posAgent.getX()-posBall.getX())/10.0) // if not near strategic pos { if( WM->getAgentStamina().getStamina() > // if stamina high SS->getRecoverDecThr()*SS->getStaminaMax()+800 ) { soc = moveToPos(WM->getStrategicPosition(), PS->getPlayerWhenToTurnAngle()); ACT->putCommandInQueue( soc ); // move to strategic pos ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // else watch ball { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else // nothing to do ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) ); } return soc; }
/*!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 Player::deMeer5_goalie( ) { int i; SoccerCommand soc; VecPosition posAgent = WM->getAgentGlobalPosition(); AngDeg angBody = WM->getAgentGlobalBodyAngle(); // 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 ACT->putCommandInQueue( soc=teleportToPos(WM->getStrategicPosition()) ); } else // else turn to center { ACT->putCommandInQueue( soc = turnBodyToPoint( VecPosition( 0, 0 ), 0 )); ACT->putCommandInQueue( alignNeckWithBody( ) ); } return soc; } if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() ) { // confidence ball too low ACT->putCommandInQueue( searchBall() ); // search ball ACT->putCommandInQueue( alignNeckWithBody( ) ); } else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() || WM->isCornerKickThem() ) { if( WM->isBallCatchable() ) { ACT->putCommandInQueue( soc = catchBall() ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else if( WM->isBallKickable() ) { soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 ); ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) && WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) == WM->getAgentObjectType() ) { ACT->putCommandInQueue( soc = intercept( true ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } 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 ) { soc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() ); ACT->putCommandInQueue( soc ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } } 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 )) ) soc.makeCommand( CMD_MOVE,posRightTop.getX(),posRightTop.getY(),0.0); else soc.makeCommand( CMD_MOVE,posLeftTop.getX(), posLeftTop.getY(), 0.0); ACT->putCommandInQueue( soc ); } else if( WM->getTimeSinceLastCatch() > 28 ) { soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 ); ACT->putCommandInQueue( soc ); } else if( WM->getTimeSinceLastCatch() < 25 ) { VecPosition posSide( 0.0, posAgent.getY() ); if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 ) { soc = turnBodyToPoint( posSide ); ACT->putCommandInQueue( soc ); } ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } } else if( WM->isGoalKickUs() ) { ACT->putCommandInQueue( soc = intercept( true ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } else { ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) ); ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) ); } return soc; }