00001 #ifndef FCS_FREECELL_DATA_H
00002 #define FCS_FREECELL_DATA_H
00003
00011
00012 #include <limits.h>
00013 #include "FCState.h"
00014 #include "FCSMove.h"
00015 #include "FCSDerivedStates.h"
00016 #include "FCCommandLineArguments.h"
00017 #include "FCSStateStorage.h"
00018 #include "FCSStackStorage.h"
00019
00020 #include "FCSIndirectStateCompareAlgorithm.h"
00021 #include "HashAlgorithms.h"
00022
00023 class FCSIndirectCard;
00024
00025 template <class SolvingAlgorithm>
00026 class FCSOptimizeSolvingAlgorithm;
00027
00028 class FCSFreecellSolvingAlgorithm;
00029 class FCSSimpleSimonSolvingAlgorithm;
00030 class FCSTalonSolvingAlgorithm;
00031
00033 class FCSFreecellData
00034 {
00035 public:
00037 virtual ~FCSFreecellData();
00038
00042 int GetNumberOfCheckedStates();
00043
00047 int GetNumberOfStatesInCollection();
00048
00050 void IncreaseMaxNumberOfCheckedStates();
00051
00054 void CleanData();
00055
00060 virtual void ShowSolution(FCSStateWithLocations* InitStateWithLocations, FCSStateWithLocations* DupStateWithLocations);
00061
00063 void TraceSolution();
00064
00066 friend class FCSOptimizeSolvingAlgorithm<FCSFreecellSolvingAlgorithm>;
00068 friend class FCSOptimizeSolvingAlgorithm<FCSSimpleSimonSolvingAlgorithm>;
00070 friend class FCSOptimizeSolvingAlgorithm<FCSTalonSolvingAlgorithm>;
00071
00072 protected:
00074 FCSFreecellData();
00076 void InitFCSFreecellData();
00078 FCSFreecellData(FCCommandLineArguments* CommandLine);
00079
00083 void InitSolve(FCSStateWithLocations* InitState);
00084
00090 int GetNextMove(FCSStateWithLocations* StateWithLocations, FCSMove* Move);
00091
00093 bool IsOptimizeClass;
00094
00096 FCStateType m_StateType;
00097
00106 AFCSStateWithLocationsMatrix* m_StatePacks;
00107
00109 int m_MaxNumberOfStatePacks;
00110
00112 int m_NumberOfStatePacks;
00113
00115 int m_NumberOfStatesInLastPack;
00116
00118 int m_StatePackLength;
00119
00121 int m_NumberOfCheckedStates;
00122
00126 int m_NumberOfStatesInCollection;
00127
00129 int m_MaxNumberOfStatesInCollection;
00130
00132 AFCSStateWithLocationsMatrix* m_SolutionStates;
00133
00135 int m_NumberOfSolutionStates;
00136
00141 FCSMoveStack* m_SolutionMoves;
00142
00145 FCSMoveStack** m_ProtoSolutionMoves;
00146
00148 FCSStateWithLocations* m_FinalState;
00149
00154 int m_MaxDepth;
00155
00160 int m_MaxNumberOfCheckedStates;
00161
00164 FCSDebugDisplayInfo* m_DebugDisplayInfo;
00165
00167 int m_TestsOrder[FCS_TESTS_NUM];
00168
00170 int m_TestsOrderNumber;
00171
00173 AFCSGenericStateStorage* m_StateStorage;
00174
00176 AFCSGenericStackStorage* m_StackStorage;
00177
00179 int m_NumberOfFreecells;
00180
00182 int m_NumberOfStacks;
00183
00185 int m_NumberOfDecks;
00186
00188 BuildSequenceByEnum m_SequencesAreBuiltBy;
00189
00192 bool m_IsUnlimitedSequenceMove;
00193
00195 FCEmptyStacksFillType m_EmptyStacksFill;
00196
00198 bool m_OptimizeSolutionPath;
00199
00200
00201
00203 CompareFunctionCompareNodesAlgorithm<FCSStateWithLocations, void> m_CompareFunction;
00205 MD5StateWithLocationsHashAlgorithm m_MD5Hash;
00207 FCSIndirectCardCompareAlgorithm<FCSIndirectCard, void>* m_IndirectCompare;
00209 MD5HashAlgorithm<FCSIndirectCard>* m_IndirectHash;
00210
00212 FCSStateWithLocations* StatePackAlloc();
00213
00215 void StatePackRelease();
00216
00223 virtual FCSStateSolvingReturnCodes CheckAndAddState(FCSStateWithLocations* NewState,
00224 FCSStateWithLocations** ExistingState,
00225 int Depth);
00226
00233 virtual inline void CheckStateBegin(FCSStateWithLocations** NewStateWithLocations, FCSStateWithLocations* StateWithLocations,
00234 FCSMoveStack *Move);
00235
00246 virtual inline bool CheckStateEnd(FCSStateWithLocations** NewStateWithLocations, FCSStateWithLocations* StateWithLocations,
00247 FCSDerivedStatesList** DerivedStateList, FCSMoveStack** Move, FCSMove** TempMove, int Depth,
00248 FCSStateSolvingReturnCodes* ReturnCode);
00249
00251 void CreateTotalMovesStack();
00252
00258 bool IsParentCard(FCSCard* Child, FCSCard* Parent);
00259
00266 int CalculateMaxSequenceMoves(int FreecellNumber, int FreeStackNumber);
00267
00278 void MoveSequence(FCSStateWithLocations* NewStateWithLocations, FCSCard* Card, FCSMoveStack *MoveStack, FCSMove** TempMove,
00279 int DestStack, int SourceStack, int Start, int End);
00280
00281 };
00282
00283 #endif