src/Player.h

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 
00049 #ifndef PLAYER
00050 #define PLAYER
00051 
00052 #include "BasicPlayer.h"
00053 #include "Formations.h"     // needed for Formations
00054 #include "SituationsLog.h"  // needed for SituationsMonitoring
00055 #include "SoccerTypes.h"        // needed for UnknownDoubleValue
00056 #include "ArsToolbox.h"
00057 #include "PlayerActionCG.h" // needed for Coordination Graphs
00058 
00059 #ifdef WIN32
00060   DWORD WINAPI stdin_callback( LPVOID v );
00061 #else
00062   void* stdin_callback( void * v );
00063 #endif
00064 
00065 #include <stdio.h>
00066 
00067 // possible player roles
00068 
00071 class Player:public BasicPlayer
00072 {
00073   SituationsLog *log;                    
00074   Formations    *formations;             
00075   bool          bContLoop;               
00078   Time          m_timeLastSay;           
00079   ObjectT       m_objMarkOpp;            
00080   ObjectT       m_objPassOption;         
00082   int           m_iPenaltyNr;            
00084   ActionT       m_actionPrev;            
00086   SoccerCommand goalieMainLoop            (                                  );
00087   SoccerCommand defenderMainLoop          (                                  );
00088   SoccerCommand midfielderMainLoop        (                                  );
00089   SoccerCommand attackerMainLoop          (                                  );
00090 
00091   void          performPenalty            (                                  );
00092 
00093 
00094   VecPosition   getDeadBallPosition       (                                  );
00095   VecPosition   goalMiddle;     
00096 
00097   // methods associated with saying (defined in Player.C)
00098   bool          shallISaySomething        ( SoccerCommand  soc               );
00099   bool          amIAgentToSaySomething    ( SoccerCommand  soc               );
00100   void          sayOppAttackerStatus      ( char *         str               );
00101   void          sayBallStatus             ( char *         str               );
00102   void          makeBallInfo              ( VecPosition    posBall,
00103                                             VecPosition    velBall,
00104                                             int            iDiff, 
00105                                             char *         str               );
00106 
00107 public:
00108   Player                                  ( ActHandler     *a,
00109                                             WorldModel     *wm,
00110                                             ServerSettings *ss,
00111                                             PlayerSettings *cs,
00112                                             Formations     *fs,
00113                                             char           *strTeamName,
00114                                             double         dVersion,
00115                                             int            iReconnect = -1   );
00116   ~Player();
00117 
00118   void          mainLoop                  (                                  );
00119 
00120 
00121   // methods that deal with user input (from keyboard) to sent commands
00122   void          handleStdin               (                                  );
00123   void          showStringCommands        ( ostream& out                     );
00124   bool          executeStringCommand      ( char *str                        );
00125 
00126     // simple teams (PlayerTeams.cpp)
00127     SoccerCommand kickToPass                      (double* dFitness = NULL           );
00128     SoccerCommand kickToPlay              (                                                                      );
00129     SoccerCommand kickToDrible                    (                                  );
00130     SoccerCommand kickToScore                     (                                  );
00131     SoccerCommand deMeer5                 (                                  );
00132     SoccerCommand deMeer5_goalie          (                                  );
00133   
00134         // returns an array of roles for each agent including mine at position 1
00135         RoleCG * getPlayerRoles();
00136         
00137         // returns my role in the field
00138         RoleCG getMyRole();
00139         
00140         // return an index where player role is stored in RoleCG *;
00141         int getPlayerIndexRole(ObjectT o);
00142          
00143         ObjectT getPlayerTypeRole(int index);
00144         
00145         // interceptor
00146         double valueRuleInterc1(PlayerActionCG agentAction);
00147     double passTo                         (AngRad angle,
00148                                            ObjectT oPlayer, 
00149                                            VecPosition *pos = NULL, 
00150                                            double dConfThr = 0.9);
00151   
00152         // passer
00153         double valueRulePasser1(RoleCG * playerRoles, int teammateIndex, PlayerActionCG agentAction, PlayerActionCG teammateAction,
00154                                                         DirCG passDirection);
00155         
00156         double valueRulePasser2(PlayerActionCG agentAction, DirCG emptySpaceDirection);
00157         
00158         double valueRulePasser3(PlayerActionCG agentAction);
00159 
00160         double valueRulePasser4(PlayerActionCG agentAction);
00161         
00162         // receiver
00163         double valueRuleReceiver1(RoleCG * playerRoles, int teammateIndex, PlayerActionCG agentAction, PlayerActionCG teammateAction,
00164                                                           DirCG passDirection);
00165         
00166         double valueRuleReceiver2(RoleCG * playerRoles, int teammateIndex1, int teammateIndex2, PlayerActionCG agentAction,
00167                                                       PlayerActionCG teammateAction1,
00168                                                           DirCG passDirection1,
00169                                                           PlayerActionCG teammateAction2,
00170                                                           DirCG passDirection2);
00171                                                           
00172         double valueRuleReceiver3(PlayerActionCG agentAction);
00173         
00174         // passive
00175         double valueRulePassive1(PlayerActionCG agentAction);   
00176         
00177         
00178         // algoritmus eliminacie premennych
00179         // vystup: akcie pre jednotlivych agentov, moja akcia bude s indexom 11
00180         PlayerActionCG * variableEliminationAlgorithmCG();
00181         
00182         
00183         PlayerActionCG * Player::variableEliminationAlgorithmCG(RoleCG * playerRoles);
00184         
00185         
00186         
00187         bool isPassBlockedCG(int playerIndex, int teammateIndex, DirCG passDirection);
00188         
00189         bool isEmptySpace(int playerIndex, DirCG direction);
00190         
00191         double uCG(int teammateIndex, DirCG passDirection);
00192 
00193 
00194         double transformGlobalDirectionToAngleCG(DirCG globalDirection);
00195         
00196         // pomocne funkcie
00197         double getMax(double val1, double val2);        
00198         
00199         bool isInFrontOfGoalCG(VecPosition pos);
00200         
00201         PlayerActionCG * getOptimalCommonAction();
00202   
00203 private:
00204     double passToFitness                  (double from1X, 
00205                                            double from1Y, 
00206                                            double to1X, 
00207                                            double to1Y, 
00208                                            double pX, 
00209                                            double pY, 
00210                                            double toX, 
00211                                            double toY,
00212                                            double r);
00213     double passToTeammateFitness          (double from1X, 
00214                                            double from1Y, 
00215                                            double to1X, 
00216                                            double to1Y, 
00217                                            double pX, 
00218                                            double pY, 
00219                                            double toX, 
00220                                            double toY,
00221                                            double r = -1);
00222     double passToOpponentFitness          (double from1X, 
00223                                            double from1Y, 
00224                                            double to1X, 
00225                                            double to1Y, 
00226                                            double pX, 
00227                                            double pY, 
00228                                            double toX, 
00229                                            double toY,
00230                                            double r = -1);
00231     bool isPassBlocked(ObjectT oPlayer, AngRad ang);
00232     double leadingPass(ObjectT oPlayer, AngRad ang);
00233     SoccerCommand circleKickToPass (double* dFitness = NULL);
00234 };
00235 
00236 #endif

Generated on Thu Apr 26 22:45:27 2007 for GangOfSix(GOS)-RoboCupTeamProject by  doxygen 1.5.1-p1