Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

PlayerTeams.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000-2003, Jelle Kok, University of Amsterdam
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice, this
00009 list of conditions and the following disclaimer.
00010 
00011 2. Redistributions in binary form must reproduce the above copyright notice,
00012 this list of conditions and the following disclaimer in the documentation
00013 and/or other materials provided with the distribution.
00014 
00015 3. Neither the name of the University of Amsterdam nor the names of its
00016 contributors may be used to endorse or promote products derived from this
00017 software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00023 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00025 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 */
00030 
00048 #include "Player.h"
00049 
00060 SoccerCommand Player::deMeer5(  )
00061 {
00062 
00063   SoccerCommand soc(CMD_ILLEGAL);
00064   VecPosition   posAgent = WM->getAgentGlobalPosition();
00065   VecPosition   posBall  = WM->getBallPos();
00066   int           iTmp;
00067 
00068   if( WM->isBeforeKickOff( ) )
00069   {
00070     if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 9 ) // 9 takes kick
00071     {
00072       if( WM->isBallKickable() )
00073       {
00074         VecPosition posGoal( PITCH_LENGTH/2.0,
00075                              (-1 + 2*(WM->getCurrentCycle()%2)) * 
00076                              0.4 * SS->getGoalWidth() );
00077         soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
00078         Log.log( 100, "take kick off" );        
00079       }
00080       else
00081       {
00082         soc = intercept( false );  
00083         Log.log( 100, "move to ball to take kick-off" );
00084       }  
00085       ACT->putCommandInQueue( soc );
00086       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00087       return soc;
00088     }  
00089     if( formations->getFormation() != FT_INITIAL || // not in kickoff formation
00090         posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
00091     {
00092       formations->setFormation( FT_INITIAL );       // go to kick_off formation
00093       ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() ));
00094     }
00095     else                                            // else turn to center
00096     {
00097       ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) );
00098       ACT->putCommandInQueue( alignNeckWithBody( ) );
00099     }
00100   }
00101   else
00102   {
00103     formations->setFormation( FT_433_OFFENSIVE );
00104     soc.commandType = CMD_ILLEGAL;
00105 
00106     if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00107     {
00108       ACT->putCommandInQueue( soc = searchBall() );   // if ball pos unknown
00109       ACT->putCommandInQueue( alignNeckWithBody( ) ); // search for it
00110     }
00111     else if( WM->isBallKickable())                    // if kickable
00112     {
00113       VecPosition posGoal( PITCH_LENGTH/2.0,
00114               (-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
00115       soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
00116 
00117       ACT->putCommandInQueue( soc );
00118       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00119       Log.log( 100, "kick ball" );
00120     }
00121     else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp )
00122               == WM->getAgentObjectType()  && !WM->isDeadBallThem() )
00123     {                                                // if fastest to ball
00124       Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp );
00125       soc = intercept( false );                      // intercept the ball
00126 
00127       if( soc.commandType == CMD_DASH &&             // if stamina low
00128           WM->getAgentStamina().getStamina() <
00129              SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
00130       {
00131         soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
00132         ACT->putCommandInQueue( soc );
00133         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00134       }
00135       else                                           // if stamina high
00136       {
00137         ACT->putCommandInQueue( soc );               // dash as intended
00138         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00139       }
00140      }
00141      else if( posAgent.getDistanceTo(WM->getStrategicPosition()) >
00142                   1.5 + fabs(posAgent.getX()-posBall.getX())/10.0)
00143                                                   // if not near strategic pos
00144      {
00145        if( WM->getAgentStamina().getStamina() >     // if stamina high
00146                             SS->getRecoverDecThr()*SS->getStaminaMax()+800 )
00147        {
00148          soc = moveToPos(WM->getStrategicPosition(),
00149                          PS->getPlayerWhenToTurnAngle());
00150          ACT->putCommandInQueue( soc );            // move to strategic pos
00151          ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00152        }
00153        else                                        // else watch ball
00154        {
00155          ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00156          ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00157        }
00158      }
00159      else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball
00160      {
00161        ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00162        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00163      }
00164      else                                         // nothing to do
00165        ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) );
00166    }
00167   return soc;
00168 }
00169 
00176 SoccerCommand Player::deMeer5_goalie(  )
00177 {
00178   int i;
00179   SoccerCommand soc;
00180   VecPosition   posAgent = WM->getAgentGlobalPosition();
00181   AngDeg        angBody  = WM->getAgentGlobalBodyAngle();
00182 
00183   // define the top and bottom position of a rectangle in which keeper moves
00184   static const VecPosition posLeftTop( -PITCH_LENGTH/2.0 +
00185                0.7*PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/4.0 );
00186   static const VecPosition posRightTop( -PITCH_LENGTH/2.0 +
00187                0.7*PENALTY_AREA_LENGTH, +PENALTY_AREA_WIDTH/4.0 );
00188 
00189   // define the borders of this rectangle using the two points.
00190   static Line  lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop);
00191   static Line  lineLeft  = Line::makeLineFromTwoPoints(
00192                          VecPosition( -50.0, posLeftTop.getY()), posLeftTop );
00193   static Line  lineRight = Line::makeLineFromTwoPoints(
00194                          VecPosition( -50.0, posRightTop.getY()),posRightTop );
00195 
00196 
00197   if( WM->isBeforeKickOff( ) )
00198   {
00199     if( formations->getFormation() != FT_INITIAL || // not in kickoff formation
00200         posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
00201     {
00202       formations->setFormation( FT_INITIAL );       // go to kick_off formation
00203       ACT->putCommandInQueue( soc=teleportToPos(WM->getStrategicPosition()) );
00204     }
00205     else                                            // else turn to center
00206     {
00207       ACT->putCommandInQueue( soc = turnBodyToPoint( VecPosition( 0, 0 ), 0 ));
00208       ACT->putCommandInQueue( alignNeckWithBody( ) );
00209     }
00210     return soc;
00211   }
00212 
00213   if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00214   {                                                // confidence ball too  low
00215     ACT->putCommandInQueue( searchBall() );        // search ball
00216     ACT->putCommandInQueue( alignNeckWithBody( ) );
00217   }
00218   else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() ||
00219            WM->isCornerKickThem() )               
00220   {
00221     if( WM->isBallCatchable() )
00222     {
00223       ACT->putCommandInQueue( soc = catchBall() );
00224       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00225     }
00226      else if( WM->isBallKickable() )
00227     {
00228        soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
00229        ACT->putCommandInQueue( soc );
00230        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00231     }
00232     else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) &&
00233              WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) == 
00234                                                WM->getAgentObjectType() )
00235     {
00236       ACT->putCommandInQueue( soc = intercept( true ) );
00237       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00238     }
00239     else
00240     {
00241       // make line between own goal and the ball
00242       VecPosition posMyGoal = ( WM->getSide() == SIDE_LEFT )
00243              ? SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_L, SIDE_LEFT )
00244              : SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_R, SIDE_RIGHT);
00245       Line lineBall = Line::makeLineFromTwoPoints( WM->getBallPos(),posMyGoal);
00246 
00247       // determine where your front line intersects with the line from ball
00248       VecPosition posIntersect = lineFront.getIntersection( lineBall );
00249 
00250       // outside rectangle, use line at side to get intersection
00251       if (posIntersect.isRightOf( posRightTop ) )
00252         posIntersect = lineRight.getIntersection( lineBall );
00253       else if (posIntersect.isLeftOf( posLeftTop )  )
00254         posIntersect = lineLeft.getIntersection( lineBall );
00255 
00256       if( posIntersect.getX() < -49.0 )
00257         posIntersect.setX( -49.0 );
00258         
00259       // and move to this position
00260       if( posIntersect.getDistanceTo( WM->getAgentGlobalPosition() ) > 0.5 )
00261       {
00262         soc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() );
00263         ACT->putCommandInQueue( soc );
00264         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00265       }
00266       else
00267       {
00268         ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00269         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00270       }
00271     }
00272   }
00273   else if( WM->isFreeKickUs() == true || WM->isGoalKickUs() == true )
00274   {
00275     if( WM->isBallKickable() )
00276     {
00277       if( WM->getTimeSinceLastCatch() == 25 && WM->isFreeKickUs() )
00278       {
00279         // move to position with lesser opponents.
00280         if( WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
00281                                           Circle(posRightTop, 15.0 )) <
00282             WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
00283                                            Circle(posLeftTop,  15.0 )) )
00284           soc.makeCommand( CMD_MOVE,posRightTop.getX(),posRightTop.getY(),0.0);
00285         else
00286           soc.makeCommand( CMD_MOVE,posLeftTop.getX(), posLeftTop.getY(), 0.0);
00287         ACT->putCommandInQueue( soc );
00288       }
00289       else if( WM->getTimeSinceLastCatch() > 28 )
00290       {
00291         soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
00292         ACT->putCommandInQueue( soc );
00293       }
00294       else if( WM->getTimeSinceLastCatch() < 25 )
00295       {
00296         VecPosition posSide( 0.0, posAgent.getY() ); 
00297         if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 )
00298         {
00299           soc = turnBodyToPoint( posSide );
00300           ACT->putCommandInQueue( soc );
00301         }
00302         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00303       }
00304     }
00305     else if( WM->isGoalKickUs()  )
00306     {
00307       ACT->putCommandInQueue( soc = intercept( true ) );
00308       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00309     }
00310     else
00311       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00312   }
00313   else
00314   {
00315      ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00316      ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00317   }
00318   return soc;
00319 }
00320 
00321 

Generated on Fri Nov 7 11:45:40 2003 for UvA Trilearn 2003 Base Code by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001