00001 /** 00002 * @file PointsWithValidityAndAge.h 00003 * 00004 * Definition of PointsWithValidityAndAge 00005 * 00006 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Juengel</A> 00007 * @author <A href=mailto:kspiess@informatik.uni-bremen.de>Kai Spiess</A> 00008 */ 00009 00010 #ifndef _PointsWithValidityAndAge_h_ 00011 #define _PointsWithValidityAndAge_h_ 00012 00013 #include "Tools/FieldDimensions.h" 00014 00015 #include "Tools/Streams/InOut.h" 00016 00017 00018 /** The threshold for voting, minimum of votes */ 00019 static const int VOTE_THRESHOLD = 5; 00020 00021 00022 /** 00023 * Represents a set of points on the field. 00024 * It is used to determine the location of other players on the field. 00025 * If a new point is added and there are as many points in the set as it can held, 00026 * the oldest point is overwritten. 00027 */ 00028 class PointsWithValidityAndAge 00029 { 00030 public: 00031 00032 /** The maximum number of points in a set */ 00033 enum{MAX_NUMBER_OF_POINTS_WITH_AGE = 600}; 00034 /** The space between grid points*/ 00035 enum{GRID_SPACING = 50}; 00036 /** The number of grid points in x-direction */ 00037 enum{NUMBER_OF_GRID_POINTS_X = (xPosFrontFlags - xPosBackFlags) / GRID_SPACING}; 00038 /** The number of grid points in y-direction */ 00039 enum{NUMBER_OF_GRID_POINTS_Y = (yPosLeftFlags - yPosRightFlags) / GRID_SPACING}; 00040 00041 /** Default-Construktor */ 00042 // PointsWithValidityAndAge(); 00043 /** Constructor */ 00044 PointsWithValidityAndAge(short int sizeOfSet); 00045 /** Destructor */ 00046 ~PointsWithValidityAndAge(); 00047 00048 /** 00049 * Sets the maximum of points in the set 00050 * @param size The size of the set 00051 */ 00052 void setSizeOfSet(int size); 00053 00054 /** 00055 * Adds a point to the set, if necessary an old point is overwritten. 00056 * The distributions (in x and y direction) are also updated. 00057 * @param x The x coordinate of the point 00058 * @param y The y coordinate of the point 00059 */ 00060 void add(int x, int y); 00061 00062 /** 00063 * Returns the index of the next position in the set, where a point 00064 * can be added/set. 00065 * @return The index of the next position 00066 */ 00067 short int getIndexOfNextPoint(); 00068 00069 /** 00070 * Gets the position of an obstacle and stores the coordinates 00071 * in x_position and y_position. 00072 * The parameter index can range from 0 up to 3. 00073 * If no obstacle with that index exists, the return value 00074 * is false. 00075 * @param index The index of the obstacle 00076 * @param x_position A pointer to the varible storing the x coordinat 00077 * @param y_position A pointer to the varible storing the y coordinat 00078 * @return True, if there is an obstacle at the given index, otherwise false 00079 */ 00080 bool getPositionOfObstacle(int index, int* x_position, int* y_position); 00081 00082 /** 00083 * Calculates the distribution of points for x and y direction 00084 */ 00085 void calculateXYDistribution(); 00086 00087 /** 00088 * Finds maxima in the distribution of points for x and y direction 00089 */ 00090 void findMaximaInXYDistribution(); 00091 00092 /** 00093 * Votes for hills in the distribution of points. 00094 * The votes are sorted in a ranking, best first 00095 */ 00096 void voteForHills(); 00097 00098 /** 00099 * Calculates the distance of two given points. 00100 * @param x1 The x coordinate of the first point 00101 * @param y1 The y coordinate of the first point 00102 * @param x2 The x coordinate of the second point 00103 * @param y2 The y coordinate of the second point 00104 */ 00105 int calculateDistance(int x1, int y1, int x2, int y2); 00106 00107 00108 // streaming data 00109 /** The x coordinates of points in the set*/ 00110 short int x[MAX_NUMBER_OF_POINTS_WITH_AGE]; 00111 /** The y coordinates of points in the set*/ 00112 short int y[MAX_NUMBER_OF_POINTS_WITH_AGE]; 00113 /** The number of points in the set*/ 00114 short int numberOfPoints; 00115 /** The index of the position in the set where the next point can be stores */ 00116 short int indexOfNextPoint; 00117 /** The size of the set*/ 00118 short int sizeOfSet; 00119 //end streaming data 00120 00121 00122 /** The distribution of points in x direction */ 00123 short int xDistribution[NUMBER_OF_GRID_POINTS_X]; 00124 /** The distribution of points in y direction */ 00125 short int yDistribution[NUMBER_OF_GRID_POINTS_Y]; 00126 /** The number of detected hills in the x distribution */ 00127 short int numberOf_xHills; 00128 /** The number of detected hills in the y distribution */ 00129 short int numberOf_yHills; 00130 /** The hills (gridposition of hills) in the x distribution */ 00131 short int xHills[8]; 00132 /** The hills (gridposition of hills) in the y distribution */ 00133 short int yHills[8]; 00134 /** All possible hills in the grid, due to the distributions */ 00135 short int voteHills[8][8]; 00136 /** The x coordinates of the four best votes (generated by voteForHills) */ 00137 short int x_vote[4]; 00138 /** The y coordinates of the four best votes (generated by voteForHills) */ 00139 short int y_vote[4]; 00140 00141 /** The number of determined obstacles */ 00142 short int numberOfObstacles; 00143 00144 }; 00145 00146 /** 00147 * Streaming operator that reads a set of PointsWithValidityAndAge from a stream. 00148 * @param stream The stream from which is read. 00149 * @param pointsWithValidityAndAge The set of PointsWithValidityAndAge. 00150 * @return The stream. 00151 */ 00152 In& operator>>(In& stream,PointsWithValidityAndAge& pointsWithValidityAndAge); 00153 00154 /** 00155 * Streaming operator that writes a set of PointsWithValidityAndAge to a stream. 00156 * @param stream The stream to write on. 00157 * @param pointsWithValidityAndAge The Set of PointsWithValidityAndAge. 00158 * @return The stream. 00159 */ 00160 Out& operator<<(Out& stream, const PointsWithValidityAndAge& pointsWithValidityAndAge); 00161 00162 00163 #endif // _PointsWithValidityAndAge_h_ 00164 00165 00166 /* 00167 * Change log : 00168 * 00169 * $Log: PointsWithValidityAndAge.h,v $ 00170 * Revision 1.1.1.1 2004/05/22 17:20:40 cvsadm 00171 * created new repository GT2004_WM 00172 * 00173 * Revision 1.1 2003/10/06 14:10:15 cvsadm 00174 * Created GT2004 (M.J.) 00175 * 00176 * Revision 1.1 2003/09/26 11:38:52 juengel 00177 * - sorted tools 00178 * - clean-up in DataTypes 00179 * 00180 * Revision 1.1.1.1 2003/07/02 09:40:22 cvsadm 00181 * created new repository for the competitions in Padova from the 00182 * tamara CVS (Tuesday 2:00 pm) 00183 * 00184 * removed unused solutions 00185 * 00186 * Revision 1.2 2003/04/15 15:52:12 risler 00187 * DDD GO 2003 code integrated 00188 * 00189 * Revision 1.3 2003/04/13 02:41:57 dthomas 00190 * modified: raised queue size 00191 * 00192 * Revision 1.2 2003/03/31 15:27:00 mkunz 00193 * more points with validity and age 00194 * (without validity and age) 00195 * 00196 * Revision 1.1 2002/09/10 15:26:39 cvsadm 00197 * Created new project GT2003 (M.L.) 00198 * - Cleaned up the /Src/DataTypes directory 00199 * - Removed Challenge Code 00200 * - Removed processing of incoming audio data 00201 * - Renamed AcousticMessage to SoundRequest 00202 * 00203 * Revision 1.4 2002/07/23 13:32:57 loetzsch 00204 * new streaming classes 00205 * 00206 * removed many #include statements 00207 * 00208 * Revision 1.3 2002/06/07 10:15:46 kspiess 00209 * constructor changed 00210 * 00211 * Revision 1.2 2002/06/06 18:37:17 loetzsch 00212 * increased number of samples for player modelling 00213 * 00214 * Revision 1.1.1.1 2002/05/10 12:40:13 cvsadm 00215 * Moved GT2002 Project from ute to tamara. 00216 * 00217 * Revision 1.3 2002/02/08 14:20:33 kspiess 00218 * Anpassung an die Namenskonventionen 00219 * 00220 * Revision 1.2 2002/01/22 11:03:15 kspiess 00221 * Fehler im Default-Konstruktor behoben und 00222 * SetSizeOfSet-Methode eingebaut 00223 * 00224 * Revision 1.1 2002/01/21 23:18:30 kspiess 00225 * PointsWithValidityAndAge portiert; 00226 * wird vom BremenBerlin2001PlayersLocator verwendet 00227 * 00228 * 00229 */