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

SoccerTypes.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000,2001, 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 */
00049 #ifndef _SOCCERTYPES_
00050 #define _SOCCERTYPES_
00051 
00052 #include <iostream.h>     // needed for output stream.
00053 #include "Geometry.h"     // needed for AngDeg
00054 #include "ServerSettings.h"
00055 
00056 
00057 /******************************************************************************/
00058 /********************** DEFINES ***********************************************/
00059 /******************************************************************************/
00060 
00061 #define MAX_TEAMMATES          11       
00062 #define MAX_OPPONENTS          11       
00063 #define MAX_PLAYER_TYPES        8       
00065 #define MAX_FORMATION_TYPES     6       
00066 #define MAX_HETERO_PLAYERS      7       
00067 #define MAX_COMMANDS           10       
00068 #define MAX_MSG              2048       
00069 #define MAX_SAY_MSG           512       
00070 #define MAX_TEAM_NAME_LENGTH   64       
00071 #define MAX_FLAGS              55       
00072 #define MAX_LINES               4       
00073 #define DEFAULT_TEAM_NAME     "Team_L"  
00074 #define DEFAULT_OPPONENT_NAME "Team_R"  
00075 #define PITCH_LENGTH        105.0       
00076 #define PITCH_WIDTH          68.0       
00077 #define PITCH_MARGIN          5.0       
00078 #define PENALTY_AREA_LENGTH  16.5       
00079 #define PENALTY_AREA_WIDTH   40.35      
00080 #define PENALTY_X (PITCH_LENGTH/2.0-PENALTY_AREA_LENGTH) 
00084 /******************************************************************************/
00085 /********************** CONSTANTS *********************************************/
00086 /******************************************************************************/
00087 
00088 const double  UnknownDoubleValue  = -1000.0; 
00089 const AngDeg  UnknownAngleValue   = -1000.0; 
00090 const int     UnknownIntValue     = -1000;   
00091 const int     UnknownTime         = -20;     
00092 const long    UnknownMessageNr    = -30;     
00094 /******************************************************************************/
00095 /********************** ENUMERATIONS ******************************************/
00096 /******************************************************************************/
00097 
00102 enum ObjectT { // don't change order
00103   OBJECT_BALL,             
00104   OBJECT_GOAL_L,               // 2 goals
00105   OBJECT_GOAL_R,           
00106   OBJECT_GOAL_UNKNOWN,     
00107   OBJECT_LINE_L,               // 4 lines
00108   OBJECT_LINE_R,           
00109   OBJECT_LINE_B,           
00110   OBJECT_LINE_T,           
00111   OBJECT_FLAG_L_T,            // 53 flags
00112   OBJECT_FLAG_T_L_50,      
00113   OBJECT_FLAG_T_L_40,      
00114   OBJECT_FLAG_T_L_30,      
00115   OBJECT_FLAG_T_L_20,      
00116   OBJECT_FLAG_T_L_10,      
00117   OBJECT_FLAG_T_0,         
00118   OBJECT_FLAG_C_T,         
00119   OBJECT_FLAG_T_R_10,      
00120   OBJECT_FLAG_T_R_20,      
00121   OBJECT_FLAG_T_R_30,      
00122   OBJECT_FLAG_T_R_40,      
00123   OBJECT_FLAG_T_R_50,      
00124   OBJECT_FLAG_R_T,         
00125   OBJECT_FLAG_R_T_30,      
00126   OBJECT_FLAG_R_T_20,      
00127   OBJECT_FLAG_R_T_10,      
00128   OBJECT_FLAG_G_R_T,       
00129   OBJECT_FLAG_R_0,         
00130   OBJECT_FLAG_G_R_B,       
00131   OBJECT_FLAG_R_B_10,      
00132   OBJECT_FLAG_R_B_20,      
00133   OBJECT_FLAG_R_B_30,      
00134   OBJECT_FLAG_R_B,         
00135   OBJECT_FLAG_B_R_50,      
00136   OBJECT_FLAG_B_R_40,      
00137   OBJECT_FLAG_B_R_30,      
00138   OBJECT_FLAG_B_R_20,      
00139   OBJECT_FLAG_B_R_10,      
00140   OBJECT_FLAG_C_B,         
00141   OBJECT_FLAG_B_0,         
00142   OBJECT_FLAG_B_L_10,      
00143   OBJECT_FLAG_B_L_20,      
00144   OBJECT_FLAG_B_L_30,      
00145   OBJECT_FLAG_B_L_40,      
00146   OBJECT_FLAG_B_L_50,      
00147   OBJECT_FLAG_L_B,         
00148   OBJECT_FLAG_L_B_30,      
00149   OBJECT_FLAG_L_B_20,      
00150   OBJECT_FLAG_L_B_10,      
00151   OBJECT_FLAG_G_L_B,       
00152   OBJECT_FLAG_L_0,         
00153   OBJECT_FLAG_G_L_T,       
00154   OBJECT_FLAG_L_T_10,      
00155   OBJECT_FLAG_L_T_20,      
00156   OBJECT_FLAG_L_T_30,      
00157   OBJECT_FLAG_P_L_T,       
00158   OBJECT_FLAG_P_L_C,       
00159   OBJECT_FLAG_P_L_B,       
00160   OBJECT_FLAG_P_R_T,       
00161   OBJECT_FLAG_P_R_C,       
00162   OBJECT_FLAG_P_R_B,       
00163   OBJECT_FLAG_C,           
00164   OBJECT_TEAMMATE_1,           // teammates 61
00165   OBJECT_TEAMMATE_2,       
00166   OBJECT_TEAMMATE_3,       
00167   OBJECT_TEAMMATE_4,       
00168   OBJECT_TEAMMATE_5,       
00169   OBJECT_TEAMMATE_6,       
00170   OBJECT_TEAMMATE_7,       
00171   OBJECT_TEAMMATE_8,       
00172   OBJECT_TEAMMATE_9,       
00173   OBJECT_TEAMMATE_10,      
00174   OBJECT_TEAMMATE_11,      
00175   OBJECT_TEAMMATE_UNKNOWN, 
00176   OBJECT_OPPONENT_1,           // opponents 73
00177   OBJECT_OPPONENT_2,       
00178   OBJECT_OPPONENT_3,       
00179   OBJECT_OPPONENT_4,       
00180   OBJECT_OPPONENT_5,       
00181   OBJECT_OPPONENT_6,       
00182   OBJECT_OPPONENT_7,       
00183   OBJECT_OPPONENT_8,       
00184   OBJECT_OPPONENT_9,       
00185   OBJECT_OPPONENT_10,      
00186   OBJECT_OPPONENT_11,      
00187   OBJECT_OPPONENT_UNKNOWN, 
00188   OBJECT_PLAYER_UNKNOWN,   
00189   OBJECT_UNKNOWN,          
00190   OBJECT_TEAMMATE_GOALIE,  
00191   OBJECT_OPPONENT_GOALIE,  
00192   OBJECT_ILLEGAL,          
00193   OBJECT_MAX_OBJECTS        // 90
00194 } ;
00195 
00198 enum ObjectSetT
00199 {
00200   OBJECT_SET_TEAMMATES,  
00201   OBJECT_SET_OPPONENTS,  
00202   OBJECT_SET_PLAYERS,    
00203   OBJECT_SET_FLAGS,      
00204   OBJECT_SET_LINES,      
00205   OBJECT_SET_ILLEGAL     
00206 } ;
00207 
00211 enum PlayModeT {
00212   PM_BEFORE_KICK_OFF,  
00213   PM_KICK_OFF_LEFT,    
00214   PM_KICK_OFF_RIGHT,   
00215   PM_KICK_IN_LEFT,     
00216   PM_KICK_IN_RIGHT,    
00217   PM_CORNER_KICK_LEFT, 
00218   PM_CORNER_KICK_RIGHT,
00219   PM_GOAL_KICK_LEFT,   
00220   PM_GOAL_KICK_RIGHT,  
00221   PM_GOAL_LEFT,        
00222   PM_GOAL_RIGHT,       
00223   PM_FREE_KICK_LEFT,   
00224   PM_FREE_KICK_RIGHT,  
00225   PM_OFFSIDE_LEFT,     
00226   PM_OFFSIDE_RIGHT,    
00227   PM_PLAY_ON,          
00228   PM_TIME_OVER,        
00229   PM_FROZEN,           
00230   PM_QUIT,             
00231   PM_ILLEGAL           
00232 } ;
00233 
00237 enum RefereeMessageT {
00238   REFC_ILLEGAL,                
00239   REFC_BEFORE_KICK_OFF,        
00240   REFC_KICK_OFF_LEFT,          
00241   REFC_KICK_OFF_RIGHT,         
00242   REFC_KICK_IN_LEFT,           
00243   REFC_KICK_IN_RIGHT,          
00244   REFC_CORNER_KICK_LEFT,       
00245   REFC_CORNER_KICK_RIGHT,      
00246   REFC_GOAL_KICK_LEFT,         
00247   REFC_GOAL_KICK_RIGHT,        
00248   REFC_FREE_KICK_LEFT,         
00249   REFC_FREE_KICK_RIGHT,        
00250   REFC_PLAY_ON,                
00251   REFC_TIME_OVER,              
00252   REFC_FROZEN,                 
00253   REFC_QUIT,                   
00254   REFC_OFFSIDE_LEFT,           
00255   REFC_OFFSIDE_RIGHT,          
00256   REFC_HALF_TIME,              
00257   REFC_TIME_UP,                
00258   REFC_TIME_UP_WITHOUT_A_TEAM, 
00259   REFC_TIME_EXTENDED,          
00260   REFC_FOUL_LEFT,              
00261   REFC_FOUL_RIGHT,             
00262   REFC_GOAL_LEFT,              
00263   REFC_GOAL_RIGHT,             
00264   REFC_DROP_BALL,              
00265   REFC_GOALIE_CATCH_BALL_LEFT, 
00266   REFC_GOALIE_CATCH_BALL_RIGHT 
00267 } ;
00268 
00271 enum ViewAngleT  {
00272   VA_NARROW,  
00273   VA_NORMAL,  
00274   VA_WIDE,    
00275   VA_ILLEGAL  
00276 };
00277 
00280 enum ViewQualityT {
00281   VQ_HIGH,    
00282   VQ_LOW,     
00283   VQ_ILLEGAL  
00284 };
00285 
00287 enum SideT {
00288   SIDE_LEFT,     
00289   SIDE_RIGHT,    
00290   SIDE_ILLEGAL   
00291 } ;
00292 
00295 enum CommandT {
00296   CMD_ILLEGAL,      
00297   CMD_DASH,         
00298   CMD_TURN,         
00299   CMD_TURNNECK,     
00300   CMD_CHANGEVIEW,   
00301   CMD_CATCH,        
00302   CMD_KICK,         
00303   CMD_MOVE,         
00304   CMD_SENSEBODY,    
00305   CMD_SAY,          
00306   CMD_CHANGEPLAYER, 
00307   CMD_MAX_COMMANDS  
00309 } ;
00310 
00316 enum PlayerT {
00317   PT_ILLEGAL,             
00318   PT_GOALKEEPER,          
00319   PT_DEFENDER_SWEEPER,    
00320   PT_DEFENDER_WING,       
00321   PT_MIDFIELDER_CENTER,   
00322   PT_MIDFIELDER_WING,     
00323   PT_ATTACKER_WING,       
00324   PT_ATTACKER             
00325 } ;
00326 
00329 enum FormationT {
00330   FT_ILLEGAL,             
00331   FT_INITIAL,             
00332   FT_STANDARD,            
00333   FT_DEFENSIVE,           
00334   FT_OPEN_DEFENSIVE,      
00335   FT_ATTACKING            
00336 } ;
00337 
00340 enum BallStatusT {
00341   BS_ILLEGAL,           
00342   BS_IN_FIELD,          
00343   BS_GOAL_LEFT,         
00344   BS_GOAL_RIGHT,        
00345   BS_OUT_OF_FIELD       
00346 } ;
00347 
00349 enum ActionT {
00350   ACT_ILLEGAL,                    
00351   ACT_SEARCH_BALL,                
00352   ACT_KICK_BALL,                  
00353   ACT_CATCH_BALL,                 
00354   ACT_INTERCEPT,                  
00355   ACT_MARK,                       
00356   ACT_TELEPORT_TO_STRATEGIC_POSITION, 
00357   ACT_WATCH_BALL,                 
00358   ACT_GOTO_STRATEGIC_POSITION,    
00359   ACT_TURN_BODY_TO_CENTER,        
00360   ACT_MOVE_TO_DEAD_BALL_POSITION, 
00361   ACT_INTERCEPT_SCORING_ATTEMPT,  
00362   ACT_DEFEND_GOALLINE,            
00363   ACT_TELEPORT_AFTER_CATCH        
00364 } ;
00365 
00367 enum MarkT {
00368   MARK_ILLEGAL,    
00369   MARK_GOAL,       
00370   MARK_BISECTOR,   
00371   MARK_BALL        
00372 } ;
00373 
00375 enum DribbleT {
00376   DRIBBLE_ILLEGAL, 
00377   DRIBBLE_WITHBALL,
00378   DRIBBLE_SLOW,    
00379   DRIBBLE_FAST     
00380 } ;
00381 
00383 enum PassT {
00384   PASS_ILLEGAL,    
00385   PASS_FAST,       
00386   PASS_NORMAL      
00387 } ;
00388 
00390 enum ClearBallT {
00391   CLEAR_BALL_ILLEGAL,    
00392   CLEAR_BALL_OFFENSIVE,  
00393   CLEAR_BALL_DEFENSIVE,  
00394   CLEAR_BALL_GOAL        
00395 } ;
00396 
00397 /******************************************************************************/
00398 /********************** CLASS TIME   ******************************************/
00399 /******************************************************************************/
00400 
00413 class Time
00414 {
00415   int m_iTime;            
00416   int m_iStopped;         
00418 public:
00419          Time             ( int     iTime = -1, int iStopped = 0 );
00420   bool   updateTime       ( int     iTime                        );
00421   bool   setTimeStopped   ( int     iTime                        );
00422   int    getTime          (                                      );
00423   int    getTimeStopped   (                                      );
00424   int    getTimeDifference( Time    t                            );
00425   bool   isStopped        (                                      );
00426   Time   getTimeAddedWith ( int     iCycles                      );
00427   bool   addToTime        ( int     iCycles                      );
00428   void   show             ( ostream &os = cout                   );
00429 
00430   // overloaded arithmetic operators
00431   Time   operator +       ( const int  &i );
00432   Time   operator +       ( Time t );
00433   Time   operator -       ( const int  &i );
00434   int    operator -       ( Time t );
00435   void   operator =       ( const int  &i );
00436   void   operator +=      ( Time t );
00437   void   operator +=      ( const int  &i );
00438   void   operator -=      ( Time t );
00439   void   operator -=      ( const int  &i );
00440   bool   operator !=      ( Time t );
00441   bool   operator !=      ( const int  &i );
00442   bool   operator ==      ( Time t );
00443   bool   operator ==      ( const int  &i );
00444   bool   operator <       ( Time t );
00445   bool   operator <       ( const int  &i );
00446   bool   operator <=      ( Time t );
00447   bool   operator <=      ( const int  &i );
00448   bool   operator >       ( Time t );
00449   bool   operator >       ( const int  &i );
00450   bool   operator >=      ( Time t );
00451   bool   operator >=      ( const int  &i );
00452 
00453 
00454   // methods for producing output
00455   friend ostream&   operator << ( ostream &os, Time t );
00456 } ;
00457 
00458 /******************************************************************************/
00459 /********************** CLASS SOCCERCOMMAND ***********************************/
00460 /******************************************************************************/
00461 
00467 class SoccerCommand
00468 {
00469   ServerSettings *SS; 
00471   // private methods to generate text string to sent to server
00472   bool  makeCatchCommand       ( char *str );
00473   bool  makeChangeViewCommand  ( char *str );
00474   bool  makeDashCommand        ( char *str );
00475   bool  makeKickCommand        ( char *str );
00476   bool  makeMoveCommand        ( char *str );
00477   bool  makeSayCommand         ( char *str );
00478   bool  makeSenseBodyCommand   ( char *str );
00479   bool  makeTurnCommand        ( char *str );
00480   bool  makeTurnNeckCommand    ( char *str );
00481   bool  makeChangePlayerCommand( char *str );
00482 
00483 public:
00484 
00485   // different variables that are used by the different possible commands
00486   // only the variables that are related to the current commandType have
00487   // legal values
00488   Time         time;        
00489   CommandT     commandType; 
00490   double       dAngle;      
00491   double       dPower;      
00492   ViewQualityT vq;          
00493   ViewAngleT   va;          
00494   double       dX;          
00495   double       dY;          
00496   char         str[MAX_SAY_MSG];
00497   int          iTimes;      
00499   SoccerCommand( CommandT com = CMD_ILLEGAL, double d1=UnknownDoubleValue,
00500                                              double d2=UnknownDoubleValue,
00501                                              double d3=UnknownDoubleValue );
00502   SoccerCommand( CommandT com,               char   *msg                  );
00503 
00504   // command to set the different values of the SoccerCommand
00505   void makeCommand( CommandT com, double     d1 = UnknownDoubleValue,
00506                                   double     d2 = UnknownDoubleValue,
00507                                   double     d3 = UnknownDoubleValue      );
00508   void makeCommand( CommandT com, ViewAngleT v,    ViewQualityT q         );
00509   void makeCommand( CommandT com, char       *msg                         );     
00510   
00511   bool isIllegal  (                                                       );
00512 
00513   void show       ( ostream& os                                           );
00514 
00515   // used to return the string representation of this SoccerCommand
00516   char* getCommandString( char *str,         ServerSettings *ss           );
00517 } ;
00518 
00519 /******************************************************************************/
00520 /********************** CLASS SOCCERTYPES *************************************/
00521 /******************************************************************************/
00522 
00528 class SoccerTypes
00529 {
00530  public:
00531   // methods that deal with the differen objects
00532   static char*           getObjectStr              ( char         *strBuf,
00533                                                      ObjectT      o,
00534                                                      const char   *strTeam    );
00535   static ObjectT         getObjectFromStr          ( char         **str,
00536                                                      bool         *isGoalie,
00537                                                      const char   *str        );
00538   static bool            isInSet                   ( ObjectT      o,
00539                                                      ObjectSetT   o_s         );
00540   static bool            isFlag                    ( ObjectT      o           );
00541   static bool            isLine                    ( ObjectT      o           );
00542   static bool            isGoal                    ( ObjectT      o           );
00543   static ObjectT         getOwnGoal                ( SideT        s           );
00544   static ObjectT         getGoalOpponent           ( SideT        s           );
00545   static bool            isBall                    ( ObjectT      o           );
00546   static bool            isTeammate                ( ObjectT      o           );
00547   static bool            isOpponent                ( ObjectT      o           );
00548   static bool            isGoalie                  ( ObjectT      o           );
00549   static bool            isPlayer                  ( ObjectT      o           );
00550   static bool            isKnownPlayer             ( ObjectT      o           );
00551   static int             getIndex                  ( ObjectT      o           );
00552   static ObjectT         getTeammateObjectFromIndex( int          iIndex      );
00553   static ObjectT         getOpponentObjectFromIndex( int          iIndex      );
00554   static VecPosition     getGlobalPositionFlag     ( ObjectT      o,
00555                                                      SideT        s,
00556                                                      double dGoalWidth = 14.02);
00557   static AngDeg          getGlobalAngleLine        ( ObjectT      o,
00558                                                      SideT        s           );
00559 
00560   // methods that deal with the differen play modes
00561   static PlayModeT       getPlayModeFromStr        ( char         *str        );
00562   static PlayModeT       getPlayModeFromRefereeMessage( RefereeMessageT rm    );
00563   static char*           getPlayModeStr            ( PlayModeT    p           );
00564   static char*           getRefereeMessageStr      ( RefereeMessageT r        );
00565   static RefereeMessageT getRefereeMessageFromStr  ( char         *str        );
00566 
00567   // methods that deal with the frequency of the visual information
00568   static char*           getViewAngleStr           ( ViewAngleT   v           );
00569   static ViewAngleT      getViewAngleFromStr       ( char         *str        );
00570   static AngDeg          getHalfViewAngleValue     ( ViewAngleT   va          );
00571   static char*           getViewQualityStr         ( ViewQualityT v           );
00572   static ViewQualityT    getViewQualityFromStr     ( char         *str        );
00573 
00574   // methods that deal with the commands
00575   static char*           getCommandStr             ( CommandT     com         );
00576   static bool            isPrimaryCommand          ( CommandT     com         );
00577 
00578   // methods that deal with the side information
00579   static char*           getSideStr                ( SideT        s           );
00580   static SideT           getSideFromStr            ( char*        str         );
00581 
00582   // methods that deal with the status of the ball.
00583   static char*           getBallStatusStr          ( BallStatusT  bs          );
00584   static BallStatusT     getBallStatusFromStr      ( char         *str        );
00585 } ;
00586 
00587 #endif

Generated on Thu Mar 7 00:37:43 2002 for UvA Trilearn 2001 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001