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     */
00028     void AssertRestored();
00029 
00030     void Init(const GoBoard& bd);
00031 
00032     /** Set to a state, in which the destructor does not call
00033         AssertRestored() anymore.
00034     */
00035     void Clear();
00036 
00037 private:
00038 #ifndef NDEBUG
00039     const GoBoard* m_bd;
00040 
00041     int m_size;
00042 
00043     SgBlackWhite m_toPlay;
00044 
00045     /** Hash code for this board position. */
00046     SgHashCode m_hash;
00047 
00048     /** Current move number. */
00049     int m_moveNumber;
00050 
00051     SgBWArray<int> m_numStones;
00052 
00053     GoRules m_rules;
00054 
00055     bool m_allowKoRepetition;
00056 
00057     bool m_allowAnyRepetition;
00058 
00059     bool m_koModifiesHash;
00060 
00061     SgEmptyBlackWhite m_koColor;
00062 
00063     int m_koLevel;
00064 
00065     SgEmptyBlackWhite m_koLoser;
00066 #endif // NDEBUG
00067 
00068     /** Not implemented. */
00069     GoAssertBoardRestored(const GoAssertBoardRestored&);
00070 
00071     /** Not implemented. */
00072     GoAssertBoardRestored& operator=(const GoAssertBoardRestored&);
00073 };
00074 
00075 inline GoAssertBoardRestored::GoAssertBoardRestored()
00076 {
00077 #ifndef NDEBUG
00078     m_bd = 0;
00079 #endif
00080 }
00081 
00082 inline GoAssertBoardRestored::GoAssertBoardRestored(const GoBoard& bd)
00083 {
00084     SG_DEBUG_ONLY(bd);
00085 #ifndef NDEBUG
00086     Init(bd);
00087 #endif
00088 }
00089 
00090 inline GoAssertBoardRestored::~GoAssertBoardRestored()
00091 {
00092 #ifndef NDEBUG
00093     AssertRestored();
00094 #endif
00095 }
00096 
00097 inline void GoAssertBoardRestored::AssertRestored()
00098 {
00099 #ifndef NDEBUG
00100     if (m_bd == 0)
00101         return;
00102     SG_ASSERT(m_bd->Size() == m_size);
00103     SG_ASSERT(m_bd->ToPlay() == m_toPlay);
00104     SG_ASSERT(m_bd->GetHashCode() == m_hash);
00105     SG_ASSERT(m_bd->MoveNumber() == m_moveNumber);
00106     SG_ASSERT(m_bd->TotalNumStones(SG_BLACK) == m_numStones[SG_BLACK]);
00107     SG_ASSERT(m_bd->TotalNumStones(SG_WHITE) == m_numStones[SG_WHITE]);
00108     SG_ASSERT(m_bd->Rules() == m_rules);
00109     SG_ASSERT(m_bd->KoRepetitionAllowed() == m_allowKoRepetition);
00110     SG_ASSERT(m_bd->AnyRepetitionAllowed() == m_allowAnyRepetition);
00111     SG_ASSERT(m_bd->KoModifiesHash() == m_koModifiesHash);
00112     SG_ASSERT(m_bd->KoColor() == m_koColor);
00113     SG_ASSERT(m_bd->KoLevel() == m_koLevel);
00114     SG_ASSERT(m_bd->KoLoser() == m_koLoser);
00115 #endif
00116 }
00117 
00118 inline void GoAssertBoardRestored::Clear()
00119 {
00120 #ifndef NDEBUG
00121     m_bd = 0;
00122 #endif
00123 }
00124 
00125 inline void GoAssertBoardRestored::Init(const GoBoard& bd)
00126 {
00127     SG_DEBUG_ONLY(bd);
00128 #ifndef NDEBUG
00129     m_bd = &bd;
00130     m_size = bd.Size();
00131     m_toPlay = bd.ToPlay();
00132     m_hash = bd.GetHashCode();
00133     m_moveNumber = bd.MoveNumber();
00134     m_numStones = bd.TotalNumStones();
00135     m_rules = bd.Rules();
00136     m_allowKoRepetition = bd.KoRepetitionAllowed();
00137     m_allowAnyRepetition = bd.AnyRepetitionAllowed();
00138     m_koModifiesHash = bd.KoModifiesHash();
00139     m_koColor = bd.KoColor();
00140     m_koLevel = bd.KoLevel();
00141     m_koLoser = bd.KoLoser();
00142 #endif
00143 }
00144 
00145 //----------------------------------------------------------------------------
00146 
00147 #endif // GO_ASSERTBOARDRESTORED_H


17 Jun 2010 Doxygen 1.4.7