Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

VCPattern.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file VCPattern.hpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef VC_PATTERN_HPP
00007 #define VC_PATTERN_HPP
00008 
00009 #include "Hex.hpp"
00010 #include "StoneBoard.hpp"
00011 
00012 _BEGIN_BENZENE_NAMESPACE_
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 class VCPattern;
00017 
00018 typedef std::vector<VCPattern> VCPatternSet;
00019 
00020 //----------------------------------------------------------------------------
00021 
00022 /** Precomputed pattern specifying a virtual connection/ladder. */
00023 class VCPattern
00024 {        
00025 public: 
00026 
00027     VCPattern(HexPoint end1, HexPoint end2, const bitset_t& must_have, 
00028               const bitset_t& not_oppt);
00029 
00030     ~VCPattern();
00031 
00032     /** Returns the set of patterns for the given boardsize; creates
00033         patterns if they currently do not exist. Return set of
00034         patterns will always be empty if width does not equal
00035         height. */
00036     static const VCPatternSet& GetPatterns(int width, int height, 
00037                                            HexColor color);
00038 
00039 
00040     /** Returns cells that this player must have. */
00041     bitset_t MustHave() const;
00042 
00043     /** Returns cells that must not be opponent stones. */
00044     bitset_t NotOpponent() const;
00045 
00046     /** Returns the endpoints, i must be in [0, 1]. */
00047     HexPoint Endpoint(int i) const;
00048 
00049     /** Returns true if this pattern matches the given board. */
00050     bool Matches(HexColor color, const StoneBoard& brd) const;
00051 
00052     /** Shifts the pattern in direction dir, if possible. Returns true
00053         on success, false if shifted pattern goes off board. 
00054         ONLY USE THIS IF YOU KNOW WHAT YOU ARE DOING!
00055     */
00056     bool ShiftPattern(HexDirection dir, const StoneBoard& brd);
00057 
00058 private:
00059 
00060     /** Cells that must be occupied. */
00061     bitset_t m_must_have;
00062 
00063     /** Cells that cannot be opponent stones. */
00064     bitset_t m_not_oppt;
00065 
00066     /** Endpoints connected by this VC. */
00067     HexPoint m_end1, m_end2;
00068 
00069     //------------------------------------------------------------------------
00070 
00071     typedef std::map< std::pair<int, int>, VCPatternSet > VCPatternSetMap;
00072     struct GlobalData
00073     {
00074         VCPatternSetMap constructed[BLACK_AND_WHITE];
00075     };
00076 
00077     /** Returns the set of PatternSets already constructed. */
00078     static VCPatternSetMap& GetConstructed(HexColor color);
00079 
00080     /** Creates the patterns for a given boardsize. */
00081     static void CreatePatterns(int width, int height);
00082 };
00083 
00084 inline bitset_t VCPattern::MustHave() const
00085 {
00086     return m_must_have;
00087 }
00088 
00089 inline bitset_t VCPattern::NotOpponent() const
00090 {
00091     return m_not_oppt;
00092 }
00093 
00094 inline HexPoint VCPattern::Endpoint(int i) const
00095 {
00096     HexAssert(0 <= i && i <= 1);
00097     if (i == 0) return m_end1;
00098     return m_end2;
00099 }
00100 
00101 //----------------------------------------------------------------------------
00102 
00103 _END_BENZENE_NAMESPACE_
00104 
00105 #endif // VC_PATTERN_HPP


6 Jan 2011 Doxygen 1.6.3