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

Generated on Tue Jul 2 10:18:54 2002 for UvA Trilearn 2002 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001