00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00054 #ifndef _SOCCERTYPES_
00055 #define _SOCCERTYPES_
00056
00057 #include <iostream>
00058 #include "Geometry.h"
00059 #include "ServerSettings.h"
00060
00061
00062
00063
00064
00065
00066 #define MAX_TEAMMATES 11
00067 #define MAX_OPPONENTS 11
00068 #define MAX_HETERO_PLAYERS 7
00069 #define MAX_MSG 4096
00070 #define MAX_SAY_MSG 10
00071 #define MAX_TEAM_NAME_LENGTH 64
00072 #define MAX_FLAGS 55
00073 #define MAX_LINES 4
00074 #define DEFAULT_TEAM_NAME "Team_L"
00075 #define DEFAULT_OPPONENT_NAME "Team_R"
00076 #define PITCH_LENGTH 105.0
00077 #define PITCH_WIDTH 68.0
00078 #define PITCH_MARGIN 5.0
00079 #define PENALTY_AREA_LENGTH 16.5
00080 #define PENALTY_AREA_WIDTH 40.32
00081 #define PENALTY_X (PITCH_LENGTH/2.0-PENALTY_AREA_LENGTH)
00085
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
00096
00097
00102 enum ObjectT {
00103 OBJECT_BALL,
00104 OBJECT_GOAL_L,
00105 OBJECT_GOAL_R,
00106 OBJECT_GOAL_UNKNOWN,
00107 OBJECT_LINE_L,
00108 OBJECT_LINE_R,
00109 OBJECT_LINE_B,
00110 OBJECT_LINE_T,
00111 OBJECT_FLAG_L_T,
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,
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,
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
00194 } ;
00195
00198 enum ObjectSetT
00199 {
00200 OBJECT_SET_TEAMMATES,
00201 OBJECT_SET_OPPONENTS,
00202 OBJECT_SET_PLAYERS,
00203 OBJECT_SET_TEAMMATES_NO_GOALIE,
00204 OBJECT_SET_FLAGS,
00205 OBJECT_SET_LINES,
00206 OBJECT_SET_ILLEGAL
00207 } ;
00208
00212 enum PlayModeT {
00213 PM_BEFORE_KICK_OFF,
00214 PM_KICK_OFF_LEFT,
00215 PM_KICK_OFF_RIGHT,
00216 PM_KICK_IN_LEFT,
00217 PM_KICK_IN_RIGHT,
00218 PM_CORNER_KICK_LEFT,
00219 PM_CORNER_KICK_RIGHT,
00220 PM_GOAL_KICK_LEFT,
00221 PM_GOAL_KICK_RIGHT,
00222 PM_GOAL_LEFT,
00223 PM_GOAL_RIGHT,
00224 PM_FREE_KICK_FAULT_LEFT,
00225 PM_FREE_KICK_FAULT_RIGHT,
00226 PM_FREE_KICK_LEFT,
00227 PM_FREE_KICK_RIGHT,
00228 PM_INDIRECT_FREE_KICK_RIGHT,
00229 PM_INDIRECT_FREE_KICK_LEFT,
00230 PM_BACK_PASS_LEFT,
00231 PM_BACK_PASS_RIGHT,
00232 PM_OFFSIDE_LEFT,
00233 PM_OFFSIDE_RIGHT,
00234 PM_PLAY_ON,
00235 PM_TIME_OVER,
00236 PM_PENALTY_SETUP_LEFT,
00237 PM_PENALTY_SETUP_RIGHT,
00238 PM_PENALTY_READY_LEFT,
00239 PM_PENALTY_READY_RIGHT,
00240 PM_PENALTY_TAKEN_LEFT,
00241 PM_PENALTY_TAKEN_RIGHT,
00242 PM_FROZEN,
00243 PM_QUIT,
00244 PM_ILLEGAL
00245 } ;
00246
00250 enum RefereeMessageT {
00251 REFC_ILLEGAL,
00252 REFC_BEFORE_KICK_OFF,
00253 REFC_KICK_OFF_LEFT,
00254 REFC_KICK_OFF_RIGHT,
00255 REFC_KICK_IN_LEFT,
00256 REFC_KICK_IN_RIGHT,
00257 REFC_CORNER_KICK_LEFT,
00258 REFC_CORNER_KICK_RIGHT,
00259 REFC_GOAL_KICK_LEFT,
00260 REFC_GOAL_KICK_RIGHT,
00261 REFC_FREE_KICK_LEFT,
00262 REFC_FREE_KICK_RIGHT,
00263 REFC_INDIRECT_FREE_KICK_RIGHT,
00264 REFC_INDIRECT_FREE_KICK_LEFT,
00265 REFC_FREE_KICK_FAULT_LEFT,
00266 REFC_FREE_KICK_FAULT_RIGHT,
00267 REFC_BACK_PASS_LEFT,
00268 REFC_BACK_PASS_RIGHT,
00269 REFC_PLAY_ON,
00270 REFC_TIME_OVER,
00271 REFC_FROZEN,
00272 REFC_QUIT,
00273 REFC_OFFSIDE_LEFT,
00274 REFC_OFFSIDE_RIGHT,
00275 REFC_HALF_TIME,
00276 REFC_TIME_UP,
00277 REFC_TIME_UP_WITHOUT_A_TEAM,
00278 REFC_TIME_EXTENDED,
00279 REFC_FOUL_LEFT,
00280 REFC_FOUL_RIGHT,
00281 REFC_GOAL_LEFT,
00282 REFC_GOAL_RIGHT,
00283 REFC_DROP_BALL,
00284 REFC_GOALIE_CATCH_BALL_LEFT,
00285 REFC_GOALIE_CATCH_BALL_RIGHT,
00286 REFC_PENALTY_SETUP_LEFT,
00287 REFC_PENALTY_SETUP_RIGHT,
00288 REFC_PENALTY_READY_LEFT,
00289 REFC_PENALTY_READY_RIGHT,
00290 REFC_PENALTY_TAKEN_LEFT,
00291 REFC_PENALTY_TAKEN_RIGHT,
00292 REFC_PENALTY_MISS_LEFT,
00293 REFC_PENALTY_MISS_RIGHT,
00294 REFC_PENALTY_SCORE_LEFT,
00295 REFC_PENALTY_SCORE_RIGHT,
00296 REFC_PENALTY_FOUL_LEFT,
00297 REFC_PENALTY_FOUL_RIGHT,
00298 REFC_PENALTY_ONFIELD_LEFT,
00299 REFC_PENALTY_ONFIELD_RIGHT,
00300 REFC_PENALTY_WINNER_LEFT,
00301 REFC_PENALTY_WINNER_RIGHT,
00302 REFC_PENALTY_DRAW
00303 } ;
00304
00307 enum ViewAngleT {
00308 VA_NARROW,
00309 VA_NORMAL,
00310 VA_WIDE,
00311 VA_ILLEGAL
00312 };
00313
00316 enum ViewQualityT {
00317 VQ_HIGH,
00318 VQ_LOW,
00319 VQ_ILLEGAL
00320 };
00321
00323 enum SideT {
00324 SIDE_LEFT,
00325 SIDE_RIGHT,
00326 SIDE_ILLEGAL
00327 } ;
00328
00331 enum CommandT {
00332 CMD_ILLEGAL,
00333 CMD_DASH,
00334 CMD_TURN,
00335 CMD_TURNNECK,
00336 CMD_CHANGEVIEW,
00337 CMD_CATCH,
00338 CMD_KICK,
00339 CMD_MOVE,
00340 CMD_SENSEBODY,
00341 CMD_SAY,
00342 CMD_CHANGEPLAYER,
00343 CMD_ATTENTIONTO,
00344 CMD_TACKLE,
00345 CMD_POINTTO,
00346 CMD_MAX_COMMANDS
00347 } ;
00348
00354 enum PlayerT {
00355 PT_ILLEGAL,
00356 PT_GOALKEEPER,
00357 PT_DEFENDER_CENTRAL,
00358 PT_DEFENDER_SWEEPER,
00359 PT_DEFENDER_WING,
00360 PT_MIDFIELDER_CENTER,
00361 PT_MIDFIELDER_WING,
00362 PT_ATTACKER_WING,
00363 PT_ATTACKER,
00364 MAX_PLAYER_TYPES
00365 } ;
00366
00369 enum PlayerSetT {
00370 PS_DEFENDERS,
00371 PS_MIDFIELDERS,
00372 PS_ATTACKERS,
00373 PS_ALL
00374 } ;
00375
00378 enum FormationT {
00379 FT_ILLEGAL,
00380 FT_INITIAL,
00381 FT_433_OFFENSIVE,
00382 FT_334_OFFENSIVE,
00383 FT_DEFENSIVE,
00384 FT_OPEN_DEFENSIVE,
00385 FT_343_ATTACKING,
00386 MAX_FORMATION_TYPES
00387 } ;
00388
00391 enum BallStatusT {
00392 BS_ILLEGAL,
00393 BS_IN_FIELD,
00394 BS_GOAL_LEFT,
00395 BS_GOAL_RIGHT,
00396 BS_OUT_OF_FIELD
00397 } ;
00398
00400 enum ActionT {
00401 ACT_ILLEGAL,
00402 ACT_SEARCH_BALL,
00403 ACT_KICK_BALL,
00404 ACT_CATCH_BALL,
00405 ACT_INTERCEPT,
00406 ACT_MARK,
00407 ACT_TELEPORT_TO_STRATEGIC_POSITION,
00408 ACT_WATCH_BALL,
00409 ACT_ANTICIPATE_BALL,
00410 ACT_GOTO_STRATEGIC_POSITION,
00411 ACT_TURN_BODY_TO_CENTER,
00412 ACT_MOVE_TO_DEAD_BALL_POSITION,
00413 ACT_INTERCEPT_SCORING_ATTEMPT,
00414 ACT_DEFEND_GOALLINE,
00415 ACT_TELEPORT_AFTER_CATCH,
00416 ACT_TACKLE,
00417 ACT_HOLD_BALL
00418 } ;
00419
00420
00422 enum MarkT {
00423 MARK_ILLEGAL,
00424 MARK_GOAL,
00425 MARK_BISECTOR,
00426 MARK_BALL
00427 } ;
00428
00430 enum DribbleT {
00431 DRIBBLE_ILLEGAL,
00432 DRIBBLE_WITHBALL,
00433 DRIBBLE_SLOW,
00434 DRIBBLE_FAST
00435 } ;
00436
00438 enum PassT {
00439 PASS_ILLEGAL,
00440 PASS_FAST,
00441 PASS_NORMAL
00442 } ;
00443
00445 enum ClearBallT {
00446 CLEAR_BALL_ILLEGAL,
00447 CLEAR_BALL_OFFENSIVE,
00448 CLEAR_BALL_DEFENSIVE,
00449 CLEAR_BALL_OFFENSIVE_SIDE,
00450 CLEAR_BALL_GOAL
00451 } ;
00452
00455 enum TiredNessT {
00456 TIREDNESS_ILLEGAL,
00457 TIREDNESS_GOOD,
00458 TIREDNESS_AVERAGE,
00459 TIREDNESS_BAD,
00460 TIREDNESS_VERY_BAD,
00461 TIREDNESS_TERRIBLE
00462 } ;
00463
00470 enum FeatureT {
00471 FEATURE_ILLEGAL,
00472 FEATURE_FASTEST_OPPONENT_TO_BALL,
00473 FEATURE_FASTEST_TEAMMATE_TO_BALL,
00474 FEATURE_FASTEST_PLAYER_TO_BALL,
00475 FEATURE_FASTEST_TEAMMATE_TO_BALL_NO_GOALIE,
00476 FEATURE_INTERCEPTION_POINT_BALL,
00477 FEATURE_INTERCEPT_CLOSE,
00478 FEATURE_INTERCEPT_CYCLES_ME,
00479 FEATURE_BEST_SCORING_POINT,
00480 MAX_FEATURES
00481 } ;
00482
00484 enum DirectionT {
00485 DIR_ILLEGAL,
00486 DIR_NORTH,
00487 DIR_NORTHWEST,
00488 DIR_NORTHEAST,
00489 DIR_CENTER,
00490 DIR_EAST,
00491 DIR_WEST,
00492 DIR_SOUTHWEST,
00493 DIR_SOUTHEAST,
00494 DIR_SOUTH,
00495 DIR_MAX
00496 } ;
00497
00499 enum SucceedT {
00500 SUCCEED_ILLEGAL,
00501 SUCCEED_ALWAYS,
00502 SUCCEED_DOUBTFUL,
00503 SUCCEED_NEVER
00504 } ;
00505
00506
00507
00508
00509
00510
00523 class Time
00524 {
00525 int m_iTime;
00526 int m_iStopped;
00528 public:
00529 Time ( int iTime = -1, int iStopped = 0 );
00530 bool updateTime ( int iTime );
00531 bool setTimeStopped ( int iTime );
00532 int getTime ( );
00533 int getTimeStopped ( );
00534 int getTimeDifference( Time t );
00535 bool isStopped ( );
00536 Time getTimeAddedWith ( int iCycles );
00537 bool addToTime ( int iCycles );
00538 void show ( ostream &os = cout );
00539
00540
00541 Time operator + ( const int &i );
00542 Time operator + ( Time t );
00543 Time operator - ( const int &i );
00544 int operator - ( Time t );
00545 void operator = ( const int &i );
00546 void operator += ( Time t );
00547 void operator += ( const int &i );
00548 void operator -= ( Time t );
00549 void operator -= ( const int &i );
00550 bool operator != ( Time t );
00551 bool operator != ( const int &i );
00552 bool operator == ( Time t );
00553 bool operator == ( const int &i );
00554 bool operator < ( Time t );
00555 bool operator < ( const int &i );
00556 bool operator <= ( Time t );
00557 bool operator <= ( const int &i );
00558 bool operator > ( Time t );
00559 bool operator > ( const int &i );
00560 bool operator >= ( Time t );
00561 bool operator >= ( const int &i );
00562
00563
00564
00565 friend ostream& operator << ( ostream &os, Time t );
00566 } ;
00567
00568
00569
00570
00571
00572
00578 class SoccerCommand
00579 {
00580 ServerSettings *SS;
00582
00583 bool makeCatchCommand ( char *str );
00584 bool makeChangeViewCommand ( char *str );
00585 bool makeDashCommand ( char *str );
00586 bool makeKickCommand ( char *str );
00587 bool makeMoveCommand ( char *str );
00588 bool makeSayCommand ( char *str );
00589 bool makeSenseBodyCommand ( char *str );
00590 bool makeTurnCommand ( char *str );
00591 bool makeTurnNeckCommand ( char *str );
00592 bool makeChangePlayerCommand( char *str );
00593 bool makeAttentionToCommand ( char *str );
00594 bool makeTackleCommand ( char *str );
00595 bool makePointToCommand ( char *str );
00596
00597 public:
00598
00599
00600
00601
00602 Time time;
00603 CommandT commandType;
00604 double dAngle;
00605 double dPower;
00606 ViewQualityT vq;
00607 ViewAngleT va;
00608 double dX;
00609 double dY;
00610 char str[MAX_SAY_MSG];
00611 int iTimes;
00613 SoccerCommand( CommandT com = CMD_ILLEGAL, double d1=UnknownDoubleValue,
00614 double d2=UnknownDoubleValue,
00615 double d3=UnknownDoubleValue );
00616 SoccerCommand( CommandT com, char *msg );
00617
00618
00619 void makeCommand( CommandT com, double d1 = UnknownDoubleValue,
00620 double d2 = UnknownDoubleValue,
00621 double d3 = UnknownDoubleValue );
00622 void makeCommand( CommandT com, ViewAngleT v, ViewQualityT q );
00623 void makeCommand( CommandT com, char *msg );
00624
00625 bool isIllegal ( );
00626
00627 void show ( ostream& os );
00628
00629
00630 bool getCommandString( char *str, ServerSettings *ss );
00631 } ;
00632
00633
00634
00635
00636
00641 class Feature
00642 {
00643 Time m_timeSee;
00644 Time m_timeSense;
00645 Time m_timeHear;
00646 ObjectT m_object;
00647 double m_dInfo;
00648 VecPosition m_vec;
00649 SoccerCommand m_soc;
00651 public:
00652
00653 Feature( );
00654 Feature( Time timeSee,
00655 Time timeSense,
00656 Time timeHear,
00657 ObjectT object,
00658 double dInfo = UnknownDoubleValue,
00659 SoccerCommand soc = SoccerCommand(CMD_ILLEGAL),
00660 VecPosition pos = VecPosition(0,0) );
00661 bool setFeature ( Time timeSee,
00662 Time timeSense,
00663 Time timeHear,
00664 ObjectT object,
00665 double dInfo = UnknownDoubleValue,
00666 SoccerCommand soc = SoccerCommand(CMD_ILLEGAL),
00667 VecPosition pos = VecPosition(0,0) );
00668 bool setTimeSee ( Time time );
00669 Time getTimeSee ( );
00670 bool setTimeSense( Time time );
00671 Time getTimeSense( );
00672 bool setTimeHear ( Time time );
00673 Time getTimeHear ( );
00674 bool setObject ( ObjectT obj );
00675 ObjectT getObject ( );
00676 bool setInfo ( double d );
00677 double getInfo ( );
00678 bool setVec ( VecPosition pos );
00679 VecPosition getVec ( );
00680 bool setCommand ( SoccerCommand soc );
00681 SoccerCommand getCommand ( );
00682
00683 } ;
00684
00685
00686
00687
00688
00695 class SoccerTypes
00696 {
00697 public:
00698
00699 static char* getObjectStr ( char *strBuf,
00700 ObjectT o,
00701 const char *strTe=NULL);
00702 static ObjectT getObjectFromStr ( char **str,
00703 bool *isGoalie,
00704 const char *strTeam );
00705 static bool isInSet ( ObjectT o,
00706 ObjectSetT o_s,
00707 ObjectT objectGoalie=
00708 OBJECT_TEAMMATE_1 );
00709 static bool isPlayerTypeInSet ( PlayerT p,
00710 PlayerSetT p_s );
00711 static bool isFlag ( ObjectT o );
00712 static bool isLine ( ObjectT o );
00713 static bool isGoal ( ObjectT o );
00714 static ObjectT getOwnGoal ( SideT s );
00715 static ObjectT getGoalOpponent ( SideT s );
00716 static bool isBall ( ObjectT o );
00717 static bool isTeammate ( ObjectT o );
00718 static bool isOpponent ( ObjectT o );
00719 static bool isGoalie ( ObjectT o );
00720 static bool isPlayer ( ObjectT o );
00721 static bool isKnownPlayer ( ObjectT o );
00722 static int getIndex ( ObjectT o );
00723 static ObjectT getTeammateObjectFromIndex( int iIndex );
00724 static ObjectT getOpponentObjectFromIndex( int iIndex );
00725 static VecPosition getGlobalPositionFlag ( ObjectT o,
00726 SideT s,
00727 double dGoalWidth =14.02);
00728 static AngDeg getGlobalAngleLine ( ObjectT o,
00729 SideT s );
00730
00731
00732 static PlayModeT getPlayModeFromStr ( char *str );
00733 static PlayModeT getPlayModeFromRefereeMessage( RefereeMessageT rm );
00734 static char* getPlayModeStr ( PlayModeT p );
00735 static char* getRefereeMessageStr ( RefereeMessageT r );
00736 static RefereeMessageT getRefereeMessageFromStr ( char *str );
00737
00738
00739 static char* getViewAngleStr ( ViewAngleT v );
00740 static ViewAngleT getViewAngleFromStr ( char *str );
00741 static AngDeg getHalfViewAngleValue ( ViewAngleT va );
00742 static char* getViewQualityStr ( ViewQualityT v );
00743 static ViewQualityT getViewQualityFromStr ( char *str );
00744
00745
00746 static char* getCommandStr ( CommandT com );
00747 static bool isPrimaryCommand ( CommandT com );
00748
00749
00750 static char* getSideStr ( SideT s );
00751 static SideT getSideFromStr ( char* str );
00752
00753
00754 static char* getBallStatusStr ( BallStatusT bs );
00755 static BallStatusT getBallStatusFromStr ( char *str );
00756
00757 static AngDeg getAngleFromDirection ( DirectionT dir );
00758 } ;
00759
00760 #endif