00001 //---------------------------------------------------------------------------- 00002 /** @file HandCodedPattern.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "HandCodedPattern.hpp" 00007 #include "BoardUtils.hpp" 00008 00009 using namespace benzene; 00010 00011 //---------------------------------------------------------------------------- 00012 00013 HandCodedPattern::HandCodedPattern() 00014 : m_dominatee(INVALID_POINT), 00015 m_dominator(INVALID_POINT) 00016 { 00017 } 00018 00019 HandCodedPattern::HandCodedPattern(HexPoint dominatee, HexPoint dominator) 00020 : m_dominatee(dominatee), 00021 m_dominator(dominator) 00022 { 00023 } 00024 00025 HandCodedPattern::~HandCodedPattern() 00026 { 00027 } 00028 00029 //---------------------------------------------------------------------------- 00030 00031 void HandCodedPattern::set(HexColor color, const bitset_t& bs) 00032 { 00033 HexAssert(HexColorUtil::isBlackWhite(color)); 00034 m_color[color] = bs; 00035 } 00036 00037 void HandCodedPattern::rotate(const ConstBoard& brd) 00038 { 00039 m_dominatee = BoardUtils::Rotate(brd, m_dominatee); 00040 m_dominator = BoardUtils::Rotate(brd, m_dominator); 00041 m_mask = BoardUtils::Rotate(brd, m_mask); 00042 for (BWIterator it; it; ++it) 00043 m_color[*it] = BoardUtils::Rotate(brd, m_color[*it]); 00044 } 00045 00046 void HandCodedPattern::mirror(const ConstBoard& brd) 00047 { 00048 m_dominatee = BoardUtils::Mirror(brd, m_dominatee); 00049 m_dominator = BoardUtils::Mirror(brd, m_dominator); 00050 m_mask = BoardUtils::Mirror(brd, m_mask); 00051 for (BWIterator it; it; ++it) 00052 m_color[*it] = BoardUtils::Mirror(brd, m_color[*it]); 00053 } 00054 00055 void HandCodedPattern::flipColors() 00056 { 00057 std::swap(m_color[BLACK], m_color[WHITE]); 00058 } 00059 00060 bool HandCodedPattern::check(const StoneBoard& brd) 00061 { 00062 for (BWIterator it; it; ++it) 00063 if (m_color[*it] != (brd.GetColor(*it) & m_mask)) 00064 return false; 00065 return true; 00066 } 00067 00068 //---------------------------------------------------------------------------- 00069 00070 void HandCodedPattern::CreatePatterns(std::vector<HandCodedPattern>& out) 00071 { 00072 bitset_t bs; 00073 HandCodedPattern pat; 00074 00075 // 00076 // 00077 // b3 dominates a3: 00078 // 00079 // A B C D 00080 // ---------- 00081 // 1 \ . . . . 00082 // 2 \ . . . 00083 // 3 \ * ! 00084 // 00085 HandCodedPattern pat1(HEX_CELL_A3, HEX_CELL_B3); 00086 bs.reset(); 00087 bs.set(HEX_CELL_A1); 00088 bs.set(HEX_CELL_B1); 00089 bs.set(HEX_CELL_C1); 00090 bs.set(HEX_CELL_D1); 00091 bs.set(HEX_CELL_A2); 00092 bs.set(HEX_CELL_B2); 00093 bs.set(HEX_CELL_C2); 00094 bs.set(HEX_CELL_A3); 00095 bs.set(HEX_CELL_B3); 00096 pat1.setMask(bs); 00097 out.push_back(pat1); 00098 00099 // 00100 // 00101 // With white c2, b3 dominates a3 and a4. 00102 // 00103 // a3 and a4 are actually vulnerable to b3!! 00104 // 00105 // A B C 00106 // ---------- 00107 // 1 \ . . . 00108 // 2 \ . . W 00109 // 3 \ * ! 00110 // 4 \ * 00111 // 00112 HandCodedPattern pat3(HEX_CELL_A3, HEX_CELL_B3); 00113 bs.reset(); 00114 bs.set(HEX_CELL_A1); 00115 bs.set(HEX_CELL_B1); 00116 bs.set(HEX_CELL_C1); 00117 bs.set(HEX_CELL_A2); 00118 bs.set(HEX_CELL_B2); 00119 bs.set(HEX_CELL_C2); 00120 bs.set(HEX_CELL_A3); 00121 bs.set(HEX_CELL_B3); 00122 bs.set(HEX_CELL_A4); 00123 pat3.setMask(bs); 00124 bs.reset(); 00125 bs.set(HEX_CELL_C2); 00126 pat3.set(WHITE, bs); 00127 00128 pat3.setDominatee(HEX_CELL_A3); 00129 out.push_back(pat3); 00130 00131 pat3.setDominatee(HEX_CELL_A4); 00132 out.push_back(pat3); 00133 } 00134 00135 //----------------------------------------------------------------------------