Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoSafetySolver.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file GoSafetySolver.h
00003     Recognize safe territories using 1-vital and 2-vital definitions
00004     under alternating play
00005     from Martin Mueller's thesis [Mueller 95, p. 62-63] 
00006     and from [Mueller 97b]. */
00007 //----------------------------------------------------------------------------
00008 
00009 #ifndef GO_SAFETYSOLVER_H
00010 #define GO_SAFETYSOLVER_H
00011 
00012 #include "GoStaticSafetySolver.h"
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 /** Improved static detection of safe blocks and regions
00017     Uses static rules to find 1-vital, 2-vital and safely surrounded areas. */
00018 class GoSafetySolver : public GoStaticSafetySolver
00019 {
00020 public:
00021     /** Constructor, @see GoStaticSafetySolver */
00022     explicit GoSafetySolver(GoBoard& board, GoRegionBoard* regions = 0) 
00023              : GoStaticSafetySolver(board, regions)
00024     {
00025         m_code.Invalidate();
00026     }
00027 
00028     /** Main function, compute safe points */
00029     void FindSafePoints(SgBWSet* safe);
00030 
00031     /** Find areas surrounded by safe blocks where the opponent cannot live */
00032     virtual void FindSurroundedSafeAreas(SgBWSet* safe, SgBlackWhite color);
00033 
00034     /** call virtual RegionHealthyForBlock */
00035     virtual void FindHealthy();
00036 
00037     /** Check if internal state matches board */
00038     virtual bool UpToDate() const
00039     {
00040         return    GoStaticSafetySolver::UpToDate() 
00041                && m_code == Board().GetHashCode();
00042     }
00043 
00044 protected:  
00045 
00046     /** See GoStaticSafetySolver::RegionHealthyForBlock.
00047         This implementation uses 1-vital information */
00048     virtual bool RegionHealthyForBlock(const GoRegion& r,
00049                                        const GoBlock& b) const;
00050 
00051     /** Compute all GoBlock's, GoChain's and GoRegion's on m_board */
00052     virtual void GenBlocksRegions();
00053 
00054     /** Like @see GoStaticSafetySolver::FindClosure, but uses GoChain's */
00055     virtual void FindClosure(SgVectorOf<GoBlock>* blocks) const;
00056 
00057     /** Like @see GoStaticSafetySolver::FindTestSets, but uses GoChain's */
00058     virtual void FindTestSets(SgVectorOf<SgVectorOf<GoBlock> >* sets,
00059                               SgBlackWhite color) const;
00060 
00061     /** static test if r is 2-vital. If yes add to safe set */
00062     virtual void Test2Vital(GoRegion* r, SgBWSet* safe);
00063 
00064     /** call Test2Vital for regions, add  2-vital ones to safe set */
00065     void Find2VitalAreas(SgBWSet* safe);
00066 
00067     /** try to find a safe pair of regions r1 + other, call AddToSafe() */
00068     bool FindSafePair(SgBWSet* safe,
00069                       SgBlackWhite color,
00070                       const SgPointSet& anySafe,
00071                       const GoRegion* r1);
00072 
00073      /** create new chain representing both chains connected in this region */
00074     void Merge(GoChain* c1, GoChain* c2, GoRegion* r, bool bySearch);
00075 
00076 private:
00077     /** find pairs of regions that are safe together. */
00078     bool FindSurroundedRegionPair(SgBWSet* safe, SgBlackWhite color);
00079 
00080     /** Find new safe region */
00081     bool FindSurroundedSingleRegion(SgBWSet* safe, SgBlackWhite color);
00082     
00083     /** for chain info */
00084     SgHashCode m_code;
00085 };
00086 
00087 //----------------------------------------------------------------------------
00088 
00089 #endif // GO_SAFETYSOLVER_H


Sun Mar 13 2011 Doxygen 1.7.1