00001 //---------------------------------------------------------------------------- 00002 /** @file 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef INFERIOR_CELLS_HPP 00007 #define INFERIOR_CELLS_HPP 00008 00009 #include "Hex.hpp" 00010 #include "Digraph.hpp" 00011 00012 _BEGIN_BENZENE_NAMESPACE_ 00013 00014 //---------------------------------------------------------------------------- 00015 00016 class VulnerableKiller 00017 { 00018 public: 00019 00020 /** Creates killer with empty carrier. */ 00021 VulnerableKiller(HexPoint killer); 00022 00023 /** Creates killer with given carrier. */ 00024 VulnerableKiller(HexPoint killer, const bitset_t& carrier); 00025 00026 HexPoint killer() const; 00027 bitset_t carrier() const; 00028 00029 bool operator==(const VulnerableKiller& other) const; 00030 bool operator!=(const VulnerableKiller& other) const; 00031 bool operator<(const VulnerableKiller& other) const; 00032 00033 private: 00034 HexPoint m_killer; 00035 bitset_t m_carrier; 00036 }; 00037 00038 inline VulnerableKiller::VulnerableKiller(HexPoint killer) 00039 : m_killer(killer), 00040 m_carrier() 00041 { 00042 } 00043 00044 inline VulnerableKiller::VulnerableKiller(HexPoint killer, 00045 const bitset_t& carrier) 00046 : m_killer(killer), 00047 m_carrier(carrier) 00048 { 00049 } 00050 00051 inline HexPoint VulnerableKiller::killer() const 00052 { 00053 return m_killer; 00054 } 00055 00056 inline bitset_t VulnerableKiller::carrier() const 00057 { 00058 return m_carrier; 00059 } 00060 00061 inline bool VulnerableKiller::operator==(const VulnerableKiller& other) const 00062 { 00063 /** @todo This ignores the carrier. This means only the first (killer, 00064 carrier) pair is stored for each killer. We may want to 00065 keep only the smallest carrier, or all of them. */ 00066 return (m_killer == other.m_killer); 00067 } 00068 00069 inline bool VulnerableKiller::operator!=(const VulnerableKiller& other) const 00070 { 00071 return !operator==(other); 00072 } 00073 00074 inline bool VulnerableKiller::operator<(const VulnerableKiller& other) const 00075 { 00076 if (m_killer != other.m_killer) 00077 return m_killer < other.m_killer; 00078 return false; 00079 } 00080 00081 //---------------------------------------------------------------------------- 00082 00083 /** Set of inferior cells. */ 00084 class InferiorCells 00085 { 00086 public: 00087 00088 /** Constructs empty inferior cell set. */ 00089 InferiorCells(); 00090 00091 //------------------------------------------------------------------------ 00092 00093 bitset_t Dead() const; 00094 bitset_t Captured(HexColor color) const; 00095 bitset_t PermInf(HexColor color) const; 00096 bitset_t PermInfCarrier(HexColor color) const; 00097 bitset_t MutualFillin(HexColor color) const; 00098 bitset_t MutualFillinCarrier(HexColor color) const; 00099 00100 /** Returns the set of vulnerable cells. */ 00101 bitset_t Vulnerable() const; 00102 00103 /** Returns the set of reversible cells. 00104 00105 @note An empty cell can be both reversible and vulnerable. In 00106 this case it will be vulnerable and not appear in the cells 00107 returned by Reversible(). */ 00108 bitset_t Reversible() const; 00109 00110 /** Returns the set of dominated cells. This is not the same as 00111 the set of all cells dominated by some other cell. The 00112 returned is a maximal set of dominated cells that can be ignored 00113 during move 00114 00115 @note A cell can be both dominated (have an outgoing arc in 00116 the domination graph), and be vulnerable (have an outgoing arc 00117 in the vulnerable graph) and/or reversible. In such a case, the 00118 cell will never appear in the cells returned by Dominated(). */ 00119 00120 bitset_t Dominated() const; 00121 00122 bitset_t All() const; 00123 00124 bitset_t Fillin(HexColor color) const; 00125 00126 const std::set<VulnerableKiller>& Killers(HexPoint p) const; 00127 00128 const std::set<HexPoint>& Reversers(HexPoint p) const; 00129 bitset_t AllReversers() const; 00130 bitset_t AllReversibleCarriers() const; 00131 00132 //------------------------------------------------------------------------ 00133 00134 /** Returns a string representation of its internal state. 00135 The format is as follows: 00136 1) First character is either f (for fill-in) or i (for ignorable) 00137 2a) If fill-in, 2nd character is c/d/p/u (captured/dead/perminf/mutual) 00138 and 3rd character is b/w (black/white fill-in colour) 00139 2b) If ignorable, 2nd character is v/r/d (vulnerable/reversible/domin) 00140 and 3rd entry is list of killers/reversers/dominators 00141 */ 00142 std::string GuiOutput() const; 00143 00144 /** Examines the vulnerable cells; returns the set of 00145 presimplicial cells on the cells they kill. */ 00146 bitset_t FindPresimplicialPairs() const; 00147 00148 /** Uses the inferior cell information to compute the deduction set. 00149 This is the part of the proof set used to derive the equivalent 00150 ICE-reduced board. 00151 The proof set is composed of this, the played stones, and (some 00152 subset of) the empty cells on the ICE-reduced board. 00153 Note: it is assumed the color passed in is the player for whom 00154 the pruning (vulnerable, reversible, dominated) was computed, so 00155 these are not used... just the fillin. 00156 */ 00157 bitset_t DeductionSet(HexColor color) const; 00158 00159 //------------------------------------------------------------------------ 00160 00161 void AddDead(const bitset_t& dead); 00162 void AddDead(HexPoint dead); 00163 00164 void AddCaptured(HexColor color, const bitset_t& captured); 00165 void AddCaptured(HexColor color, HexPoint captured); 00166 00167 void AddPermInf(HexColor color, const bitset_t& cells, 00168 const bitset_t& carrier); 00169 void AddPermInf(HexColor color, HexPoint cell, const bitset_t& carrier); 00170 00171 void AddMutualFillin(HexColor color, const bitset_t& cells, 00172 const bitset_t& carrier); 00173 void AddMutualFillin(HexColor color, HexPoint cell, 00174 const bitset_t& carrier); 00175 00176 void AddDominated(HexPoint cell, HexPoint dominator); 00177 void AddDominated(HexPoint cell, const std::set<HexPoint>& dom); 00178 00179 void AddVulnerable(HexPoint cell, HexPoint killer); 00180 void AddVulnerable(HexPoint cell, const std::set<HexPoint>& killers); 00181 void AddVulnerable(HexPoint cell, const VulnerableKiller& killer); 00182 void AddVulnerable(HexPoint cell, const std::set<VulnerableKiller>& dom); 00183 00184 void AddReversible(HexPoint cell, bitset_t carrier, HexPoint reverser); 00185 void AddReversible(HexPoint cell, bitset_t carrier, 00186 const std::set<HexPoint>& reversers); 00187 00188 void AddDominatedFrom(const InferiorCells& other); 00189 void AddVulnerableFrom(const InferiorCells& other); 00190 void AddReversibleFrom(const InferiorCells& other); 00191 void AddPermInfFrom(HexColor color, const InferiorCells& other); 00192 void AddMutualFillinFrom(HexColor color, const InferiorCells& other); 00193 00194 //------------------------------------------------------------------------ 00195 00196 void Clear(); 00197 00198 void ClearDead(); 00199 void ClearVulnerable(); 00200 void ClearReversible(); 00201 void ClearDominated(); 00202 void ClearCaptured(HexColor color); 00203 void ClearPermInf(HexColor color); 00204 void ClearMutualFillin(HexColor color); 00205 00206 void RemoveDead(const bitset_t& dead); 00207 void RemoveCaptured(HexColor color, const bitset_t& captured); 00208 void RemoveDominated(const bitset_t& dominated); 00209 void RemoveVulnerable(const bitset_t& vulnerable); 00210 void RemoveReversible(const bitset_t& reversible); 00211 void RemoveReversible(HexPoint reversible); 00212 void RemovePermInf(HexColor color, const bitset_t& perminf); 00213 void RemoveMutualFillin(HexColor color, const bitset_t& mutual); 00214 00215 private: 00216 00217 //------------------------------------------------------------------------ 00218 00219 void AssertPairwiseDisjoint() const; 00220 00221 //------------------------------------------------------------------------ 00222 00223 bitset_t m_dead; 00224 00225 bitset_t m_captured[BLACK_AND_WHITE]; 00226 00227 bitset_t m_perm_inf[BLACK_AND_WHITE]; 00228 bitset_t m_perm_inf_carrier[BLACK_AND_WHITE]; 00229 00230 bitset_t m_mutual_fillin[BLACK_AND_WHITE]; 00231 bitset_t m_mutual_fillin_carrier[BLACK_AND_WHITE]; 00232 00233 //------------------------------------------------------------------------ 00234 00235 /** Vulnerable cells; not those involved in presimplicial 00236 pairs, though. */ 00237 bitset_t m_vulnerable; 00238 std::set<VulnerableKiller> m_killers[BITSETSIZE]; 00239 00240 //------------------------------------------------------------------------ 00241 00242 /** Reversible cells and their reversers. */ 00243 bitset_t m_reversible; 00244 std::set<HexPoint> m_reversers[BITSETSIZE]; 00245 /** Data to test for independent captured-reversible sets. */ 00246 bitset_t m_allReversibleCarriers; 00247 bitset_t m_allReversers; 00248 00249 //------------------------------------------------------------------------ 00250 00251 /** Graph of domination; dominated cells point to their 00252 dominators. */ 00253 Digraph<HexPoint> m_dom_graph; 00254 00255 /** True if the dominated set has been computed from the 00256 domination graph. Set to false whenever the domination graph 00257 changes. */ 00258 mutable bool m_dominated_computed; 00259 00260 /** The sources of the domination graph minus a few 00261 representatives. */ 00262 mutable bitset_t m_dominated; 00263 00264 }; 00265 00266 inline bitset_t InferiorCells::Dead() const 00267 { 00268 return m_dead; 00269 } 00270 00271 inline bitset_t InferiorCells::Vulnerable() const 00272 { 00273 return m_vulnerable; 00274 } 00275 00276 inline bitset_t InferiorCells::Reversible() const 00277 { 00278 return m_reversible; 00279 } 00280 00281 inline bitset_t InferiorCells::Captured(HexColor color) const 00282 { 00283 return m_captured[color]; 00284 } 00285 00286 inline bitset_t InferiorCells::PermInf(HexColor color) const 00287 { 00288 return m_perm_inf[color]; 00289 } 00290 00291 inline bitset_t InferiorCells::PermInfCarrier(HexColor color) const 00292 { 00293 return m_perm_inf_carrier[color]; 00294 } 00295 00296 inline bitset_t InferiorCells::MutualFillin(HexColor color) const 00297 { 00298 return m_mutual_fillin[color]; 00299 } 00300 00301 inline bitset_t InferiorCells::MutualFillinCarrier(HexColor color) const 00302 { 00303 return m_mutual_fillin_carrier[color]; 00304 } 00305 00306 inline 00307 const std::set<VulnerableKiller>& InferiorCells::Killers(HexPoint p) const 00308 { 00309 return m_killers[p]; 00310 } 00311 00312 inline 00313 const std::set<HexPoint>& InferiorCells::Reversers(HexPoint p) const 00314 { 00315 return m_reversers[p]; 00316 } 00317 00318 inline bitset_t InferiorCells::AllReversers() const 00319 { 00320 return m_allReversers; 00321 } 00322 00323 inline bitset_t InferiorCells::AllReversibleCarriers() const 00324 { 00325 return m_allReversibleCarriers; 00326 } 00327 00328 //------------------------------------------------------------------------ 00329 00330 /** Utilities on InferiorCells. */ 00331 namespace InferiorCellsUtil 00332 { 00333 00334 bitset_t FindDominationCaptains(const Digraph<HexPoint>& graph); 00335 00336 } 00337 00338 //------------------------------------------------------------------------ 00339 00340 _END_BENZENE_NAMESPACE_ 00341 00342 #endif // INFERIOR_CELLS_HPP