00001 //---------------------------------------------------------------------------- 00002 /** @file VCUtils.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "VCUtils.hpp" 00007 #include "VCSet.hpp" 00008 #include "HexBoard.hpp" 00009 #include "BoardUtils.hpp" 00010 00011 using namespace benzene; 00012 00013 //---------------------------------------------------------------------------- 00014 00015 bitset_t VCUtils::GetMustplay(const HexBoard& brd, HexColor color) 00016 { 00017 HexColor other = !color; 00018 HexPoint edge1 = HexPointUtil::colorEdge1(other); 00019 HexPoint edge2 = HexPointUtil::colorEdge2(other); 00020 00021 if (brd.Cons(other).Exists(edge1, edge2, VC::FULL)) 00022 return EMPTY_BITSET; 00023 00024 const VCList& semi = brd.Cons(other).GetList(VC::SEMI, edge1, edge2); 00025 bitset_t intersection = semi.hardIntersection(); 00026 intersection &= brd.GetPosition().GetEmpty(); // FIXME: need this line? 00027 00028 return intersection; 00029 } 00030 00031 //---------------------------------------------------------------------------- 00032 00033 /** Number of cells in a MIAI (bridge). 00034 @note Should always be 2! */ 00035 #define MIAI_SIZE 2 00036 00037 //---------------------------------------------------------------------------- 00038 00039 bool VCUtils::ValidEdgeBridge(const StoneBoard& brd, 00040 const bitset_t& carrier, 00041 HexPoint& endpoint, 00042 HexPoint& edge) 00043 { 00044 // must have carrier of size two 00045 if (carrier.count() != MIAI_SIZE) return false; 00046 00047 // the carrier must be of empty cells 00048 if ((brd.GetOccupied() & carrier).any()) return false; 00049 00050 // find the two cells in the VC's carrier... 00051 std::vector<HexPoint> miai; 00052 BitsetUtil::BitsetToVector(carrier, miai); 00053 00054 // carrier cells must be neighbours to qualify as bridge 00055 if (!brd.Const().Adjacent(miai[0], miai[1])) 00056 return false; 00057 00058 // find the two cells adjacent to both 00059 std::vector<HexPoint> adj; 00060 for (BoardIterator n1(brd.Const().Nbs(miai[0])); n1; ++n1) 00061 for (BoardIterator n2(brd.Const().Nbs(miai[1])); n2; ++n2) 00062 if (*n1 == *n2) adj.push_back(*n1); 00063 HexAssert(adj.size() == 2); 00064 00065 // pick the edge and endpoint 00066 for (std::size_t i=0; i<2; ++i) 00067 { 00068 if (HexPointUtil::isEdge(adj[i])) { 00069 edge = adj[i]; 00070 endpoint = adj[i^1]; 00071 return true; 00072 } 00073 } 00074 00075 // did not touch an edge, so return false 00076 return false; 00077 } 00078 00079 //----------------------------------------------------------------------------