00001 //---------------------------------------------------------------------------- 00002 /** @file SgIncrementalStack.h 00003 Incremental Update Stack for fast undo during search. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #ifndef SG_INCREMENTALSTACK_H 00008 #define SG_INCREMENTALSTACK_H 00009 00010 #include "SgBoardColor.h" 00011 #include "SgVector.h" 00012 #include "SgPoint.h" 00013 00014 class SgPointSet; 00015 class SgBWSet; 00016 00017 //---------------------------------------------------------------------------- 00018 00019 /** constants for types of stack entries */ 00020 enum SgIncrementalStackEvent 00021 { 00022 SG_NEW_POINTS = 1000, 00023 SG_ADD_EMPTY = 1001, 00024 SG_NEW_SAFE = 1002, 00025 SG_NEW_UNSAFE = 1003, 00026 SG_UNSAFE_TO_SAFE = 1004, 00027 SG_CAPTURES = 1005, 00028 SG_INCREMENTAL_MOVE = 1006, 00029 SG_NEXTMOVE = 1007, 00030 SG_UNSAFE_TO_HALF_SAFE = 1008, 00031 SG_CAPTURE_HALF_SAFE = 1009 00032 }; 00033 00034 /** Incremental Update Stack for fast undo during search. 00035 Used by GoRegionBoard. 00036 */ 00037 class SgIncrementalStack 00038 { 00039 public: 00040 SgIncrementalStack(){} 00041 00042 void Clear(); 00043 00044 bool IsEmpty() const {return m_stack.IsEmpty();} 00045 00046 void PushPts(int type, SgEmptyBlackWhite col, const SgPointSet& pts); 00047 00048 void PushPt(int type, SgEmptyBlackWhite col, SgPoint pt); 00049 00050 void PushPtr(void* ptr) 00051 { 00052 m_stack.PushBack(IntOrPtr(ptr)); 00053 } 00054 00055 void PushPtrEvent(int type, void* ptr); 00056 00057 void PushInt(int i) 00058 { 00059 m_stack.PushBack(IntOrPtr(i)); 00060 } 00061 00062 /** relies on SgPoint == int; add to union if that changes */ 00063 void PushPoint(SgPoint p) 00064 { 00065 m_stack.PushBack(IntOrPtr(p)); 00066 } 00067 00068 void StartMoveInfo(); 00069 00070 SgIncrementalStackEvent PopEvent() 00071 { 00072 return static_cast<SgIncrementalStackEvent>(PopInt()); 00073 } 00074 00075 void* PopPtr() 00076 { 00077 void* p = m_stack.Back().m_ptr; 00078 m_stack.PopBack(); 00079 return p; 00080 } 00081 00082 int PopInt() 00083 { 00084 int i = m_stack.Back().m_int; 00085 m_stack.PopBack(); 00086 return i; 00087 } 00088 00089 /** relies on SgPoint == int; add to union if that changes */ 00090 SgPoint PopPoint() 00091 { 00092 return PopInt(); 00093 } 00094 00095 void SubtractPoints(SgPointSet* set); 00096 00097 void AddPoints(SgPointSet* set); 00098 00099 void SubtractPoints(SgBWSet* set); 00100 00101 void AddPoints(SgBWSet* set); 00102 00103 void SubtractAndAddPoints(SgBWSet* subtractset, SgBWSet* addset); 00104 00105 void SubtractAndAddPoints(SgPointSet* subtractset, SgBWSet* addset); 00106 00107 void SubtractAndAddPoints(SgBWSet* subtractset, SgPointSet* addset); 00108 00109 private: 00110 /** Entry for SgIncrementalStack */ 00111 union IntOrPtr 00112 { 00113 IntOrPtr() 00114 { 00115 } 00116 00117 IntOrPtr(int i) 00118 { 00119 m_int = i; 00120 } 00121 00122 IntOrPtr(void* ptr) 00123 { 00124 m_ptr = ptr; 00125 } 00126 00127 int m_int; 00128 00129 void* m_ptr; 00130 }; 00131 00132 /** Stores incremental state changes for execute/undo moves */ 00133 SgVector<IntOrPtr> m_stack; 00134 }; 00135 00136 //---------------------------------------------------------------------------- 00137 00138 #endif // SG_INCREMENTALSTACK_H