00001 00002 00003 00004 00005 00006 00007 00008 00009 #include "FCTalonState.h" 00010 #include "FCSTalonStateWithLocations.h" 00011 00012 FCSDebugTalonStateData::FCSDebugTalonStateData() 00013 { 00014 m_Talon = NULL; 00015 } 00016 00017 FCSDebugTalonStateData::~FCSDebugTalonStateData() 00018 { 00019 if (m_Talon != NULL) 00020 delete [] m_Talon; 00021 } 00022 00023 void FCSDebugTalonStateData::Copy(FCSTalonStateData* Data) 00024 { 00025 FCSTalonStateData::Copy(Data); 00026 00027 if (m_Talon == NULL) 00028 m_Talon = new FCSDebugCard[m_KlondikeTalonLength]; 00029 00030 for (int i = 0; i < m_KlondikeTalonLength; i++) 00031 m_Talon[i].Copy(&((FCSDebugTalonStateData*)Data)->m_Talon[i]); 00032 } 00033 00034 int FCSDebugTalonStateData::Compare(const FCSTalonStateData* TalonData) 00035 { 00036 int CompareValue = FCSTalonStateData::Compare(TalonData); 00037 if (CompareValue != 0) 00038 return CompareValue; 00039 00040 for (int a = 0;a<m_KlondikeTalonLength;a++) 00041 if ((CompareValue = m_Talon[a].Compare(&((FCSDebugTalonStateData*)TalonData)->m_Talon[a])) != 0) 00042 return CompareValue; 00043 00044 return 0; 00045 }; 00046 00047 00048 FCSCard* FCSDebugTalonStateData::GetTalon(int Position) 00049 { 00050 return &m_Talon[Position]; 00051 } 00052 00053 void FCSDebugTalonStateData::KlondikeTalonQueueToStack() 00054 { 00055 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00056 while ((m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION] < m_KlondikeTalonLength-1) && 00057 (m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]].IsEmptyCard())) 00058 { 00059 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00060 } 00061 00062 m_TalonParams[FC_TALON_PARAM_KLONDIKE_QUEUE_POSITION]++; 00063 } 00064 00065 FCSCard* FCSDebugTalonStateData::GetKlondikeTalonTopCard() 00066 { 00067 return &m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]]; 00068 } 00069 00070 00071 00072 FCSDebugTalonStateWithLocations::FCSDebugTalonStateWithLocations() : FCSDebugStateWithLocations<FCSTalonStateWithLocations>() 00073 { 00074 m_TalonData = NULL; 00075 } 00076 00077 FCSDebugTalonStateWithLocations::~FCSDebugTalonStateWithLocations() 00078 { 00079 } 00080 00081 void FCSDebugTalonStateWithLocations::Copy(FCSStateWithLocations* State) 00082 { 00083 FCSDebugStateWithLocations<FCSTalonStateWithLocations>::Copy(State); 00084 m_TalonData = new FCSDebugTalonStateData(); 00085 m_TalonData->Copy(((FCSDebugTalonStateWithLocations*)State)->m_TalonData); 00086 } 00087 00088 void FCSDebugTalonStateWithLocations::Initialize(int NumberOfStacks) 00089 { 00090 m_TalonData = new FCSDebugTalonStateData(); 00091 } 00092 00093 void FCSDebugTalonStateWithLocations::CleanState() 00094 { 00095 if (m_TalonData != NULL) 00096 delete m_TalonData; 00097 } 00098 00099 void FCSDebugTalonStateWithLocations::CacheTalonStacks(FCInternalHash<FCSTalonStateData, void>* TalonHash) 00100 { 00101 FCSDebugTalonStateData* CachedTalonData; 00102 00103 Realloc<FCSDebugCard>(&m_TalonData->m_Talon, 00104 (m_TalonData->m_Talon == NULL) ? 0 : m_TalonData->GetKlondikeTalonLength()+1, 00105 m_TalonData->GetKlondikeTalonLength()+1); 00106 00107 CachedTalonData = (FCSDebugTalonStateData*)TalonHash->Insert(m_TalonData, true); 00108 00109 if (CachedTalonData != NULL) 00110 { 00111 delete m_TalonData; 00112 m_TalonData = CachedTalonData; 00113 } 00114 } 00115 00116 void FCSDebugTalonStateWithLocations::CreateTalons(int NumberOfTalons) 00117 { 00118 m_TalonData->m_Talon = new FCSDebugCard[NumberOfTalons]; 00119 } 00120 00121 FCSTalonStateData* FCSDebugTalonStateWithLocations::GetTalonData() 00122 { 00123 return m_TalonData; 00124 } 00125 00126 void FCSDebugTalonStateWithLocations::DecrementKlondikeTalonStack() 00127 { 00128 m_TalonData->m_Talon[m_TalonData->m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]--].EmptyCard(); 00129 } 00130 00131 00132 FCSCompactTalonStateData::FCSCompactTalonStateData() 00133 { 00134 m_Talon = NULL; 00135 } 00136 00137 FCSCompactTalonStateData::~FCSCompactTalonStateData() 00138 { 00139 if (m_Talon != NULL) 00140 delete [] m_Talon; 00141 } 00142 00143 void FCSCompactTalonStateData::Copy(FCSTalonStateData* Data) 00144 { 00145 FCSTalonStateData::Copy(Data); 00146 00147 if (m_Talon == NULL) 00148 m_Talon = new FCSCompactCard[m_KlondikeTalonLength]; 00149 00150 for (int i = 0; i < m_KlondikeTalonLength; i++) 00151 m_Talon[i].Copy(&((FCSCompactTalonStateData*)Data)->m_Talon[i]); 00152 } 00153 00154 int FCSCompactTalonStateData::Compare(const FCSTalonStateData* TalonData) 00155 { 00156 int CompareValue = FCSTalonStateData::Compare(TalonData); 00157 if (CompareValue != 0) 00158 return CompareValue; 00159 00160 for (int a = 0;a<m_KlondikeTalonLength;a++) 00161 if ((CompareValue = m_Talon[a].Compare(&((FCSCompactTalonStateData*)TalonData)->m_Talon[a])) != 0) 00162 return CompareValue; 00163 00164 return 0; 00165 }; 00166 00167 FCSCard* FCSCompactTalonStateData::GetTalon(int Position) 00168 { 00169 return &m_Talon[Position]; 00170 } 00171 00172 void FCSCompactTalonStateData::KlondikeTalonQueueToStack() 00173 { 00174 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00175 while ((m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION] < m_KlondikeTalonLength-1) && 00176 (m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]].IsEmptyCard())) 00177 { 00178 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00179 } 00180 00181 m_TalonParams[FC_TALON_PARAM_KLONDIKE_QUEUE_POSITION]++; 00182 } 00183 00184 FCSCard* FCSCompactTalonStateData::GetKlondikeTalonTopCard() 00185 { 00186 return &m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]]; 00187 } 00188 00189 FCSCompactTalonStateWithLocations::FCSCompactTalonStateWithLocations() : FCSCompactStateWithLocations<FCSTalonStateWithLocations>() 00190 { 00191 m_TalonData = NULL; 00192 } 00193 00194 FCSCompactTalonStateWithLocations::~FCSCompactTalonStateWithLocations() 00195 { 00196 } 00197 00198 void FCSCompactTalonStateWithLocations::Copy(FCSStateWithLocations* State) 00199 { 00200 FCSCompactStateWithLocations<FCSTalonStateWithLocations>::Copy(State); 00201 m_TalonData = new FCSCompactTalonStateData(); 00202 m_TalonData->Copy(((FCSCompactTalonStateWithLocations*)State)->m_TalonData); 00203 } 00204 00205 void FCSCompactTalonStateWithLocations::Initialize(int NumberOfStacks) 00206 { 00207 m_TalonData = new FCSCompactTalonStateData(); 00208 } 00209 00210 void FCSCompactTalonStateWithLocations::CleanState() 00211 { 00212 if (m_TalonData != NULL) 00213 delete m_TalonData; 00214 } 00215 00216 void FCSCompactTalonStateWithLocations::CacheTalonStacks(FCInternalHash<FCSTalonStateData, void>* TalonHash) 00217 { 00218 FCSCompactTalonStateData* CachedTalonData; 00219 00220 Realloc<FCSCompactCard>(&m_TalonData->m_Talon, 00221 (m_TalonData->m_Talon == NULL) ? 0 : m_TalonData->GetKlondikeTalonLength()+1, 00222 m_TalonData->GetKlondikeTalonLength()+1); 00223 00224 CachedTalonData = (FCSCompactTalonStateData*)TalonHash->Insert(m_TalonData, true); 00225 00226 if (CachedTalonData != NULL) 00227 { 00228 delete m_TalonData; 00229 m_TalonData = CachedTalonData; 00230 } 00231 } 00232 00233 void FCSCompactTalonStateWithLocations::CreateTalons(int NumberOfTalons) 00234 { 00235 m_TalonData->m_Talon = new FCSCompactCard[NumberOfTalons]; 00236 } 00237 00238 FCSTalonStateData* FCSCompactTalonStateWithLocations::GetTalonData() 00239 { 00240 return m_TalonData; 00241 } 00242 00243 void FCSCompactTalonStateWithLocations::DecrementKlondikeTalonStack() 00244 { 00245 m_TalonData->m_Talon[m_TalonData->m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]--].EmptyCard(); 00246 } 00247 00248 00249 00250 FCSIndirectTalonStateData::FCSIndirectTalonStateData() 00251 { 00252 m_Talon = NULL; 00253 } 00254 00255 FCSIndirectTalonStateData::~FCSIndirectTalonStateData() 00256 { 00257 if (m_Talon != NULL) 00258 delete [] m_Talon; 00259 } 00260 00261 void FCSIndirectTalonStateData::Copy(FCSTalonStateData* Data) 00262 { 00263 FCSTalonStateData::Copy(Data); 00264 00265 if (m_Talon == NULL) 00266 m_Talon = new FCSIndirectCard[m_KlondikeTalonLength]; 00267 00268 for (int i = 0; i < m_KlondikeTalonLength; i++) 00269 m_Talon[i].Copy(&((FCSIndirectTalonStateData*)Data)->m_Talon[i]); 00270 } 00271 00272 int FCSIndirectTalonStateData::Compare(const FCSTalonStateData* TalonData) 00273 { 00274 int CompareValue = FCSTalonStateData::Compare(TalonData); 00275 if (CompareValue != 0) 00276 return CompareValue; 00277 00278 for (int a = 0;a<m_KlondikeTalonLength;a++) 00279 if ((CompareValue = m_Talon[a].Compare(&((FCSIndirectTalonStateData*)TalonData)->m_Talon[a])) != 0) 00280 return CompareValue; 00281 00282 return 0; 00283 }; 00284 00285 FCSCard* FCSIndirectTalonStateData::GetTalon(int Position) 00286 { 00287 return &m_Talon[Position]; 00288 } 00289 00290 void FCSIndirectTalonStateData::KlondikeTalonQueueToStack() 00291 { 00292 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00293 while ((m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION] < m_KlondikeTalonLength-1) && 00294 (m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]].IsEmptyCard())) 00295 { 00296 m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]++; 00297 } 00298 00299 m_TalonParams[FC_TALON_PARAM_KLONDIKE_QUEUE_POSITION]++; 00300 } 00301 00302 FCSCard* FCSIndirectTalonStateData::GetKlondikeTalonTopCard() 00303 { 00304 return &m_Talon[m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]]; 00305 } 00306 00307 FCSIndirectTalonStateWithLocations::FCSIndirectTalonStateWithLocations() : FCSIndirectStateWithLocations<FCSTalonStateWithLocations>() 00308 { 00309 m_TalonData = NULL; 00310 } 00311 00312 FCSIndirectTalonStateWithLocations::~FCSIndirectTalonStateWithLocations() 00313 { 00314 } 00315 00316 void FCSIndirectTalonStateWithLocations::Copy(FCSStateWithLocations* State) 00317 { 00318 FCSIndirectStateWithLocations<FCSTalonStateWithLocations>::Copy(State); 00319 m_TalonData = new FCSIndirectTalonStateData(); 00320 m_TalonData->Copy(((FCSIndirectTalonStateWithLocations*)State)->m_TalonData); 00321 } 00322 00323 void FCSIndirectTalonStateWithLocations::Initialize(int NumberOfStacks) 00324 { 00325 FCSIndirectStateWithLocations<FCSTalonStateWithLocations>::Initialize(NumberOfStacks); 00326 m_TalonData = new FCSIndirectTalonStateData(); 00327 } 00328 00329 void FCSIndirectTalonStateWithLocations::CleanState() 00330 { 00331 FCSIndirectStateWithLocations<FCSTalonStateWithLocations>::CleanState(); 00332 if (m_TalonData != NULL) 00333 delete m_TalonData; 00334 } 00335 00336 void FCSIndirectTalonStateWithLocations::CacheTalonStacks(FCInternalHash<FCSTalonStateData, void>* TalonHash) 00337 { 00338 FCSIndirectTalonStateData* CachedTalonData; 00339 00340 Realloc<FCSIndirectCard>(&m_TalonData->m_Talon, 00341 (m_TalonData->m_Talon == NULL) ? 0 : m_TalonData->GetKlondikeTalonLength()+1, 00342 m_TalonData->GetKlondikeTalonLength()+1); 00343 00344 CachedTalonData = (FCSIndirectTalonStateData*)TalonHash->Insert(m_TalonData, true); 00345 00346 if (CachedTalonData != NULL) 00347 { 00348 delete m_TalonData; 00349 m_TalonData = CachedTalonData; 00350 } 00351 } 00352 00353 void FCSIndirectTalonStateWithLocations::CreateTalons(int NumberOfTalons) 00354 { 00355 m_TalonData->m_Talon = new FCSIndirectCard[NumberOfTalons]; 00356 } 00357 00358 FCSTalonStateData* FCSIndirectTalonStateWithLocations::GetTalonData() 00359 { 00360 return m_TalonData; 00361 } 00362 00363 void FCSIndirectTalonStateWithLocations::DecrementKlondikeTalonStack() 00364 { 00365 m_TalonData->m_Talon[m_TalonData->m_TalonParams[FC_TALON_PARAM_KLONDIKE_STACK_POSITION]--].EmptyCard(); 00366 }