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

FCSIndirectStateCompareAlgorithm.h

Go to the documentation of this file.
00001 #ifndef FCS_INDIRECT_STATE_COMPARE_ALGORITHM_H
00002 #define FCS_INDIRECT_STATE_COMPARE_ALGORITHM_H
00003 
00011 
00012 #include "CompareAlgorithms.h"
00013 
00019 template <class Data, class ConfigData>
00020 class FCSIndirectCardCompareAlgorithm : public ACompareNodesAlgorithm<Data, ConfigData>
00021 {
00022 public:
00028     virtual int Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData);
00029 };
00030 
00031 template <class Data, class ConfigData>
00032 int FCSIndirectCardCompareAlgorithm<Data, ConfigData>::Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData)
00033 {
00034     FCSIndirectCard* Card1 = (FCSIndirectCard*)Node1;
00035     FCSIndirectCard* Card2 = (FCSIndirectCard*)Node2;
00036     FCSIndirectCard *Temp1, *Temp2;
00037 
00038     int MinimumLength = min(Card1->m_Card, Card2->m_Card),
00039         ReturnValue;
00040 
00041     for(int a=0;a<MinimumLength;a++)
00042     {
00043         Temp1 = &Card1[a+1] /*+ a + 1*/;
00044         Temp2 = &Card2[a+1] /*+ a + 1*/;
00045 
00046         if ((ReturnValue = Temp1->Compare(Temp2)) != 0)
00047             return ReturnValue;
00048     }
00049     /*
00050      * The reason I do the stack length comparisons after the card-by-card
00051      * comparison is to maintain correspondence with 
00052      * StackSortCompare, and with the one card comparison
00053      * of the other state representation mechanisms.
00054      * */
00055     return Card1->Compare(Card2);
00056 }
00057 
00062 template <class Data>
00063 class FCSIndirectStatesCompareAlgorithm : public ACompareNodesAlgorithm<Data, void>
00064 {
00065 public:
00066 
00072     virtual int Compare(const Data* Node1, const Data* Node2, const void* TConfigData);
00073 };
00074 
00075 template <class Data>
00076 int FCSIndirectStatesCompareAlgorithm<Data>::Compare(const Data* Node1, const Data* Node2, const void* TConfigData)
00077 {
00078     if (((*Node1) == NULL) && ((*Node2) == NULL))
00079         return 0;
00080 
00081     if ((*Node2) == NULL)
00082         return 1;
00083 
00084     if ((*Node1) == NULL)
00085         return -1;
00086 
00087     return (*Node1)->Compare(*Node2);
00088 }
00089 
00090 #endif

Generated on Sat Nov 5 11:20:15 2005 for Cpp Freecell Solver by  doxygen 1.4.4