00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream.h>
00010
00011 #ifdef _DEBUG
00012 #include <afx.h>
00013 #endif
00014
00015 #include "FCSFreecellSolvingAlgorithm.h"
00016 #include "FCSSimpleSimonSolvingAlgorithm.h"
00017 #include "FCCommandLineArguments.h"
00018 #include "FCSOptimizeSolvingAlgorithm.h"
00019 #include "FCPresets.h"
00020 #include "MainGameFunctions.h"
00021
00023 int main(int argc, char **argv)
00024 {
00025
00026 #ifdef _DEBUG
00027 CMemoryState oldMemState, newMemState, diffMemState;
00028 oldMemState.Checkpoint();
00029 #endif
00030
00031 FCSFreecellSolvingAlgorithm* SolvingAlgorithm = NULL;
00032 FCSSimpleSimonSolvingAlgorithm* SimpleSimonSolvingAlgorithm = NULL;
00033 FCSTalonSolvingAlgorithm* TalonSolvingAlgorithm = NULL;
00034 FCCommandLineArguments CommandLineArguments;
00035 FCSStateWithLocations *InitialState,
00036 *DuplicateInitialState;
00037 FCSStateSolvingReturnCodes SolveValue;
00038 FCSPresetID GamePreset;
00039
00040 if (!CommandLineArguments.Parse(argc, argv))
00041 exit(-1);
00042 if (!CommandLineArguments.Verify())
00043 exit(-1);
00044
00045 GamePreset = FCSPresetName::GetPresetID(CommandLineArguments.GetGameName());
00046 MainCreate(GamePreset, &CommandLineArguments,
00047 &SolvingAlgorithm, &SimpleSimonSolvingAlgorithm, &TalonSolvingAlgorithm);
00048
00049 InitialState = CommandLineArguments.GetInitialState();
00050
00051 DuplicateInitialState = CreateStateWithLocations();
00052 DuplicateInitialState->Copy(InitialState);
00053
00054 InitialState->CanonizeState(CommandLineArguments.GetNumberOfFreecells(),
00055 CommandLineArguments.GetNumberOfStacks());
00056
00057 if (InitialState != NULL)
00058 {
00059 SolveValue = MainSolve(GamePreset, InitialState,
00060 SolvingAlgorithm, SimpleSimonSolvingAlgorithm, TalonSolvingAlgorithm);
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 if (SolveValue == FCS_STATE_WAS_SOLVED)
00072 {
00073 cout << "This game is solveable." << endl;
00074 if (CommandLineArguments.GetOptimizeSolution())
00075 {
00076 cout << "Now trying to optimize solution." << endl;
00077 MainOptimize(GamePreset, InitialState, DuplicateInitialState,
00078 SolvingAlgorithm, SimpleSimonSolvingAlgorithm, TalonSolvingAlgorithm);
00079 }
00080 else
00081 {
00082 MainSolution(GamePreset, InitialState, DuplicateInitialState,
00083 SolvingAlgorithm, SimpleSimonSolvingAlgorithm, TalonSolvingAlgorithm);
00084 }
00085 }
00086 else
00087 {
00088 cout << "I could not solve this game." << endl;
00089 }
00090
00091 MainStats(GamePreset, SolvingAlgorithm, SimpleSimonSolvingAlgorithm, TalonSolvingAlgorithm);
00092
00093 DuplicateInitialState->CleanState();
00094 delete DuplicateInitialState;
00095
00096 delete InitialState;
00097 delete SolvingAlgorithm;
00098 delete SimpleSimonSolvingAlgorithm;
00099 delete TalonSolvingAlgorithm;
00100
00101 #ifdef _DEBUG
00102 newMemState.Checkpoint();
00103 if( diffMemState.Difference( oldMemState, newMemState ) )
00104 {
00105 diffMemState.DumpStatistics();
00106 TRACE( "Memory leaked detected!!!\n" );
00107 cout << "Memory leaked detected!!!" << endl;
00108 _CrtDumpMemoryLeaks();
00109 }
00110 #endif
00111
00112 return 0;
00113 }
00114