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


17 Jun 2010 Doxygen 1.4.7