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

Tools/KickSelectionTable.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file KickSelectionTable.cpp
00003 * Implementation of class KickSelectionTable.
00004 *
00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
00006 */
00007 
00008 #include "KickSelectionTable.h"
00009 #include "Platform/SystemCall.h"
00010 #include "Tools/Math/Common.h"
00011 #include "Tools/Streams/InStreams.h"
00012 #include "Tools/Debugging/Debugging.h"
00013 #include "Tools/Location.h"
00014 
00015 
00016 KickSelectionTable::KickSelectionTable()
00017 {
00018   memset(action,0,sizeof(action));
00019 }
00020 
00021 KickSelectionTable::~KickSelectionTable()
00022 {
00023 }
00024 
00025 KickSelectionTable::KickSelectionTableID KickSelectionTable::getTableIDFromName(const char* name)
00026 {
00027   for (int i=0;i<numberOfKickSelectionTableIDs;i++)
00028   {
00029     if (strcmp(name,getKickSelectionTableIDName((KickSelectionTableID)i))==0)
00030     {
00031       return (KickSelectionTableID)i;
00032     }
00033   }
00034   
00035   return inCenterOfField;
00036 }
00037 
00038 KickSelectionTable::ActionID KickSelectionTable::getActionIDFromShortName(const char* name)
00039 {
00040   for (int i=0;i<numberOfActions;i++)
00041   {
00042     if (strcmp(name,getShortActionName((ActionID)i))==0)
00043     {
00044       return (ActionID)i;
00045     }
00046   }
00047   
00048   return nothing;
00049 }
00050 
00051 void KickSelectionTable::load(const char* fileName)
00052 {
00053   InTextFile f(getLocation().getModelFilename(fileName));
00054   if (f.exists())
00055     f >> *this;
00056 }
00057 
00058 KickSelectionTable::ActionID KickSelectionTable::retrieveKick
00059 (
00060  double ballOffsetX, double ballOffsetY,
00061  double destinationAngle,
00062  KickSelectionTableID kickSelectionTableID
00063  ) const
00064 {
00065   int x,y;
00066   int sector;
00067   sector = (int)((normalize(fromDegrees(destinationAngle) + pi + pi2 / KickSelectionTable::numberOfSectors / 2) + pi) / pi2 * KickSelectionTable::numberOfSectors);
00068   x = (int)(ballOffsetX / 10.0);
00069   y = (int)(ballOffsetY / 10.0) + KickSelectionTable::yRange / 2;
00070   
00071   //  OUTPUT(idText,text,"bx: " << ballOffsetX << ", by: " << ballOffsetY
00072   //    << ", x: " << x << ", y: " << y << ", a: " << destinationAngle 
00073   //    << ", s: " << sector << ", t: " << kickSelectionTableID);
00074   
00075   if(x < 0 || x >= KickSelectionTable::xRange ||
00076     y < 0 || y >= KickSelectionTable::yRange) return nothing;
00077   
00078   
00079   
00080   return action[x][y][sector][kickSelectionTableID];
00081 }
00082 
00083 In& operator>>(In& stream, KickSelectionTable& kickSelectionTable)
00084 {
00085   KickSelectionTable::KickSelectionTableID tableID;
00086   KickSelectionTable::ActionID actionID;
00087   int x,y,s;
00088   char buf[200];
00089   memset(kickSelectionTable.action,0,sizeof(kickSelectionTable.action));
00090   while (1)
00091   {
00092     stream >> buf;
00093     if (strcmp(buf,"___")==0) break;
00094     tableID = kickSelectionTable.getTableIDFromName(buf);
00095     while(1)
00096     {
00097       stream >> buf;
00098       if (strcmp(buf,"___")==0) break;
00099       
00100       x = atoi(buf);
00101       
00102       stream >> y >> s >> buf;
00103       actionID = kickSelectionTable.getActionIDFromShortName(buf);
00104       kickSelectionTable.action[x][y][s][tableID] = actionID;
00105     }
00106   }
00107   return stream;
00108 }
00109 
00110 Out& operator<<(Out& stream, const KickSelectionTable& kickSelectionTable)
00111 {
00112   int t,x,y,s;
00113   for (t=0; t<KickSelectionTable::numberOfKickSelectionTableIDs; t++)
00114   {
00115     stream << kickSelectionTable.getKickSelectionTableIDName((KickSelectionTable::KickSelectionTableID)t);
00116     
00117     for (x = 0; x< kickSelectionTable.xRange; x++)
00118     {
00119       for (y = 0; y< kickSelectionTable.yRange; y++)
00120       {
00121         for (s = 0; s< kickSelectionTable.numberOfSectors; s++)
00122         {
00123           if (kickSelectionTable.action[x][y][s][t] != KickSelectionTable::nothing)
00124           {
00125             stream << x << y << s << kickSelectionTable.getShortActionName(
00126               kickSelectionTable.action[x][y][s][t]);
00127           }
00128         }
00129       }
00130     }
00131     stream << "___";
00132   }
00133   stream << "___";
00134   return stream;
00135 }
00136 
00137 In& operator>>(In& stream,KickCase& kickCase)
00138 {
00139   stream.read(&kickCase,sizeof(KickCase));
00140   return stream;
00141 }
00142  
00143 Out& operator<<(Out& stream, const KickCase& kickCase)
00144 {
00145   stream.write(&kickCase,sizeof(KickCase));
00146   return stream;
00147 }
00148 
00149 /*
00150 * Change log :
00151 * 
00152 * $Log: KickSelectionTable.cpp,v $
00153 * Revision 1.5  2004/06/30 11:07:27  cesarz
00154 * kick selection table is location based now for Lisboa penalty shooter
00155 *
00156 * Revision 1.4  2004/06/24 13:57:10  risler
00157 * clear table when reading from stream
00158 *
00159 * Revision 1.3  2004/06/20 15:22:35  risler
00160 * increased kick editor usability:
00161 * KickLogger now sends kick record via debug key instead of writing to file
00162 * KickEditor automatically displays sent kick records
00163 * KickCase moved to KickSelectionTable
00164 *
00165 * Revision 1.2  2004/06/17 14:27:21  risler
00166 * load table only if file exists
00167 *
00168 * Revision 1.1.1.1  2004/05/22 17:35:53  cvsadm
00169 * created new repository GT2004_WM
00170 *
00171 * Revision 1.1  2004/03/16 14:00:23  juengel
00172 * Integrated Improvments from "Günne"
00173 * -ATH2004ERS7Behavior
00174 * -ATHHeadControl
00175 * -KickSelectionTable
00176 * -KickEditor
00177 *
00178 * Revision 1.4  2004/03/10 18:41:00  loetzsch
00179 * first functioning version
00180 *
00181 * Revision 1.3  2004/03/10 14:06:04  juengel
00182 * Implemented retrieveKick.
00183 *
00184 * Revision 1.2  2004/03/09 18:43:54  juengel
00185 * Added ActionID "nothing".
00186 *
00187 * Revision 1.1  2004/03/09 13:40:30  juengel
00188 * Moved KickSelectionTable to Tools.
00189 *
00190 * Revision 1.1  2004/03/09 01:14:36  juengel
00191 * Added class KickSelectionTable.
00192 *
00193 */

Generated on Thu Sep 23 19:57:38 2004 for GT2004 by doxygen 1.3.6