00001 00002 00003 00004 00005 00006 00007 00008 00009 #include "FCSCompactMove.h" 00010 #include "FCHelpingAlgorithms.h" 00011 00012 FCSCompactMove::FCSCompactMove() : FCSMove() 00013 { 00014 memset(m_Data, 0, sizeof(char)*4); 00015 } 00016 00017 FCSCompactMove::~FCSCompactMove() 00018 { 00019 } 00020 00021 void FCSCompactMove::Copy(FCSMove* Move) 00022 { 00023 memcpy(m_Data, ((FCSCompactMove*)Move)->m_Data, sizeof(((FCSCompactMove*)Move)->m_Data)); 00024 } 00025 00026 unsigned char FCSCompactMove::GetSourceStack() 00027 { 00028 return m_Data[FCS_MOVE_SRC]; 00029 } 00030 00031 unsigned char FCSCompactMove::GetSourceFreecell() 00032 { 00033 return m_Data[FCS_MOVE_SRC]; 00034 } 00035 00036 unsigned char FCSCompactMove::GetDestStack() 00037 { 00038 return m_Data[FCS_MOVE_DEST]; 00039 } 00040 00041 unsigned char FCSCompactMove::GetDestFreecell() 00042 { 00043 return m_Data[FCS_MOVE_DEST]; 00044 } 00045 00046 unsigned char FCSCompactMove::GetFoundation() 00047 { 00048 return m_Data[FCS_MOVE_DEST]; 00049 } 00050 00051 FCSMoveTypes FCSCompactMove::GetType() 00052 { 00053 return (FCSMoveTypes)m_Data[FCS_MOVE_TYPE]; 00054 } 00055 00056 unsigned char FCSCompactMove::GetNumberOfCardsInSequence() 00057 { 00058 return m_Data[FCS_MOVE_NUM_CARDS_IN_SEQ]; 00059 } 00060 00061 unsigned char FCSCompactMove::GetNumberOfCardsFlipped() 00062 { 00063 return m_Data[FCS_MOVE_NUM_CARDS_FLIPPED]; 00064 } 00065 00066 void FCSCompactMove::SetSourceStack(unsigned char Value) 00067 { 00068 m_Data[FCS_MOVE_SRC] = Value; 00069 } 00070 00071 void FCSCompactMove::SetSourceFreecell(unsigned char Value) 00072 { 00073 m_Data[FCS_MOVE_SRC] = Value; 00074 } 00075 00076 void FCSCompactMove::SetDestStack(unsigned char Value) 00077 { 00078 m_Data[FCS_MOVE_DEST] = Value; 00079 } 00080 00081 void FCSCompactMove::SetDestFreecell(unsigned char Value) 00082 { 00083 m_Data[FCS_MOVE_DEST] = Value; 00084 } 00085 00086 void FCSCompactMove::SetFoundation(unsigned char Value) 00087 { 00088 m_Data[FCS_MOVE_DEST] = Value; 00089 } 00090 00091 void FCSCompactMove::SetType(FCSMoveTypes Value) 00092 { 00093 m_Data[FCS_MOVE_TYPE] = Value; 00094 } 00095 00096 void FCSCompactMove::SetNumberOfCardsInSequence(unsigned char Value) 00097 { 00098 m_Data[FCS_MOVE_NUM_CARDS_IN_SEQ] = Value; 00099 } 00100 00101 void FCSCompactMove::SetNumberOfCardsFlipped(unsigned char Value) 00102 { 00103 m_Data[FCS_MOVE_NUM_CARDS_FLIPPED] = Value; 00104 } 00105 00106 00107 FCSCompactMoveStack::FCSCompactMoveStack() : FCSMoveStack() 00108 { 00109 m_Moves = new FCSCompactMove[m_MaxNumberOfMoves]; 00110 } 00111 00112 FCSCompactMoveStack::~FCSCompactMoveStack() 00113 { 00114 delete [] m_Moves; 00115 } 00116 00117 FCSMoveStack* FCSCompactMoveStack::Copy() 00118 { 00119 FCSCompactMoveStack* ReturnStack = new FCSCompactMoveStack(); 00120 00121 ReturnStack->m_MaxNumberOfMoves = m_MaxNumberOfMoves; 00122 ReturnStack->m_NumberOfMoves = m_NumberOfMoves; 00123 for (int a =0;a<m_MaxNumberOfMoves;a++) 00124 ReturnStack->m_Moves[a].Copy(&(m_Moves[a])); 00125 00126 return ReturnStack; 00127 } 00128 00129 void FCSCompactMoveStack::Push(FCSMove* Move) 00130 { 00131 // If all the moves inside the stack are taken then resize the move vector 00132 if (m_NumberOfMoves == m_MaxNumberOfMoves) 00133 { 00134 m_MaxNumberOfMoves += max((m_MaxNumberOfMoves >> 3), FCS_MOVE_STACK_GROW_BY); 00135 Realloc<FCSCompactMove>(&m_Moves, m_NumberOfMoves, m_MaxNumberOfMoves); 00136 } 00137 00138 m_Moves[m_NumberOfMoves++].Copy(Move); 00139 } 00140 00141 int FCSCompactMoveStack::Pop(FCSMove** Move) 00142 { 00143 if (m_NumberOfMoves > 0) 00144 { 00145 (*Move)->Copy(&(m_Moves[--m_NumberOfMoves])); 00146 return 0; 00147 } 00148 else 00149 { 00150 return 1; 00151 } 00152 }