src/PlayerTeamsTest.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 #include "ArsToolbox.h"
00050 #include <stdio.h>
00051 
00052 //DRIBLOVANIE
00053 #include <fstream>
00054 using namespace std;
00055 //koniec DRIBLOVANIE
00056 
00057 //#define PRIHRAVKY_FUZZY
00058 
00059 SoccerCommand Player::kickToScore(  ){
00060     SoccerCommand soc(CMD_ILLEGAL);
00062         // FUZZY REGULACIA      START                                                                                           //
00064 
00065         double goalWidth = SS->getGoalWidth();
00066         double a = goalWidth * 0.5;
00067         int samples = 100;
00068 
00069         const int IN_Y_GOALIE = 0;                      // input  fuzzygroup (lingvisticka premenna)
00070         const int IN_ME_TO_GOALIE = 1;          // input  fuzzygroup (lingvisticka premenna)
00071         const int OUT_Y_DIRECTION = 0;          // output fuzzygroup (lingvisticka premenna)
00072 
00073         const int BRANKAR_VLAVO = 0;            // charakteristicka funkcia pre IN_Y_GOALIE
00074         const int BRANKAR_TROCHU_VLAVO = 1; // charakteristicka funkcia pre IN_Y_GOALIE
00075         const int BRANKAR_TROCHU_VPRAVO = 2;// charakteristicka funkcia pre IN_Y_GOALIE
00076         const int BRANKAR_VPRAVO = 3;           // charakteristicka funkcia pre IN_Y_GOALIE
00077 
00078         const int NALAVO_OD_BRANKARA  = 0;      // charakteristicka funkcia pre IN_ME_TO_GOALIE
00079         const int BRANKAR_PREDOMNOU   = 1;      // charakteristicka funkcia pre IN_ME_TO_GOALIE
00080         const int NAPRAVO_OD_BRANKARA = 2;      // charakteristicka funkcia pre IN_ME_TO_GOALIE
00081 
00082         const int KOPNI_EX_VLAVO = 0;           // charakteristicka funkcia pre OUT_Y_DIRECTION
00083         const int KOPNI_VLAVO = 1;                      // charakteristicka funkcia pre OUT_Y_DIRECTION
00084         const int KOPNI_VPRAVO = 2;                     // charakteristicka funkcia pre OUT_Y_DIRECTION
00085         const int KOPNI_EX_VPRAVO = 3;          // charakteristicka funckia pre OUT_Y_DIRECTION
00086 
00087         cFuzzyObj * fz = new cFuzzyObj();
00088         fz->SetSamples(samples);
00089 
00090         fz->AddInput(-a, a);    // vytvorenie IN_Y_GOALIE
00091         fz->AddInput(-a, a);    // vytovrenie IN_ME_TO_GOALIE
00092         fz->AddOutput(-a, a);   // vytvorenie OUT_Y_DIRECTION
00093 
00094         fz->AddInputMF(IN_Y_GOALIE, FZ_LEFT,      -0.75*a,  -0.4*a);                                    // BRANKAR_VLAVO
00095         fz->AddInputMF(IN_Y_GOALIE, FZ_TRAPEZOID,  -0.6*a,  -0.3*a, -0.1*a, 0.1*a);     // BRANKAR_TROCHU_VLAVO
00096         fz->AddInputMF(IN_Y_GOALIE, FZ_TRAPEZOID,  -0.1*a,   0.1*a,  0.3*a, 0.6*a);             // BRANKAR_TROCHU_VPRAVO
00097         fz->AddInputMF(IN_Y_GOALIE, FZ_RIGHT,       0.4*a,   0.75*a);                                   // BRANKAR_VPRAVO
00098 
00099         fz->AddInputMF(IN_ME_TO_GOALIE, FZ_LEFT,          -0.9*a, -0.2*a);                                      // NALAVO_OD_BRANKARA
00100         fz->AddInputMF(IN_ME_TO_GOALIE, FZ_TRAPEZOID, -0.3*a, -0.2*a, 0.2*a, 0.3*a);    // BRANKAR_PREDOMNOU
00101         fz->AddInputMF(IN_ME_TO_GOALIE, FZ_RIGHT,      0.2*a,  0.9*a);                                  // NAPRAVO_OD_BRANKARA
00102 
00103 
00104         fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRIANGLE,      -a, -0.9*a, -0.8*a);                 // KOPNI_EX_VLAVO
00105         fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRAPEZOID, -0.9*a, -0.8*a, -0.6*a, -0.4*a); // KOPNI_VLAVO
00106         fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRAPEZOID,  0.4*a,  0.6*a,  0.8*a,  0.9*a); // KOPNI_VPRAVO
00107         fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRIANGLE,   0.8*a,  0.9*a, a);                              // KOPNI_EX_VPRAVO
00108 
00109         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, NALAVO_OD_BRANKARA , KOPNI_EX_VLAVO);
00110         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, BRANKAR_PREDOMNOU  , KOPNI_VPRAVO);
00111         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, NAPRAVO_OD_BRANKARA, KOPNI_VPRAVO);
00112 
00113         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, NALAVO_OD_BRANKARA  , KOPNI_EX_VLAVO);
00114         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, BRANKAR_PREDOMNOU   , KOPNI_EX_VPRAVO);
00115         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, NAPRAVO_OD_BRANKARA , KOPNI_VPRAVO);
00116 
00117         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, NALAVO_OD_BRANKARA  , KOPNI_VLAVO);
00118         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, BRANKAR_PREDOMNOU   , KOPNI_EX_VLAVO);
00119         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, NAPRAVO_OD_BRANKARA , KOPNI_EX_VPRAVO);
00120 
00121         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, NALAVO_OD_BRANKARA  , KOPNI_VLAVO);
00122         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, BRANKAR_PREDOMNOU   , KOPNI_VLAVO);
00123         fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, NAPRAVO_OD_BRANKARA , KOPNI_EX_VPRAVO);
00124 
00125 
00126         VecPosition gp = WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
00127         double opp_goalie_position = gp.getY();
00128         if(opp_goalie_position < -a) {
00129                 opp_goalie_position = -a;
00130         }
00131         if(opp_goalie_position > a) {
00132                 opp_goalie_position = a;
00133         }
00134 
00135         VecPosition myPos = WM->getAgentGlobalPosition();
00136         VecPosition diff  = myPos - gp;
00137         double my_rel_pos     = diff.getY();
00138 
00139         if(my_rel_pos<0) {
00140                 if(my_rel_pos < -a) {
00141                         my_rel_pos = -a;
00142                 }
00143         }
00144         else {
00145         if(my_rel_pos > a) {
00146                 my_rel_pos = a;
00147         }
00148         }
00149 
00150         double y_direction = fz->CountResult(OUT_Y_DIRECTION, DFZ_CENTROID, OPS_ZADEH, opp_goalie_position, my_rel_pos);
00151         delete fz;
00152 
00154         // FUZZY REGULACIA      END                                                                                                     //
00156 
00157         VecPosition posGoal( PITCH_LENGTH/2.0, y_direction );
00158         soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
00159 
00160         ACT->putCommandInQueue( soc );
00161         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00162         Log.log( 100, "kick ball" );
00163         return soc;
00164 }
00165 
00166 SoccerCommand Player::kickToDrible(  ){
00167     SoccerCommand soc(CMD_ILLEGAL);
00168         printf("Kicking to drible\n");
00169         // TODO: find better position to kick ball to, now random
00170         VecPosition posGoal( PITCH_LENGTH/2.0,
00171           (-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
00172         soc = kickTo( posGoal, SS->getBallSpeedMax() / 30 ); // kick maximal
00173 
00174         ACT->putCommandInQueue( soc );
00175         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00176         Log.log( 100, "kick ball" );
00177 }
00178 
00179 void Player::findPosition(double dConfThr){
00180         
00181   struct circle {
00182         double x,y,r;
00183         bool tm;
00184   };
00185   circle circles[22];
00186   int circlesC = 0;
00187 
00188   circle lines[20];
00189   
00190   VecPosition vec1 = WM->getAgentGlobalPosition();
00191   double dDist;
00192   VecPosition posObj;
00193   int iIndex;
00194   
00195   for( ObjectT o = WM->iterateObjectStart( iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE, dConfThr );
00196        o != OBJECT_ILLEGAL;
00197        o = WM->iterateObjectNext ( iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE, dConfThr ) )
00198   {
00199     posObj    = WM->getGlobalPosition( o );
00200     dDist     = posObj.getDistanceTo( vec1 );
00201     
00202     circles[circlesC].x = posObj.getX();
00203     circles[circlesC].y = posObj.getY();    
00204     circles[circlesC].r = dDist / 5;
00205     circles[circlesC].tm = true;
00206     log->addObject(LOG_PLAYER_TEAM, posObj.getX(),posObj.getY());
00207     circlesC++;      
00208   }
00209   WM->iterateObjectDone( iIndex );
00210   
00211   for( ObjectT o = WM->iterateObjectStart( iIndex, OBJECT_SET_OPPONENTS, dConfThr );
00212        o != OBJECT_ILLEGAL;
00213        o = WM->iterateObjectNext ( iIndex, OBJECT_SET_OPPONENTS, dConfThr ) )
00214   {
00215     posObj    = WM->getGlobalPosition( o );
00216     dDist     = posObj.getDistanceTo( vec1 );
00217     
00218     circles[circlesC].x = posObj.getX();
00219     circles[circlesC].y = posObj.getY();    
00220     circles[circlesC].r = dDist / 5;
00221     circles[circlesC].tm = false;        
00222     log->addObject(LOG_PLAYER_OTHER, posObj.getX(),posObj.getY());
00223     circlesC++;      
00224   }
00225   
00226   // pre kazdy luc prejdeme kruznice
00227   double p1x, p1y, p2x, p2y;
00228   for (int i = 0; i < 20; i++) {
00229         lines[i].r = 10000;
00230         for (int j = 0; j < circlesC; j++) {
00231 /*      if (circleLineIntersection(
00232             vec1.getX(), 
00233             vec1.getY(), 
00234             ?, 
00235             ?, 
00236             circle[j].getX(), 
00237             circle[j].getY(), 
00238             &p1x, 
00239             &p1y, 
00240             &p2x, 
00241             &p2y
00242       ) != 0) {
00243           
00244       }*/ 
00245         }
00246   }
00247   
00248   WM->iterateObjectDone( iIndex );
00249 
00250   log->addObject(LOG_PLAYER_ACTIVE, vec1.getX(), vec1.getY());    
00251   log->addObject(LOG_BALL, 0, 0);
00252 }
00253 
00254 SoccerCommand Player::kickToPass(  ){
00255     SoccerCommand soc(CMD_ILLEGAL);
00256         double dis;
00257         ObjectT obj;
00258 
00259     log->situationBegin("Prihravka", WM->getCurrentCycle());
00260   
00261         // skusime najst lepsie miesto na strielanie
00262         findPosition(0.97);     
00263         
00264         // skusime najst hraca, ktory je najblizsie ku brane
00265         obj = WM->getClosestInSetTo( OBJECT_SET_TEAMMATES_NO_GOALIE, goalMiddle,  &dis, 0.97, 1.0);
00266 
00267         // ak taky nie je, tak nahrame najblizsiemu
00268         if (obj == OBJECT_ILLEGAL)
00269                 obj = WM->getClosestRelativeInSet(OBJECT_SET_TEAMMATES_NO_GOALIE, &dis, 1.0);
00270                 
00271         // ak napriek tomu nemame ziadneho hraca, tak kopeme na branku          
00272         if (obj == OBJECT_ILLEGAL){
00273                 kickToScore();
00274         } else {
00275                 // kolko trva lopte kym dojde ku hracovi?
00276                 int cycles = WM->predictNrCyclesForDistance(OBJECT_BALL, dis, SS->getBallSpeedMax());           
00277                 VecPosition vec1 = WM->getGlobalPosition(obj); 
00278                 
00279                 // ideme hracovi kopnut do behu s tym, ze uvazujeme ze ma 50% dash, getDashPowerRate sa nepouziva...
00280                 VecPosition vec2 = WM->predictPosAfterNrCycles(obj, cycles, 50, NULL, NULL);             
00281                 VecPosition delta = vec2 - vec1;
00282                 
00283                 // urobime priemer, pretoze hraci nestihaju reagovat
00284                 VecPosition vec3 = VecPosition(
00285             (vec2.getX() + cycles*vec1.getX()) / (cycles + 1), 
00286             (vec2.getY() + cycles*vec1.getY()) / (cycles + 1)
00287         );  
00288         
00289         double speed;            
00290 
00291 #ifdef PRIHRAVKY_FUZZY
00293                 // FUZZY zistenie sily a koeficientu "do behu" - START
00295                 int samples = 100;
00296                 const double P3 = PITCH_LENGTH/3.0;
00297                 const double a = 12;
00298                 const double b = 1;
00299                 
00300                 const int IN_PLAYER_SPEED    = 0;       // input fuzzygroup, rychlost hraca
00301                 const int IN_PLAYER_DISTANCE = 1;       // input fuzzygroup, vzdialenost hraca
00302                 const int OUT_BALL_SPEED         = 0;   // output fuzzygroup, rychlost kopu do lopty
00303                 const int OUT_BALL_DIRECTION = 1;       // output fuzzygroup, velkost prekopavanej nahravky
00304                 
00305                 const int PLAYER_SLOW   = 0;            // charakteristicka funkcia pre IN_PLAYER_SPEED
00306                 const int PLAYER_FAST           = 1;    // charakteristicka funkcia pre IN_PLAYER_SPEED
00307                 const int PLAYER_VERY_FAST = 2;         // charakteristicka funkcia pre IN_PLAYER_SPEED
00308                 
00309                 const int PLAYER_NEAR           = 0;    // charakteristicka funkcia pre IN_PLAYER_DISTANCE
00310                 const int PLAYER_MIDDLE = 1;            // charakteristicka funkcia pre IN_PLAYER_DISTANCE
00311                 const int PLAYER_FAR            = 2;    // charakteristicka funkcia pre IN_PLAYER_DISTNACE
00312                 
00313                 const int POWER_SMALL   = 0;            // charakteristicka funkcia pre OUT_BALL_SPEED
00314                 const int POWER_MEAN    = 1;            // charakteristicka funkcia pre OUT_BALL_SPEED
00315                 const int POWER_BIG             = 2;            // charakteristicka funkcia pre OUT_BALL_SPEED
00316                 const int POWER_MAX             = 3;            // charakteristicka funkcia pre OUT_BALL_SPEED
00317                 
00318                 const int BALL_NEAR             = 0;            // charakteristicka funkcia pre OUT_BALL_DIRECTION
00319                 const int BALL_MIDDLE   = 1;            // charakteristicka funkcia pre OUT_BALL_DIRECTION
00320                 const int BALL_FAR              = 2;            // charakteristicka funkcia pre OUT_BALL_DIRECTION
00321                 
00322                 cFuzzyObj * silaFuzzy = new cFuzzyObj();
00323                 silaFuzzy->SetSamples(samples);
00324                 
00325                 silaFuzzy->AddInput(0, a);                      // interval pre IN_PLAYER_SPEED
00326                 silaFuzzy->AddInput(0, P3);                     // interval pre IN_PLAYER_DISTANCE
00327                 silaFuzzy->AddOutput(0, b);                     // interval pre OUT_BALL_SPEED
00328                 silaFuzzy->AddOutput(0, b);                     // interval pre OUT_BALL_DIRECTION
00329                 
00330                 
00331                 silaFuzzy->AddInputMF(IN_PLAYER_SPEED, FZ_LEFT, 0, 0.33*a);                                                     // PLAYER_SLOWLY
00332                 silaFuzzy->AddInputMF(IN_PLAYER_SPEED, FZ_TRAPEZOID, 0.177*a, 0.33*a, 0.66*a, 0.833*a); // PLAYER_FAST
00333                 silaFuzzy->AddInputMF(IN_PLAYER_SPEED, FZ_RIGHT, 0.66*a, a);                                            // PLAYER_VERY_FAST
00334                 
00335                 
00336                 silaFuzzy->AddInputMF(IN_PLAYER_DISTANCE, FZ_LEFT, 0.125*P3,  0.5*P3);                                                  // PLAYER_NEAR
00337                 silaFuzzy->AddInputMF(IN_PLAYER_DISTANCE, FZ_TRAPEZOID, 0.125*P3, 0.375*P3, 0.625*P3, 0.875*P3);// PLAYER_MIDDLE
00338                 silaFuzzy->AddInputMF(IN_PLAYER_DISTANCE, FZ_RIGHT, 0.5*P3, 0.875*P3);                                                  // PLAYER_FAR
00339                 
00340                 silaFuzzy->AddOutputMF(OUT_BALL_SPEED, FZ_LEFT, 0.125*b, 0.375*b);                                              // POWER_SMALL
00341                 silaFuzzy->AddOutputMF(OUT_BALL_SPEED, FZ_TRAPEZOID, 0.125*b, 0.375*b, 0.5*b, 0.625*b); // POWER_MEAN
00342                 silaFuzzy->AddOutputMF(OUT_BALL_SPEED, FZ_TRAPEZOID, 0.375*b, 0.5*b, 0.625*b, 0.875*b); // POWER_BIG
00343                 silaFuzzy->AddOutputMF(OUT_BALL_SPEED, FZ_RIGHT, 0.625*b, 0.875*b);                                             // POWER_MAX
00344                 
00345                 silaFuzzy->AddOutputMF(OUT_BALL_DIRECTION, FZ_LEFT, 0.125*b, 0.375*b);                                           // BALL_NEAR
00346                 silaFuzzy->AddOutputMF(OUT_BALL_DIRECTION, FZ_TRAPEZOID, 0.125*b, 0.375*b, 0.625*b, 0.875*b);// BALL_MIDLLE
00347                 silaFuzzy->AddOutputMF(OUT_BALL_DIRECTION, FZ_RIGHT, 0.625*b, 0.875*b);                                          // BALL_FAR
00348                 
00349                 // Prva tabulka
00350                 
00351                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_SLOW, PLAYER_NEAR, POWER_SMALL );
00352                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_SLOW, PLAYER_MIDDLE, POWER_MEAN);
00353                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_SLOW, PLAYER_FAR, POWER_BIG);
00354                 
00355                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_FAST, PLAYER_NEAR, POWER_MEAN);
00356                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_FAST, PLAYER_MIDDLE, POWER_MEAN);
00357                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_FAST, PLAYER_FAR, POWER_BIG);
00358                 
00359                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_VERY_FAST, PLAYER_NEAR, POWER_BIG); 
00360                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_VERY_FAST, PLAYER_MIDDLE, POWER_BIG);
00361                 silaFuzzy->AddRule(OUT_BALL_SPEED, PLAYER_VERY_FAST, PLAYER_FAR, POWER_MAX);
00362                 
00363                 // Druha tabulka
00364                 
00365                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_SLOW, PLAYER_NEAR, BALL_NEAR );
00366                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_SLOW, PLAYER_MIDDLE, BALL_MIDDLE);
00367                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_SLOW,     PLAYER_FAR, BALL_FAR);
00368                 
00369                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_FAST, PLAYER_NEAR, BALL_MIDDLE);
00370                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_FAST, PLAYER_MIDDLE, BALL_MIDDLE);
00371                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_FAST, PLAYER_FAR, BALL_FAR);
00372                 
00373                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_VERY_FAST, PLAYER_NEAR, BALL_FAR); 
00374                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_VERY_FAST, PLAYER_MIDDLE, BALL_FAR);
00375                 silaFuzzy->AddRule(OUT_BALL_DIRECTION, PLAYER_VERY_FAST, PLAYER_FAR, BALL_FAR);
00376                 
00377                 // rychlost hraca
00378                 double player_speed = vec2.getMagnitude();
00379                 // ak je jeho "rychlost" vacsia, ako nas rozzsah, tak ju skreseme
00380                 if(player_speed > a) {
00381                         player_speed = a;
00382                 }
00383                 
00384                 // ak je ich vzdialenost vecsia, ako nas rozsah, tak ju skreseme
00385                 double dist = dis;
00386                 if(dis > P3) {
00387                         dist = P3;
00388                 }
00389                 
00390                 double speed_coeficient = silaFuzzy->CountResult(OUT_BALL_SPEED, DFZ_CENTROID, OPS_ZADEH, player_speed, dist);
00391                 double run_coefficient   = silaFuzzy->CountResult(OUT_BALL_DIRECTION, DFZ_CENTROID, OPS_ZADEH, player_speed, dist);
00392                 
00393                 delete silaFuzzy;
00394                 
00396                 // FUZZY zistenie sily a koeficientu "do behu" - END
00398                 
00399                 speed = SS->getBallSpeedMax()*speed_coeficient;
00400                 VecPosition vec4 = vec2 + (delta * run_coefficient);
00401         log->addObject(LOG_BALL, vec4.getX(),vec4.getY());
00402                 soc = kickTo( vec4, speed );
00403                 
00404 #else
00405                 
00406                 // zistime silu a kopneme
00407                 speed = SS->getBallSpeedMax() * ((dis + delta.getMagnitude()) / (PITCH_LENGTH / (double)3));
00408                 soc = kickTo( vec3, speed );
00409         log->addObject(LOG_BALL, vec3.getX(),vec3.getY());
00410         
00411 #endif
00412         
00413                 ACT->putCommandInQueue( soc );
00414                 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00415         }
00416     log->situationEnd();
00417     return soc;
00418 }
00429 SoccerCommand Player::deMeer5(  )
00430 {
00431 
00432   SoccerCommand soc(CMD_ILLEGAL);
00433   VecPosition   posAgent = WM->getAgentGlobalPosition();
00434   VecPosition   posBall  = WM->getBallPos();
00435   int           iTmp;
00436   
00437   if( WM->getCurrentCycle() == 1 )
00438         cycle = -20;
00439 
00440   if( WM->isBeforeKickOff( ) )
00441   {
00442     if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 9 ) // 9 takes kick
00443     {
00444       if( WM->isBallKickable() )
00445       {
00446         
00447         
00448         VecPosition posGoal( PITCH_LENGTH/2.0,
00449                              (-1 + 2*(WM->getCurrentCycle()%2)) * 
00450                              0.4 * SS->getGoalWidth() );
00451                             
00452         soc = kickTo( posGoal, SS->getBallSpeedMax() ); // kick maximal
00453         Log.log( 100, "take kick off" );        
00454       }
00455       else
00456       {
00457         soc = intercept( false );  
00458         Log.log( 100, "move to ball to take kick-off" );
00459       }  
00460       ACT->putCommandInQueue( soc );
00461       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00462       return soc;
00463     }  
00464     if( formations->getFormation() != FT_INITIAL || // not in kickoff formation
00465         posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
00466     {
00467       formations->setFormation( FT_INITIAL );       // go to kick_off formation
00468       ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() ));
00469     }
00470     else                                            // else turn to center
00471     {
00472       ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) );
00473       ACT->putCommandInQueue( alignNeckWithBody( ) );
00474     }
00475   }
00476   else
00477   {
00478     formations->setFormation( FT_433_OFFENSIVE );
00479     soc.commandType = CMD_ILLEGAL;
00480 
00481     if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00482     {
00483       ACT->putCommandInQueue( soc = searchBall() );   // if ball pos unknown
00484       ACT->putCommandInQueue( alignNeckWithBody( ) ); // search for it
00485     }
00486     else if( WM->isBallKickable())                    // if kickable
00487     {
00488         // DRIBLOVANIE
00489         
00490         double angle;
00491         
00492         soc = dribble( 0.0 , DRIBBLE_SLOW);
00493         
00494         //SITUATIONSLOG
00495         
00496         log->situationBegin("Driblovanie", WM->getCurrentCycle());
00497 
00498         if( fabs( WM->getCurrentCycle() - cycle ) > 12 )
00499         {
00500         
00501 #ifdef DEBUG
00502         LOG_PRINTP(LOG_SOMI, "\nnew dribble: %d", cycle);
00503 #endif //DEBUG
00504 
00505         }
00506         else
00507         {
00508 
00509 #ifdef DEBUG
00510         LOG_PRINTP(LOG_SOMI, "\ndribble again: %d", cycle);
00511 #endif //DEBUG
00512 
00513         }
00514         cycle = WM->getCurrentCycle();
00515                
00516         VecPosition vec = WM->getAgentGlobalPosition();
00517         double dDist;
00518         VecPosition posObj;
00519         int iIndex;
00520   
00521         for( ObjectT o = WM->iterateObjectStart( iIndex, 
00522                          OBJECT_SET_TEAMMATES_NO_GOALIE );
00523              o != OBJECT_ILLEGAL;
00524              o = WM->iterateObjectNext ( iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE ) )
00525         {
00526           posObj    = WM->getGlobalPosition( o );
00527           dDist     = posObj.getDistanceTo( vec );
00528     
00529           if (dDist <= 20.0)
00530             log->addObject(LOG_PLAYER_TEAM, posObj.getX(),posObj.getY());
00531         } 
00532         
00533         for( ObjectT o = WM->iterateObjectStart( iIndex, OBJECT_SET_OPPONENTS );
00534              o != OBJECT_ILLEGAL;
00535              o = WM->iterateObjectNext ( iIndex, OBJECT_SET_OPPONENTS ) )
00536         {
00537           posObj    = WM->getGlobalPosition( o );
00538           dDist     = posObj.getDistanceTo( vec );
00539     
00540           if (dDist <= 20.0)
00541                 log->addObject(LOG_PLAYER_OTHER, posObj.getX(),posObj.getY());
00542         }
00543         
00544         log->addObject( LOG_PLAYER_ACTIVE, WM->getAgentGlobalPosition().getX(), 
00545                         WM->getAgentGlobalPosition().getY() );
00546         log->addObject( LOG_CIRCLE, WM->getBallPos().getX(), 
00547                         WM->getBallPos().getY(), 10.0 );
00548         log->addObject( LOG_BALL, WM->getBallPos().getX(), WM->getBallPos().getY() );
00549         
00550         log->situationEnd();
00551                 
00552         //koniec SITUATIONSLOG
00553         
00554         ACT->putCommandInQueue( soc );
00555         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );            
00556         
00557         // KONIEC DRIBLOVANIE
00558     }
00559     else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp )
00560               == WM->getAgentObjectType()  && !WM->isDeadBallThem() )
00561     {                                                // if fastest to ball
00562       Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp );
00563       soc = intercept( false );                      // intercept the ball
00564 
00565       if( soc.commandType == CMD_DASH &&             // if stamina low
00566           WM->getAgentStamina().getStamina() <
00567              SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
00568       {
00569         soc.dPower = 30.0 * WM->getAgentStamina().getRecovery(); // dash slow
00570         ACT->putCommandInQueue( soc );
00571         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00572       }
00573       else                                           // if stamina high
00574       {
00575         ACT->putCommandInQueue( soc );               // dash as intended
00576         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00577       }
00578      }
00579      else if( posAgent.getDistanceTo(WM->getStrategicPosition()) >
00580                   1.5 + fabs(posAgent.getX()-posBall.getX())/10.0)
00581                                                   // if not near strategic pos
00582      {
00583        if( WM->getAgentStamina().getStamina() >     // if stamina high
00584                             SS->getRecoverDecThr()*SS->getStaminaMax()+800 )
00585        {
00586          soc = moveToPos(WM->getStrategicPosition(),
00587                          PS->getPlayerWhenToTurnAngle());
00588          ACT->putCommandInQueue( soc );            // move to strategic pos
00589          ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00590        }
00591        else                                        // else watch ball
00592        {
00593          ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00594          ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00595        }
00596      }
00597      else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 ) // watch ball
00598      {
00599        ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00600        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00601      }
00602      else                                         // nothing to do
00603        ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) );
00604    }
00605   return soc;
00606 }
00607 
00614 SoccerCommand Player::deMeer5_goalie(  )
00615 {
00616   int i;
00617   SoccerCommand soc;
00618   VecPosition   posAgent = WM->getAgentGlobalPosition();
00619   AngDeg        angBody  = WM->getAgentGlobalBodyAngle();
00620 
00621   // define the top and bottom position of a rectangle in which keeper moves
00622   static const VecPosition posLeftTop( -PITCH_LENGTH/2.0 +
00623                0.7*PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/4.0 );
00624   static const VecPosition posRightTop( -PITCH_LENGTH/2.0 +
00625                0.7*PENALTY_AREA_LENGTH, +PENALTY_AREA_WIDTH/4.0 );
00626 
00627   // define the borders of this rectangle using the two points.
00628   static Line  lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop);
00629   static Line  lineLeft  = Line::makeLineFromTwoPoints(
00630                          VecPosition( -50.0, posLeftTop.getY()), posLeftTop );
00631   static Line  lineRight = Line::makeLineFromTwoPoints(
00632                          VecPosition( -50.0, posRightTop.getY()),posRightTop );
00633 
00634 
00635   if( WM->isBeforeKickOff( ) )
00636   {
00637     if( formations->getFormation() != FT_INITIAL || // not in kickoff formation
00638         posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )  
00639     {
00640       formations->setFormation( FT_INITIAL );       // go to kick_off formation
00641       ACT->putCommandInQueue( soc=teleportToPos(WM->getStrategicPosition()) );
00642     }
00643     else                                            // else turn to center
00644     {
00645       ACT->putCommandInQueue( soc = turnBodyToPoint( VecPosition( 0, 0 ), 0 ));
00646       ACT->putCommandInQueue( alignNeckWithBody( ) );
00647     }
00648     return soc;
00649   }
00650 
00651   if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00652   {                                                // confidence ball too  low
00653     ACT->putCommandInQueue( searchBall() );        // search ball
00654     ACT->putCommandInQueue( alignNeckWithBody( ) );
00655   }
00656   else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() ||
00657            WM->isCornerKickThem() )               
00658   {
00659     if( WM->isBallCatchable() )
00660     {
00661       ACT->putCommandInQueue( soc = catchBall() );
00662       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00663     }
00664      else if( WM->isBallKickable() )
00665     {
00666        soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
00667        ACT->putCommandInQueue( soc );
00668        ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00669     }
00670     else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) &&
00671              WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) == 
00672                                                WM->getAgentObjectType() )
00673     {
00674       ACT->putCommandInQueue( soc = intercept( true ) );
00675       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00676     }
00677     else
00678     {
00679       // make line between own goal and the ball
00680       VecPosition posMyGoal = ( WM->getSide() == SIDE_LEFT )
00681              ? SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_L, SIDE_LEFT )
00682              : SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_R, SIDE_RIGHT);
00683       Line lineBall = Line::makeLineFromTwoPoints( WM->getBallPos(),posMyGoal);
00684 
00685       // determine where your front line intersects with the line from ball
00686       VecPosition posIntersect = lineFront.getIntersection( lineBall );
00687 
00688       // outside rectangle, use line at side to get intersection
00689       if (posIntersect.isRightOf( posRightTop ) )
00690         posIntersect = lineRight.getIntersection( lineBall );
00691       else if (posIntersect.isLeftOf( posLeftTop )  )
00692         posIntersect = lineLeft.getIntersection( lineBall );
00693 
00694       if( posIntersect.getX() < -49.0 )
00695         posIntersect.setX( -49.0 );
00696         
00697       // and move to this position
00698       if( posIntersect.getDistanceTo( WM->getAgentGlobalPosition() ) > 0.5 )
00699       {
00700         soc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() );
00701         ACT->putCommandInQueue( soc );
00702         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00703       }
00704       else
00705       {
00706         ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00707         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00708       }
00709     }
00710   }
00711   else if( WM->isFreeKickUs() == true || WM->isGoalKickUs() == true )
00712   {
00713     if( WM->isBallKickable() )
00714     {
00715       if( WM->getTimeSinceLastCatch() == 25 && WM->isFreeKickUs() )
00716       {
00717         // move to position with lesser opponents.
00718         if( WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
00719                                           Circle(posRightTop, 15.0 )) <
00720             WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS, 
00721                                            Circle(posLeftTop,  15.0 )) )
00722           soc.makeCommand( CMD_MOVE,posRightTop.getX(),posRightTop.getY(),0.0);
00723         else
00724           soc.makeCommand( CMD_MOVE,posLeftTop.getX(), posLeftTop.getY(), 0.0);
00725         ACT->putCommandInQueue( soc );
00726       }
00727       else if( WM->getTimeSinceLastCatch() > 28 )
00728       {
00729         soc = kickTo( VecPosition(0,posAgent.getY()*2.0), 2.0 );    
00730         ACT->putCommandInQueue( soc );
00731       }
00732       else if( WM->getTimeSinceLastCatch() < 25 )
00733       {
00734         VecPosition posSide( 0.0, posAgent.getY() ); 
00735         if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 )
00736         {
00737           soc = turnBodyToPoint( posSide );
00738           ACT->putCommandInQueue( soc );
00739         }
00740         ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00741       }
00742     }
00743     else if( WM->isGoalKickUs()  )
00744     {
00745       ACT->putCommandInQueue( soc = intercept( true ) );
00746       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00747     }
00748     else
00749       ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00750   }
00751   else
00752   {
00753      ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00754      ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00755   }
00756   return soc;
00757 } 

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