Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoAssertBoardRestored.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file GoAssertBoardRestored.h */
00003 //----------------------------------------------------------------------------
00004 
00005 #ifndef GO_ASSERTBOARDRESTORED_H
00006 #define GO_ASSERTBOARDRESTORED_H
00007 
00008 #include "GoBoard.h"
00009 
00010 //----------------------------------------------------------------------------
00011 
00012 /** Assert that the board has been restored to previous state. */
00013 class GoAssertBoardRestored
00014 {
00015 public:
00016     /** Constructor for later explicit call of Init() */
00017     GoAssertBoardRestored();
00018 
00019     /** Constructor, calls Init(). */
00020     GoAssertBoardRestored(const GoBoard& bd);
00021 
00022     /** Destructor, calls CheckRestored(). */
00023     ~GoAssertBoardRestored();
00024 
00025     /** Checks with assertions that the state of the board is the same
00026         as it was at the last call to Init() or the constructor. */
00027     void AssertRestored();
00028 
00029     void Init(const GoBoard& bd);
00030 
00031     /** Set to a state, in which the destructor does not call
00032         AssertRestored() anymore. */
00033     void Clear();
00034 
00035 private:
00036 #ifndef NDEBUG
00037     const GoBoard* m_bd;
00038 
00039     int m_size;
00040 
00041     SgBlackWhite m_toPlay;
00042 
00043     /** Hash code for this board position. */
00044     SgHashCode m_hash;
00045 
00046     /** Current move number. */
00047     int m_moveNumber;
00048 
00049     SgBWArray<int> m_numStones;
00050 
00051     GoRules m_rules;
00052 
00053     bool m_allowKoRepetition;
00054 
00055     bool m_allowAnyRepetition;
00056 
00057     bool m_koModifiesHash;
00058 
00059     SgEmptyBlackWhite m_koColor;
00060 
00061     int m_koLevel;
00062 
00063     SgEmptyBlackWhite m_koLoser;
00064 #endif // NDEBUG
00065 
00066     /** Not implemented. */
00067     GoAssertBoardRestored(const GoAssertBoardRestored&);
00068 
00069     /** Not implemented. */
00070     GoAssertBoardRestored& operator=(const GoAssertBoardRestored&);
00071 };
00072 
00073 inline GoAssertBoardRestored::GoAssertBoardRestored()
00074 {
00075 #ifndef NDEBUG
00076     m_bd = 0;
00077 #endif
00078 }
00079 
00080 inline GoAssertBoardRestored::GoAssertBoardRestored(const GoBoard& bd)
00081 {
00082     SG_DEBUG_ONLY(bd);
00083 #ifndef NDEBUG
00084     Init(bd);
00085 #endif
00086 }
00087 
00088 inline GoAssertBoardRestored::~GoAssertBoardRestored()
00089 {
00090 #ifndef NDEBUG
00091     AssertRestored();
00092 #endif
00093 }
00094 
00095 inline void GoAssertBoardRestored::AssertRestored()
00096 {
00097 #ifndef NDEBUG
00098     if (m_bd == 0)
00099         return;
00100     SG_ASSERT(m_bd->Size() == m_size);
00101     SG_ASSERT(m_bd->ToPlay() == m_toPlay);
00102     SG_ASSERT(m_bd->GetHashCode() == m_hash);
00103     SG_ASSERT(m_bd->MoveNumber() == m_moveNumber);
00104     SG_ASSERT(m_bd->TotalNumStones(SG_BLACK) == m_numStones[SG_BLACK]);
00105     SG_ASSERT(m_bd->TotalNumStones(SG_WHITE) == m_numStones[SG_WHITE]);
00106     SG_ASSERT(m_bd->Rules() == m_rules);
00107     SG_ASSERT(m_bd->KoRepetitionAllowed() == m_allowKoRepetition);
00108     SG_ASSERT(m_bd->AnyRepetitionAllowed() == m_allowAnyRepetition);
00109     SG_ASSERT(m_bd->KoModifiesHash() == m_koModifiesHash);
00110     SG_ASSERT(m_bd->KoColor() == m_koColor);
00111     SG_ASSERT(m_bd->KoLevel() == m_koLevel);
00112     SG_ASSERT(m_bd->KoLoser() == m_koLoser);
00113 #endif
00114 }
00115 
00116 inline void GoAssertBoardRestored::Clear()
00117 {
00118 #ifndef NDEBUG
00119     m_bd = 0;
00120 #endif
00121 }
00122 
00123 inline void GoAssertBoardRestored::Init(const GoBoard& bd)
00124 {
00125     SG_DEBUG_ONLY(bd);
00126 #ifndef NDEBUG
00127     m_bd = &bd;
00128     m_size = bd.Size();
00129     m_toPlay = bd.ToPlay();
00130     m_hash = bd.GetHashCode();
00131     m_moveNumber = bd.MoveNumber();
00132     m_numStones = bd.TotalNumStones();
00133     m_rules = bd.Rules();
00134     m_allowKoRepetition = bd.KoRepetitionAllowed();
00135     m_allowAnyRepetition = bd.AnyRepetitionAllowed();
00136     m_koModifiesHash = bd.KoModifiesHash();
00137     m_koColor = bd.KoColor();
00138     m_koLevel = bd.KoLevel();
00139     m_koLoser = bd.KoLoser();
00140 #endif
00141 }
00142 
00143 //----------------------------------------------------------------------------
00144 
00145 #endif // GO_ASSERTBOARDRESTORED_H


Sun Mar 13 2011 Doxygen 1.7.1