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

# Representations/Cognition/LandmarksState.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file LandmarksState.cpp
    00003 *
    00004 * Implementation of class LandmarksState.
    00005 *
    00006 * @author <A href=mailto:marc.dassler@web.de>Marc Dassler</A>
    00007 */
    00008
    00009
    00010
    00011 #include "LandmarksState.h"
    00012
    00013 const double LandmarksState::BEACON = 1;
    00014 const double LandmarksState::GOAL = 1;
    00015 const double LandmarksState::LINE = 0.5;
    00016 const double LandmarksState::EDGE = 0.75;
    00017
    00018 LandmarksState::LandmarksState()
    00019 {
    00020   initLandmarks();
    00021   lastSeenBeacon = 0;
    00022   reset();
    00023 }
    00024
    00025 void LandmarksState::initLandmarks()
    00026 {
    00027
    00028   // BEACON
    00029   // decide which color is on opponent side
    00030   if (getPlayer().getTeamColor() == Player::red)
    00031   {
    00032     landmarks[0] =  LandmarkState(Vector3<double>(xPosFrontFlags, yPosLeftFlags,  flagHeight+ flagColorHeight),Flag::pinkAboveSkyblue,BEACON);
    00033     landmarks[1] =  LandmarkState(Vector3<double>(xPosFrontFlags, yPosRightFlags,  flagHeight+ flagColorHeight),Flag::skyblueAbovePink,BEACON);
    00034     landmarks[2] =  LandmarkState(Vector3<double>(xPosBackFlags, yPosLeftFlags,  flagHeight+ flagColorHeight),Flag::yellowAbovePink,BEACON);
    00035     landmarks[3] =  LandmarkState(Vector3<double>(xPosBackFlags, yPosRightFlags,  flagHeight+ flagColorHeight),Flag::pinkAboveYellow,BEACON);
    00036   }
    00037   else
    00038   {
    00039     landmarks[0] =  LandmarkState(Vector3<double>(xPosFrontFlags, yPosLeftFlags,  flagHeight+ flagColorHeight),Flag::pinkAboveYellow,BEACON);
    00040     landmarks[1] =  LandmarkState(Vector3<double>(xPosFrontFlags, yPosRightFlags,  flagHeight+ flagColorHeight),Flag::yellowAbovePink,BEACON);
    00041     landmarks[2] =  LandmarkState(Vector3<double>(xPosBackFlags, yPosLeftFlags,  flagHeight+ flagColorHeight),Flag::pinkAboveSkyblue,BEACON);
    00042     landmarks[3] =  LandmarkState(Vector3<double>(xPosBackFlags, yPosRightFlags,  flagHeight+ flagColorHeight),Flag::skyblueAbovePink,BEACON);
    00043   }
    00044
    00045   // OWN PENALTY AREA
    00046   landmarks[4] =  LandmarkState(Vector3<double>(xPosOwnPenaltyArea, yPosLeftPenaltyArea, 0.0),-1, EDGE);
    00047   landmarks[5] =  LandmarkState(Vector3<double>(xPosOwnPenaltyArea, yPosRightPenaltyArea, 0.0),-1, EDGE);
    00048
    00049   // OPPONENT PENALTY AREA
    00050   landmarks[6] =  LandmarkState(Vector3<double>(xPosOpponentPenaltyArea, yPosLeftPenaltyArea, 0.0),-1, EDGE);
    00051   landmarks[7] =  LandmarkState(Vector3<double>(xPosOpponentPenaltyArea, yPosRightPenaltyArea, 0.0),-1, EDGE);
    00052
    00053   // CENTER LINE AND EDGES
    00054   landmarks[8] =  LandmarkState(Vector3<double>(xPosHalfWayLine, 0.0, 0.0),-1, LINE);
    00055   landmarks[9] =  LandmarkState(Vector3<double>(xPosOpponentPenaltyArea, yPosLeftGroundline, 0.0),-1, EDGE);
    00056   landmarks[10]=  LandmarkState(Vector3<double>(xPosOpponentPenaltyArea, yPosRightGroundline, 0.0),-1, EDGE);
    00057
    00058   // GOALS
    00059   landmarks[11]=  LandmarkState(Vector3<double>(xPosOpponentGoal, 0.0, 0.0),-1, GOAL);
    00060   landmarks[12]=  LandmarkState(Vector3<double>(xPosOpponentGoal, 0.0, 0.0),-1, GOAL);
    00061
    00062 }
    00063
    00064 void LandmarksState::reset()
    00065 {
    00066   for (int i=0; i<numOfLandmarks; i++)
    00067   {
    00068     landmarks[i].visible = false;
    00069     landmarks[i].timeWhenLastSeen = 0;
    00070   }
    00071
    00072 }
    00073
    00074 bool LandmarksState::seenAnyBeacon() const
    00075 {
    00076   bool ret=false;
    00077   for (int i=0; i<Flag::numberOfFlagTypes; i++)
    00078     ret = ret | landmarks[i].visible;
    00079   return ret;
    00080 }
    00081
    00082 bool LandmarksState::seenAnyFlag() const
    00083 {
    00084   return seenAnyBeacon() | landmarks[11].visible | landmarks[12].visible;
    00085 }
    00086
    00087 int LandmarksState::lastSeenBeaconIndex() const
    00088 {
    00089   long theMax = 0;
    00090   int ret=0;
    00091   for (int i=0;i<Flag::numberOfFlagTypes;i++)
    00092   {
    00093     if (landmarks[i].timeWhenLastSeen>theMax)
    00094     {
    00095       theMax = landmarks[i].timeWhenLastSeen;
    00096       ret = i;
    00097     }
    00098   }
    00099   return ret;
    00100
    00101 }
    00102 long LandmarksState::timeOfLastSeenBeacon(int beaconIndex) const
    00103 {
    00104   return landmarks[beaconIndex].timeWhenLastSeen;
    00105 }
    00106
    00107 long LandmarksState::timeBetweenSeen2LastBeacons(int beaconIndex) const
    00108 {
    00109   //calculate the time difference between the last seen and the others
    00110   long minTime = 1000000;
    00111   for (int i=0;i<Flag::numberOfFlagTypes;i++)
    00112     if (beaconIndex!=i)
    00113       minTime = min(landmarks[beaconIndex].timeWhenLastSeen-landmarks[i].timeWhenLastSeen,minTime);
    00114   return minTime;
    00115
    00116 }
    00117 void LandmarksState::update(const LandmarksPercept& landmarksPercept)
    00118 {
    00119   int i;
    00120   for (i=0; i<Flag::numberOfFlagTypes; i++) landmarks[i].visible = false;
    00121
    00122   for (i=0; i<landmarksPercept.numberOfFlags; i++)
    00123     setLandmarkVisibleByBeaconType(landmarksPercept.flags[i].type);
    00124 }
    00125
    00126 void LandmarksState::setLandmarkVisibleByBeaconType(int type)
    00127 {
    00128   for (int i=0;i<Flag::numberOfFlagTypes;i++)
    00129     if (landmarks[i].beaconColor == type)
    00130     {
    00131       landmarks[i].visible = true;
    00132       landmarks[i].timeWhenLastSeen = SystemCall::getCurrentSystemTime();
    00133       break;
    00134     }
    00135 }
    00136
    00137 In& operator>>(In& stream,LandmarksState& landmarksState)
    00138 {
    00139   for(int i=0; i<landmarksState.numOfLandmarks; i++)
    00140     stream >> landmarksState.landmarks[i];
    00141   return stream;
    00142 }
    00143
    00144 Out& operator<<(Out& stream, const LandmarksState& landmarksState)
    00145 {
    00146   for(int i=0; i<landmarksState.numOfLandmarks; i++)
    00147     stream << landmarksState.landmarks[i];
    00148   return stream;
    00149 }
    00150