00001
00002
00003
00004
00005
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
00072
00073
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
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193