00001 #ifndef MMANN_FCS_DEBUG_STATE_WITH_LOCATIONS_H
00002 #define MMANN_FCS_DEBUG_STATE_WITH_LOCATIONS_H
00003
00011
00012 class FCSDebugState;
00013
00016 template <class StateWithLocation>
00017 class FCSDebugStateWithLocations : public StateWithLocation
00018 {
00019 public:
00021 FCSDebugStateWithLocations();
00022
00024 virtual ~FCSDebugStateWithLocations();
00025
00029 virtual void Copy(FCSStateWithLocations* State);
00030
00036 int Compare(const FCSStateWithLocations* State);
00037
00043 FCSCard* GetStackCard(int Stack, int Card);
00044
00050 char GetStackCardSuit(int Stack, int Card);
00051
00057 char GetStackCardNumber(int Stack, int Card);
00058
00063 int GetStackLength(int Stack);
00064
00069 FCSCard* GetFreecellCard(int Freecell);
00070
00075 char GetFreecellCardSuit(int Freecell);
00076
00081 char GetFreecellCardNumber(int Freecell);
00082
00087 char GetFoundation(int Foundation);
00088
00092 void IncrementFoundation(int Foundation);
00093
00098 void SetFoundation(int Foundation, char Value);
00099
00104 void PopStackCard(int Stack, FCSCard* Card);
00105
00111 void PushStackCardIntoStack(int DestStack, int SrcStack, int SrcCard);
00112
00117 void PushCardIntoStack(int DestStack, FCSCard* Card);
00118
00123 void PutCardInFreecell(int Freecell, FCSCard* Card);
00124
00128 void EmptyFreecell(int Freecell);
00129
00134 void FlipStackCard(int Stack, int Card);
00135
00140 void CanonizeState(int NumberOfFreecells, int NumberOfStacks);
00141
00145 FCSState* GetState();
00146
00147 protected:
00149 FCSDebugState m_State;
00150 };
00151
00152 template <class StateWithLocation>
00153 FCSDebugStateWithLocations<StateWithLocation>::FCSDebugStateWithLocations() : StateWithLocation()
00154 {
00155 }
00156
00157 template <class StateWithLocation>
00158 FCSDebugStateWithLocations<StateWithLocation>::~FCSDebugStateWithLocations()
00159 {
00160 }
00161
00162 template <class StateWithLocation>
00163 void FCSDebugStateWithLocations<StateWithLocation>::Copy(FCSStateWithLocations* State)
00164 {
00165 StateWithLocation::Copy(State);
00166
00167 m_State = ((FCSDebugStateWithLocations*)State)->m_State;
00168 }
00169
00170 template <class StateWithLocation>
00171 int FCSDebugStateWithLocations<StateWithLocation>::Compare(const FCSStateWithLocations *State)
00172 {
00173 return m_State.Compare(&(((FCSDebugStateWithLocations*)State)->m_State));
00174 }
00175
00176 template <class StateWithLocation>
00177 FCSCard* FCSDebugStateWithLocations<StateWithLocation>::GetStackCard(int Stack, int Card)
00178 {
00179 return &(m_State.m_Stacks[Stack].m_Cards[Card]);
00180 }
00181
00182 template <class StateWithLocation>
00183 char FCSDebugStateWithLocations<StateWithLocation>::GetStackCardSuit(int Stack, int Card)
00184 {
00185 return m_State.m_Stacks[Stack].m_Cards[Card].GetSuit();
00186 }
00187
00188 template <class StateWithLocation>
00189 char FCSDebugStateWithLocations<StateWithLocation>::GetStackCardNumber(int Stack, int Card)
00190 {
00191 return m_State.m_Stacks[Stack].m_Cards[Card].GetCardNumber();
00192 }
00193
00194 template <class StateWithLocation>
00195 int FCSDebugStateWithLocations<StateWithLocation>::GetStackLength(int Stack)
00196 {
00197 return m_State.m_Stacks[Stack].m_NumberOfCards;
00198 }
00199
00200 template <class StateWithLocation>
00201 FCSCard* FCSDebugStateWithLocations<StateWithLocation>::GetFreecellCard(int Freecell)
00202 {
00203 return &(m_State.m_Freecells[Freecell]);
00204 }
00205
00206 template <class StateWithLocation>
00207 char FCSDebugStateWithLocations<StateWithLocation>::GetFreecellCardSuit(int Freecell)
00208 {
00209 return m_State.m_Freecells[Freecell].GetSuit();
00210 }
00211
00212 template <class StateWithLocation>
00213 char FCSDebugStateWithLocations<StateWithLocation>::GetFreecellCardNumber(int Freecell)
00214 {
00215 return m_State.m_Freecells[Freecell].GetCardNumber();
00216 }
00217
00218 template <class StateWithLocation>
00219 char FCSDebugStateWithLocations<StateWithLocation>::GetFoundation(int Foundation)
00220 {
00221 return m_State.m_Foundations[Foundation];
00222 }
00223
00224 template <class StateWithLocation>
00225 void FCSDebugStateWithLocations<StateWithLocation>::IncrementFoundation(int Foundation)
00226 {
00227 m_State.m_Foundations[Foundation]++;
00228 }
00229
00230 template <class StateWithLocation>
00231 void FCSDebugStateWithLocations<StateWithLocation>::SetFoundation(int Foundation, char Value)
00232 {
00233 m_State.m_Foundations[Foundation] = Value;
00234 }
00235
00236 template <class StateWithLocation>
00237 void FCSDebugStateWithLocations<StateWithLocation>::PopStackCard(int Stack, FCSCard* Card)
00238 {
00239 Card->Copy(&m_State.m_Stacks[Stack].m_Cards[m_State.m_Stacks[Stack].m_NumberOfCards-1]);
00240 m_State.m_Stacks[Stack].m_Cards[m_State.m_Stacks[Stack].m_NumberOfCards-1].EmptyCard();
00241 m_State.m_Stacks[Stack].m_NumberOfCards--;
00242 }
00243
00244 template <class StateWithLocation>
00245 void FCSDebugStateWithLocations<StateWithLocation>::PushStackCardIntoStack(int DestStack, int SrcStack, int SrcCard)
00246 {
00247 m_State.m_Stacks[DestStack].m_Cards[m_State.m_Stacks[DestStack].m_NumberOfCards].Copy(&m_State.m_Stacks[SrcStack].m_Cards[SrcCard]);
00248 m_State.m_Stacks[DestStack].m_NumberOfCards++;
00249 }
00250
00251 template <class StateWithLocation>
00252 void FCSDebugStateWithLocations<StateWithLocation>::PushCardIntoStack(int DestStack, FCSCard* Card)
00253 {
00254 m_State.m_Stacks[DestStack].m_Cards[m_State.m_Stacks[DestStack].m_NumberOfCards].Copy(Card);
00255 m_State.m_Stacks[DestStack].m_NumberOfCards++;
00256 }
00257
00258 template <class StateWithLocation>
00259 void FCSDebugStateWithLocations<StateWithLocation>::PutCardInFreecell(int Freecell, FCSCard* Card)
00260 {
00261 m_State.m_Freecells[Freecell].Copy(Card);
00262 }
00263
00264 template <class StateWithLocation>
00265 void FCSDebugStateWithLocations<StateWithLocation>::EmptyFreecell(int Freecell)
00266 {
00267 m_State.m_Freecells[Freecell].m_CardNumber = 0;
00268 m_State.m_Freecells[Freecell].m_Suit = 0;
00269 m_State.m_Freecells[Freecell].m_Flags = 0;
00270 }
00271
00272 template <class StateWithLocation>
00273 void FCSDebugStateWithLocations<StateWithLocation>::FlipStackCard(int Stack, int Card)
00274 {
00275 m_State.m_Stacks[Stack].m_Cards[Card].SetFlipped(0);
00276 }
00277
00278 template <class StateWithLocation>
00279 void FCSDebugStateWithLocations<StateWithLocation>::CanonizeState(int NumberOfFreecells, int NumberOfStacks)
00280 {
00281 int b,c;
00282
00283 FCSDebugStack TempStack;
00284 FCSDebugCard TempFeecell;
00285 char TempLocation;
00286
00287
00288 for(b=1;b<NumberOfStacks;b++)
00289 {
00290 c = b;
00291 while((c>0) && (m_State.StackCompare(c, c-1) < 0))
00292 {
00293 TempStack = m_State.m_Stacks[c];
00294 m_State.m_Stacks[c] = m_State.m_Stacks[c-1];
00295 m_State.m_Stacks[c-1] = TempStack;
00296
00297 TempLocation = m_StackLocations[c];
00298 m_StackLocations[c] = m_StackLocations[c-1];
00299 m_StackLocations[c-1] = TempLocation;
00300
00301 c--;
00302 }
00303 }
00304
00305
00306 for(b=1;b<NumberOfFreecells;b++)
00307 {
00308 c = b;
00309 while((c>0) && (m_State.m_Freecells[c].Compare(&m_State.m_Freecells[c-1]) < 0))
00310 {
00311 TempFeecell = m_State.m_Freecells[c];
00312 m_State.m_Freecells[c] = m_State.m_Freecells[c-1];
00313 m_State.m_Freecells[c-1] = TempFeecell;
00314
00315 TempLocation = m_FreecellLocations[c];
00316 m_FreecellLocations[c] = m_FreecellLocations[c-1];
00317 m_FreecellLocations[c-1] = TempLocation;
00318
00319 c--;
00320 }
00321 }
00322 }
00323
00324 template <class StateWithLocation>
00325 FCSState* FCSDebugStateWithLocations<StateWithLocation>::GetState()
00326 {
00327 return &m_State;
00328 }
00329
00330 #endif