Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Representations/Cognition/PassCorridorCollection.cpp

Go to the documentation of this file.

    00001 /**
    00002  * @file PassCorridorCollection.cpp
    00003  *
    00004  * Implementation of class PassCorridorCollection.
    00005  */
    00006
    00007 #include "PassCorridorCollection.h"
    00008 #include "Tools/Math/Common.h"
    00009 #include "Tools/FieldDimensions.h"
    00010
    00011 void PassCorridor::reset()
    00012 {
    00013   openingAngle = pi/3;
    00014   distance = 2 * xPosOpponentGroundline;
    00015   distanceToOppPlayer = distance;
    00016   rate = 0.0;
    00017
    00018 };
    00019
    00020 In& operator>>(In& stream,PassCorridor& passCorridor)
    00021 {
    00022   stream.read(&passCorridor,sizeof(PassCorridor));
    00023   return stream;
    00024 }
    00025
    00026 Out& operator<<(Out& stream, const PassCorridor& passCorridor)
    00027 {
    00028   stream.write(&passCorridor,sizeof(PassCorridor));
    00029   return stream;
    00030 }
    00031
    00032 PassCorridorCollection::PassCorridorCollection()
    00033 {
    00034   reset();
    00035   maxPassCorridorRate = 6.5;
    00036 }
    00037
    00038 void PassCorridorCollection::reset()
    00039 {
    00040   bestPassCorridorIndex = -1;
    00041   numberOfPassCorridors = 0;
    00042   for (int i=0;i<4;i++)
    00043     passCorridors[i].reset();
    00044 };
    00045
    00046 bool PassCorridorCollection::findBestPassCorridor()
    00047 {
    00048   double rate = -100.0;
    00049   int best = -1;
    00050   for (int i=0;i < numberOfPassCorridors;i++)
    00051   {
    00052     passCorridors[i].rate = passCorridors[i].rateDistanceToPartner
    00053                           + passCorridors[i].rateDistanceWin * 3
    00054                           + passCorridors[i].rateDistanceBorderLine * 0.5
    00055                           + passCorridors[i].rateWidthOfCorridor
    00056                           + passCorridors[i].rateAngleToPartner;
    00057     if (passCorridors[i].rate > rate)
    00058     {
    00059       best = i;
    00060       rate = passCorridors[i].rate;
    00061     }
    00062   }
    00063   if (best != -1)
    00064   {
    00065     bestPassCorridorIndex = best;
    00066     bestPassCorridor = &passCorridors[best];
    00067     return true;
    00068   }
    00069   else
    00070   {
    00071     bestPassCorridorIndex = -1;
    00072     bestPassCorridor = NULL;
    00073     return false;
    00074   }
    00075 }
    00076
    00077 const double PassCorridorCollection::getBestPassCorridorQuality() const
    00078 {
    00079   if (bestPassCorridorIndex != -1)
    00080     return passCorridors[bestPassCorridorIndex].rate / maxPassCorridorRate;
    00081   else
    00082     return 0.0;
    00083 }
    00084
    00085 In& operator>>(In& stream,PassCorridorCollection& passCorridorCollection)
    00086 {
    00087   stream >> passCorridorCollection.numberOfPassCorridors;
    00088   for (int i=0;i<passCorridorCollection.numberOfPassCorridors;i++)
    00089     stream.read(&passCorridorCollection.passCorridors[i],sizeof(PassCorridor));
    00090   return stream;
    00091 };
    00092
    00093 Out& operator<<(Out& stream, const PassCorridorCollection& passCorridorCollection)
    00094 {
    00095   stream << passCorridorCollection.numberOfPassCorridors;
    00096   for (int i=0;i<passCorridorCollection.numberOfPassCorridors;i++)
    00097     stream.write(&passCorridorCollection.passCorridors[i],sizeof(PassCorridor));
    00098   return stream;
    00099 };