Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

FCSFreecellData Class Reference

Holds all of the common data for the freecell solver.

#include <FCSFreecellData.h>

Inheritance diagram for FCSFreecellData:

FCSFreecellSolvingAlgorithm FCSSimpleSimonSolvingAlgorithm FCSTalonSolvingAlgorithm List of all members.

Public Member Functions

virtual ~FCSFreecellData ()
 Destructor.
int GetNumberOfCheckedStates ()
 Get the number of check states in the solver.
int GetNumberOfStatesInCollection ()
 Get the number states in the solver.
void IncreaseMaxNumberOfCheckedStates ()
 Increase the max number of checked states allowed.
void CleanData ()
 Delete the current solution states to create room for an optimized solution.
virtual void ShowSolution (FCSStateWithLocations *InitStateWithLocations, FCSStateWithLocations *DupStateWithLocations)
 Show the solution, step by step.
void TraceSolution ()
 Trace the solution from the final state down to the initial state.

Protected Member Functions

 FCSFreecellData ()
 Default constructor.
void InitFCSFreecellData ()
 The "real" default constructor.
 FCSFreecellData (FCCommandLineArguments *CommandLine)
 Constructor with command line interface.
void InitSolve (FCSStateWithLocations *InitState)
 Call this to initialize members needed for solve. (Common between all children).
int GetNextMove (FCSStateWithLocations *StateWithLocations, FCSMove *Move)
 Get the next move of a SOLVED state.
FCSStateWithLocationsStatePackAlloc ()
 Allocate a state pack.
void StatePackRelease ()
 Release a state pack.
virtual FCSStateSolvingReturnCodes CheckAndAddState (FCSStateWithLocations *NewState, FCSStateWithLocations **ExistingState, int Depth)
 If the state is new state (not generated before), add it to storage.
virtual void CheckStateBegin (FCSStateWithLocations **NewStateWithLocations, FCSStateWithLocations *StateWithLocations, FCSMoveStack *Move)
 Prep a state to be added into storage.
virtual bool CheckStateEnd (FCSStateWithLocations **NewStateWithLocations, FCSStateWithLocations *StateWithLocations, FCSDerivedStatesList **DerivedStateList, FCSMoveStack **Move, FCSMove **TempMove, int Depth, FCSStateSolvingReturnCodes *ReturnCode)
 Put the last move onto the move stack for the current state.
void CreateTotalMovesStack ()
 Create a move stack of all the moves in the game.
bool IsParentCard (FCSCard *Child, FCSCard *Parent)
 is a card a parent of another?
int CalculateMaxSequenceMoves (int FreecellNumber, int FreeStackNumber)
 Calculate the maximum number of sequence moves given the number of freecells and free stacks.
void MoveSequence (FCSStateWithLocations *NewStateWithLocations, FCSCard *Card, FCSMoveStack *MoveStack, FCSMove **TempMove, int DestStack, int SourceStack, int Start, int End)
 Move a sequence of cards.

Protected Attributes

bool IsOptimizeClass
 Is child class an optimize class?
FCStateType m_StateType
 State type - Debug, Compact or Indirect.
AFCSStateWithLocationsMatrixm_StatePacks
 States used to solve the game.
int m_MaxNumberOfStatePacks
 Maximum number of state packs before more memory has to be allocated for more.
int m_NumberOfStatePacks
 Current number of state packs.
int m_NumberOfStatesInLastPack
 Number of states in the last state pack.
int m_StatePackLength
 Number of states in each pack.
int m_NumberOfCheckedStates
 Number of states that were checked by the solving algorithm.
int m_NumberOfStatesInCollection
 This is the number of states in the state collection.
int m_MaxNumberOfStatesInCollection
 A limit on the number of states in the state collection.
AFCSStateWithLocationsMatrixm_SolutionStates
 A vector of the states leading to the solution.
int m_NumberOfSolutionStates
 The number of states in m_SolutionStates.
FCSMoveStackm_SolutionMoves
 A move stack that contains the moves leading to the solution.
FCSMoveStack ** m_ProtoSolutionMoves
 m_ProtoSolutionMoves[i] are the moves that lead from m_SolutionStates[i] to m_SolutionStates[i+1].
FCSStateWithLocationsm_FinalState
 This is the final state that the scan recommends to the interface.
int m_MaxDepth
 Limits the maximal depth.
int m_MaxNumberOfCheckedStates
 Limits the maximal number of checked states.
FCSDebugDisplayInfom_DebugDisplayInfo
 m_DebugDisplayInfo provide a programmer with a programmable way to debug the algorithm while it is running.
int m_TestsOrder [FCS_TESTS_NUM]
 The tests' order indicates which tests (i.e: kinds of multi-moves) to do at what order.
int m_TestsOrderNumber
 Number of tests in the test's order.
AFCSGenericStateStoragem_StateStorage
 Used to store the previous states in a scan.
AFCSGenericStackStoragem_StackStorage
 Used to store stacks assuming Indirect Stack States are used.
int m_NumberOfFreecells
 Number of freecells present in the game.
int m_NumberOfStacks
 Number of stacks present in the game.
int m_NumberOfDecks
 Number of decks present in the game.
BuildSequenceByEnum m_SequencesAreBuiltBy
 What two adjacent cards in the same sequence can be.
bool m_IsUnlimitedSequenceMove
 Whether an entire sequence can be moved from one place to the other regardless of the number of unoccupied Freecells there are.
FCEmptyStacksFillType m_EmptyStacksFill
 With what cards can empty stacks be filled with.
bool m_OptimizeSolutionPath
 A flag that indicates whether to optimize the solution path at the end of the scan.
CompareFunctionCompareNodesAlgorithm<
FCSStateWithLocations, void > 
m_CompareFunction
 Compare function used for comparing states.
MD5StateWithLocationsHashAlgorithm m_MD5Hash
 Hash function used when storing in hash tables.
FCSIndirectCardCompareAlgorithm<
FCSIndirectCard, void > * 
m_IndirectCompare
 Compare function when storing FCSIndirectCards.
MD5HashAlgorithm< FCSIndirectCard > * m_IndirectHash
 Hash function when storing FCSIndirectCards.

Friends

class FCSOptimizeSolvingAlgorithm< FCSFreecellSolvingAlgorithm >
 added for every "optimized solving algorithm type"
class FCSOptimizeSolvingAlgorithm< FCSSimpleSimonSolvingAlgorithm >
 added for every "optimized solving algorithm type"
class FCSOptimizeSolvingAlgorithm< FCSTalonSolvingAlgorithm >
 added for every "optimized solving algorithm type"

Detailed Description

Definition at line 33 of file FCSFreecellData.h.


Member Function Documentation

int FCSFreecellData::CalculateMaxSequenceMoves int  FreecellNumber,
int  FreeStackNumber
[protected]
 

Parameters:
FreecellNumber is the number of freecells
FreeStackNumber is the number of free stacks
Returns:
The biggest sequence that can be moved

Definition at line 535 of file FCSFreecellData.cpp.

References m_EmptyStacksFill, and m_IsUnlimitedSequenceMove.

Referenced by FCSFreecellSolvingAlgorithm::MoveCardsToADifferentParent(), FCSFreecellSolvingAlgorithm::MoveSequencesToFreeStacks(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFalseParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToParentOnTheSameStack(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithJunkSequenceAboveToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithSomeCardsAboveToTrueParent(), FCSFreecellSolvingAlgorithm::MoveStackCardsToDifferentStacks(), FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParent(), and FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParentWithSomeCardsAbove().

FCSStateSolvingReturnCodes FCSFreecellData::CheckAndAddState FCSStateWithLocations NewState,
FCSStateWithLocations **  ExistingState,
int  Depth
[protected, virtual]
 

Parameters:
NewState is the state to add
ExistingState becomes the state to work with (if NewState is added, ExistingState = NewState)
Depth is the current depth of the state
Returns:
Solving return code

Reimplemented in FCSTalonSolvingAlgorithm.

Definition at line 492 of file FCSFreecellData.cpp.

References FCSStateWithLocations::CacheStacks(), FCSStateWithLocations::CanonizeState(), AFCSGenericStateStorage::CheckAndInsert(), m_MaxDepth, m_MaxNumberOfCheckedStates, m_MaxNumberOfStatesInCollection, m_NumberOfCheckedStates, m_NumberOfFreecells, m_NumberOfStacks, m_NumberOfStatesInCollection, m_StackStorage, and m_StateStorage.

Referenced by CheckStateEnd(), and InitSolve().

void FCSFreecellData::CheckStateBegin FCSStateWithLocations **  NewStateWithLocations,
FCSStateWithLocations StateWithLocations,
FCSMoveStack Move
[inline, protected, virtual]
 

Parameters:
NewStateWithLocations is the state being added to storage
StateWithLocations is the current state
Move is how to get from StateWithLocations to NewStateWithLocations
Depth is the current depth of the state

Definition at line 436 of file FCSFreecellData.cpp.

References FCSStateWithLocations::m_Depth, FCSStateWithLocations::m_MovesToParent, FCSMoveStack::Reset(), and StatePackAlloc().

Referenced by FCSFreecellSolvingAlgorithm::EmptyStackIntoFreecells(), FCSTalonSolvingAlgorithm::GetCardFromKlondikeTalon(), FCSFreecellSolvingAlgorithm::MoveCardsToADifferentParent(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToEmptyStack(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToFounds(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToTopOfStacks(), FCSFreecellSolvingAlgorithm::MoveNonTopStackCardsToFounds(), FCSFreecellSolvingAlgorithm::MoveSequencesToFreeStacks(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFalseParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFounds(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToParentOnTheSameStack(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithJunkSequenceAboveToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithSomeCardsAboveToTrueParent(), FCSFreecellSolvingAlgorithm::MoveStackCardsToAParentOnTheSameStack(), FCSFreecellSolvingAlgorithm::MoveStackCardsToDifferentStacks(), FCSFreecellSolvingAlgorithm::MoveTopStackCardsToFounds(), FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParent(), and FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParentWithSomeCardsAbove().

bool FCSFreecellData::CheckStateEnd FCSStateWithLocations **  NewStateWithLocations,
FCSStateWithLocations StateWithLocations,
FCSDerivedStatesList **  DerivedStateList,
FCSMoveStack **  Move,
FCSMove **  TempMove,
int  Depth,
FCSStateSolvingReturnCodes ReturnCode
[inline, protected, virtual]
 

Parameters:
NewStateWithLocations is the state being added to storage
StateWithLocations is the current state
DerivedStateList is the derived state list for the current state
Move is how to get from StateWithLocations to NewStateWithLocations
TempMove is the last move from StateWithLocations to NewStateWithLocations
Depth is the current depth of the state
ReturnCode determines if the test is done
Returns:
Whether or not to return the ReturnCode

Definition at line 451 of file FCSFreecellData.cpp.

References CheckAndAddState(), CreateMoveStack(), and StatePackRelease().

Referenced by FCSFreecellSolvingAlgorithm::EmptyStackIntoFreecells(), FCSTalonSolvingAlgorithm::GetCardFromKlondikeTalon(), FCSFreecellSolvingAlgorithm::MoveCardsToADifferentParent(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToEmptyStack(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToFounds(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToTopOfStacks(), FCSFreecellSolvingAlgorithm::MoveNonTopStackCardsToFounds(), FCSFreecellSolvingAlgorithm::MoveSequencesToFreeStacks(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFalseParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFounds(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToParentOnTheSameStack(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithJunkSequenceAboveToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithSomeCardsAboveToTrueParent(), FCSFreecellSolvingAlgorithm::MoveStackCardsToAParentOnTheSameStack(), FCSFreecellSolvingAlgorithm::MoveStackCardsToDifferentStacks(), FCSFreecellSolvingAlgorithm::MoveTopStackCardsToFounds(), FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParent(), and FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParentWithSomeCardsAbove().

int FCSFreecellData::GetNextMove FCSStateWithLocations StateWithLocations,
FCSMove Move
[protected]
 

Parameters:
StateWithLocations is the state to get the moves from
Move is the move returned
Returns:
0 if there is another move, Nonzero if no more moves

Definition at line 374 of file FCSFreecellData.cpp.

References ApplyMove(), m_NumberOfDecks, m_NumberOfFreecells, m_NumberOfStacks, m_SolutionMoves, and FCSMoveStack::Pop().

Referenced by ShowSolution().

int FCSFreecellData::GetNumberOfCheckedStates  ) 
 

Returns:
Number of checked states

Definition at line 359 of file FCSFreecellData.cpp.

References m_NumberOfCheckedStates.

Referenced by MainStats().

int FCSFreecellData::GetNumberOfStatesInCollection  ) 
 

Returns:
Number of states

Definition at line 364 of file FCSFreecellData.cpp.

References m_NumberOfStatesInCollection.

Referenced by MainStats().

void FCSFreecellData::InitSolve FCSStateWithLocations InitState  )  [protected]
 

Parameters:
InitState is the start state of the game

Reimplemented in FCSTalonSolvingAlgorithm.

Definition at line 225 of file FCSFreecellData.cpp.

References CheckAndAddState().

Referenced by FCSTalonSolvingAlgorithm::InitSolve().

bool FCSFreecellData::IsParentCard FCSCard Child,
FCSCard Parent
[protected]
 

Parameters:
Child is the child card
Parent is the possible parent card
Returns:
Whether or not a parent relationship exists

Definition at line 523 of file FCSFreecellData.cpp.

References FCSCard::GetCardNumber(), FCSCard::GetSuit(), and m_SequencesAreBuiltBy.

Referenced by FCSTalonSolvingAlgorithm::GetCardFromKlondikeTalon(), FCSFreecellSolvingAlgorithm::MoveCardsToADifferentParent(), FCSFreecellSolvingAlgorithm::MoveFreecellCardsToTopOfStacks(), FCSFreecellSolvingAlgorithm::MoveSequencesToFreeStacks(), FCSFreecellSolvingAlgorithm::MoveStackCardsToAParentOnTheSameStack(), and FCSFreecellSolvingAlgorithm::MoveStackCardsToDifferentStacks().

void FCSFreecellData::MoveSequence FCSStateWithLocations NewStateWithLocations,
FCSCard Card,
FCSMoveStack MoveStack,
FCSMove **  TempMove,
int  DestStack,
int  SourceStack,
int  Start,
int  End
[protected]
 

Parameters:
NewStateWithLocations is the state the cards will move to
Card is the starting card in the sequence
MoveStack is the move stack for the state
Move is the move of the sequence
DestStack is the destination stack of the sequence
SourceStack is the source stack of the sequence
Start is the start height of the stack
End is the end height of the stack

Definition at line 546 of file FCSFreecellData.cpp.

References FCSStateWithLocations::PopStackCard(), FCSMoveStack::Push(), and FCSStateWithLocations::PushStackCardIntoStack().

Referenced by FCSSimpleSimonSolvingAlgorithm::MoveSequenceToFalseParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToParentOnTheSameStack(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParent(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithJunkSequenceAboveToTrueParentWithSomeCardsAbove(), FCSSimpleSimonSolvingAlgorithm::MoveSequenceWithSomeCardsAboveToTrueParent(), FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParent(), and FCSSimpleSimonSolvingAlgorithm::MoveWholeStackSequenceToFalseParentWithSomeCardsAbove().

void FCSFreecellData::ShowSolution FCSStateWithLocations InitStateWithLocations,
FCSStateWithLocations DupStateWithLocations
[virtual]
 

Parameters:
InitStateWithLocations is the start state of the game
DupStateWithLocations is a copy of the start state because it will get modified

Definition at line 250 of file FCSFreecellData.cpp.

References FCSStateWithLocations::CleanState(), FCSMove::Create(), CreateTotalMovesStack(), DEBUG_DISPLAY_MOVES, DEBUG_DISPLAY_STATES, DEBUG_USE_STANDARD_NOTATION, AFCSStateWithLocationsMatrix::Delete(), AFCSStateWithLocationsMatrix::Get(), GetNextMove(), m_DebugDisplayInfo, FCSDebugDisplayInfo::m_DisplayDebugOptions, m_NumberOfDecks, m_NumberOfFreecells, m_NumberOfSolutionStates, m_NumberOfStacks, m_SolutionMoves, m_SolutionStates, FCSMove::MoveAsString(), FCSMove::MoveAsStringStandardNotation(), FCSMoveStack::Normalize(), and FCSStateWithLocations::StateAsString().

Referenced by MainSolution().


Member Data Documentation

int FCSFreecellData::m_MaxDepth [protected]
 

m_MaxDepth is quite dangerous because it blocks some intermediate moves and doesn't allow a program to fully reach its solution.

Definition at line 154 of file FCSFreecellData.h.

Referenced by FCSTalonSolvingAlgorithm::CheckAndAddState(), CheckAndAddState(), FCSFreecellData(), and InitFCSFreecellData().

int FCSFreecellData::m_MaxNumberOfCheckedStates [protected]
 

m_MaxNumberOfCheckedStates is useful because it enables the process to stop before it consumes too much memory.

Definition at line 160 of file FCSFreecellData.h.

Referenced by FCSTalonSolvingAlgorithm::CheckAndAddState(), CheckAndAddState(), FCSFreecellData(), IncreaseMaxNumberOfCheckedStates(), and InitFCSFreecellData().

int FCSFreecellData::m_NumberOfStatesInCollection [protected]
 

It gives a rough estimate of the memory occupied by the instance.

Definition at line 126 of file FCSFreecellData.h.

Referenced by FCSTalonSolvingAlgorithm::CheckAndAddState(), CheckAndAddState(), GetNumberOfStatesInCollection(), and InitFCSFreecellData().

FCSMoveStack* FCSFreecellData::m_SolutionMoves [protected]
 

It is created only after the solution was found by swallowing all the stacks of each depth.

Definition at line 141 of file FCSFreecellData.h.

Referenced by CreateTotalMovesStack(), GetNextMove(), InitFCSFreecellData(), ShowSolution(), and ~FCSFreecellData().

AFCSStateWithLocationsMatrix* FCSFreecellData::m_StatePacks [protected]
 

The State Packs variables are used by all the state cache management routines. A pack stores as many states as can fit in a 64KB segment, and those variables manage an array of such packs.
Such allocation is possible, because at the worst situation the last state is released.

Definition at line 106 of file FCSFreecellData.h.

Referenced by FCSFreecellData(), InitFCSFreecellData(), StatePackAlloc(), and ~FCSFreecellData().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 11:20:17 2005 for Cpp Freecell Solver by  doxygen 1.4.4