Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

ICEngine.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef ICENGINE_H
00007 #define ICENGINE_H
00008 
00009 #include "Digraph.hpp"
00010 #include "Groups.hpp"
00011 #include "InferiorCells.hpp"
00012 #include "IcePatternSet.hpp"
00013 #include "HandCodedPattern.hpp"
00014 #include "PatternState.hpp"
00015 
00016 _BEGIN_BENZENE_NAMESPACE_
00017 
00018 //----------------------------------------------------------------------------
00019 
00020 /** Inferior Cell Engine. 
00021     Finds inferior cells on a given boardstate.
00022 
00023     ICE is thread-safe. Multiple threads can use the same instance
00024     of ICEngine without any problems. 
00025 */
00026 class ICEngine
00027 {
00028 public:
00029 
00030     //------------------------------------------------------------------------
00031 
00032     /** Constructor. */
00033     ICEngine();
00034 
00035     /** Destructor. */
00036     virtual ~ICEngine();
00037 
00038     //------------------------------------------------------------------------
00039     
00040     /** @name Board modifying functions of ICEngine */
00041     // @{
00042 
00043     /** Categorizes cells as dead, captured, etc. Board will be
00044         modified with the fill-in.
00045     */
00046     void ComputeInferiorCells(HexColor color, Groups& board,
00047                               PatternState& pastate, 
00048                               InferiorCells& out) const;
00049     
00050     /** Computes fill-in; dominated and vulnerable cells are not
00051         stored.
00052     */
00053     void ComputeFillin(HexColor color, Groups& board, 
00054                        PatternState& pastate, InferiorCells& out,
00055                        HexColorSet colors_to_capture=ALL_COLORS) const;
00056 
00057     /** Computes only the dead and captured cells; board will be
00058         modified to have the captured cells filled-in. Returns number of
00059         cells filled-in.
00060     */
00061     std::size_t ComputeDeadCaptured(Groups& board, PatternState& pastate,
00062                                     InferiorCells& inf, 
00063                                     HexColorSet colors_to_capture) const;
00064     
00065     // @} // @name
00066 
00067     //------------------------------------------------------------------------
00068 
00069     /** @name Methods to find various types of inferior cells */
00070     // @{ 
00071 
00072     /** Returns the dead cells among the consider set. */
00073     bitset_t FindDead(const PatternState& board, 
00074                       const bitset_t& consider) const;
00075 
00076     /** Finds vulnerable cells for color among the consider set. */
00077     void FindVulnerable(const PatternState& board, HexColor color,
00078             const bitset_t& consider,
00079             InferiorCells& inf) const;
00080 
00081     /** Finds reversible cells for color among the consider set. */
00082     void FindReversible(const PatternState& board, HexColor color,
00083             const bitset_t& consider,
00084             InferiorCells& inf) const;
00085 
00086     /** Finds dominated cells for color among the consider set using
00087         local patterns. Calls FindHandCodedDominated(). */
00088     void FindDominated(const PatternState& board, HexColor color, 
00089                        const bitset_t& consider, InferiorCells& inf) const;
00090 
00091     /** Finds all dominated cell patterns for color on this one cell. */
00092     void FindDominatedOnCell(const PatternState& pastate,
00093                              HexColor color, 
00094                              HexPoint cell,
00095                              PatternHits& hits) const;
00096 
00097     /** Finds cells dominated via hand-coded patterns. */
00098     void FindHandCodedDominated(const StoneBoard& board, HexColor color,
00099                                 const bitset_t& consider, 
00100                                 InferiorCells& inf) const;
00101 
00102     /** Finds captured cells for color among the consider set using
00103         local patterns. */
00104     bitset_t FindCaptured(const PatternState& board, HexColor color, 
00105                           const bitset_t& consider) const;
00106 
00107     /** Finds the permanently inferior cells for color among consider
00108         set using local patterns. */
00109     bitset_t FindPermanentlyInferior(const PatternState& board, 
00110                                      HexColor color, 
00111                                      const bitset_t& consider,
00112                                      bitset_t& carrier) const;
00113 
00114     /** Finds the mutual fillin cells for color among consider
00115         set using local patterns. */
00116     void FindMutualFillin(const PatternState& board, 
00117                           HexColor color, 
00118                           const bitset_t& consider,
00119                           bitset_t& carrier,
00120                           bitset_t *mut) const;
00121 
00122     // @} // @name
00123     
00124     //------------------------------------------------------------------------
00125 
00126     /** @name Parameters */
00127     // @{ 
00128 
00129     /** @todo Document what presimplicial pairs are! */
00130     bool FindPresimplicialPairs() const;
00131 
00132     /** @see FindPresimplicialPairs() */
00133     void SetFindPresimplicialPairs(bool enable);
00134 
00135     /** @todo Document permanently inferior cells. */
00136     bool FindPermanentlyInferior() const;
00137 
00138     /** @see FindPermanentlyInferior() */
00139     void SetFindPermanentlyInferior(bool enable);
00140 
00141     /** @todo Document mutual fillin. */
00142     bool FindMutualFillin() const;
00143 
00144     /** @see FindMutualFillin() */
00145     void SetFindMutualFillin(bool enable);
00146 
00147     /** Find all killers for each cell if true, stop at first if false. */
00148     bool FindAllPatternKillers() const;
00149 
00150     /** @see FindAllPatternKillers() */
00151     void SetFindAllPatternKillers(bool enable);
00152 
00153     /** Find all reversers for each cell if true, stop at first if false. */
00154     bool FindAllPatternReversers() const;
00155 
00156     /** @see FindAllPatternReversers() */
00157     void SetFindAllPatternReversers(bool enable);
00158 
00159     /** Find all dominators for each cell if true, stop at first if false. */
00160     bool FindAllPatternDominators() const;
00161 
00162     /** @see FindAllPatternDominators() */
00163     void SetFindAllPatternDominators(bool enable);
00164 
00165     /** @todo Document hand coded patterns. */
00166     bool UseHandCodedPatterns() const;
00167 
00168     /** @see UseHandCodedPatterns() */
00169     void SetUseHandCodedPatterns(bool enable);
00170 
00171     /** Performs a 1-ply search for the opponent: any dead stones
00172         created in child states are backed-up as vulnerable cells in
00173         this state, with the killer set to all the created fillin.*/
00174     bool BackupOpponentDead() const;
00175 
00176     /** @see BackupOpponentDead() */
00177     void SetBackupOpponentDead(bool enable);
00178 
00179     /** @todo Document three sided dead regions. */
00180     bool FindThreeSidedDeadRegions() const;
00181 
00182     /** @see FindThreeSidedDeadRegions() */
00183     void SetFindThreeSidedDeadRegions(bool enable);
00184 
00185     /** Performs a dead region sweep on each iteration of
00186         the fillin loop if true, only at the end if false. 
00187 
00188         @todo Link to fillin algo documentation!
00189     */
00190     bool IterativeDeadRegions() const;
00191 
00192     /** @see IterativeDeadRegions() */
00193     void SetIterativeDeadRegions(bool enable);
00194 
00195     // @}
00196 
00197 private:
00198     /** @see FindPresimplicialPairs() */
00199     bool m_find_presimplicial_pairs;
00200 
00201     /** @see FindPermanentlyInferior() */
00202     bool m_find_permanently_inferior;
00203 
00204     /** @see FindMutualFillin() */
00205     bool m_find_mutual_fillin;
00206 
00207     /** @see FindAllPatternKillers() */
00208     bool m_find_all_pattern_killers;
00209 
00210     /** @see FindAllPatternReversers() */
00211     bool m_find_all_pattern_reversers;
00212 
00213     /** @see FindAllPatternDominators() */
00214     bool m_find_all_pattern_dominators;
00215 
00216     /** @see UseHandCodedPatterns() */
00217     bool m_use_handcoded_patterns;
00218 
00219     /** @see BackupOpponentDead() */
00220     bool m_backup_opponent_dead;
00221 
00222     /** @see FindThreeSidedDeadRegions() */
00223     bool m_find_three_sided_dead_regions;
00224 
00225     /** @see IterativeDeadRegions() */
00226     bool m_iterative_dead_regions;
00227     
00228     std::vector<HandCodedPattern> m_hand_coded;
00229 
00230     IcePatternSet m_patterns;
00231 
00232     void LoadPatterns();
00233 
00234     void LoadHandCodedPatterns();
00235 
00236     std::size_t FillinPermanentlyInferior(Groups& groups, 
00237                                           PatternState& board, HexColor color,
00238                                           InferiorCells& out, 
00239                                           HexColorSet colors_to_capture) const;
00240 
00241     std::size_t FillInMutualFillin(Groups& groups, 
00242                                    PatternState& board, HexColor color,
00243                                    InferiorCells& out, 
00244                                    HexColorSet colors_to_capture) const;
00245 
00246     std::size_t CliqueCutsetDead(Groups& groups, PatternState& pastate, 
00247                                  InferiorCells& out) const;
00248 
00249     std::size_t BackupOpponentDead(HexColor color, const StoneBoard& board, 
00250                               PatternState& pastate, InferiorCells& out) const;
00251 
00252     std::size_t FillInVulnerable(HexColor color, Groups& groups, 
00253                                  PatternState& pastate, InferiorCells& inf, 
00254                                  HexColorSet colors_to_capture) const;
00255 
00256     void CheckHandCodedDominates(const StoneBoard& brd, HexColor color,
00257                                  const HandCodedPattern& pattern, 
00258                                  const bitset_t& consider, 
00259                                  InferiorCells& inf) const;
00260 
00261 };
00262 
00263 inline bool ICEngine::FindPresimplicialPairs() const
00264 {
00265     return m_find_presimplicial_pairs;
00266 }
00267 
00268 inline void ICEngine::SetFindPresimplicialPairs(bool enable)
00269 {
00270     m_find_presimplicial_pairs = enable;
00271 }
00272 
00273 inline bool ICEngine::FindPermanentlyInferior() const
00274 {
00275     return m_find_permanently_inferior;
00276 }
00277 
00278 inline void ICEngine::SetFindPermanentlyInferior(bool enable)
00279 {
00280     m_find_permanently_inferior = enable;
00281 }
00282 
00283 inline bool ICEngine::FindMutualFillin() const
00284 {
00285     return m_find_mutual_fillin;
00286 }
00287 
00288 inline void ICEngine::SetFindMutualFillin(bool enable)
00289 {
00290     m_find_mutual_fillin = enable;
00291 }
00292 
00293 inline bool ICEngine::FindAllPatternKillers() const
00294 {
00295     return m_find_all_pattern_killers;
00296 }
00297 
00298 inline void ICEngine::SetFindAllPatternKillers(bool enable)
00299 {
00300     m_find_all_pattern_killers = enable;
00301 }
00302 
00303 inline bool ICEngine::FindAllPatternReversers() const
00304 {
00305     return m_find_all_pattern_reversers;
00306 }
00307 
00308 inline void ICEngine::SetFindAllPatternReversers(bool enable)
00309 {
00310     m_find_all_pattern_reversers = enable;
00311 }
00312 
00313 inline bool ICEngine::FindAllPatternDominators() const
00314 {
00315     return m_find_all_pattern_dominators;
00316 }
00317 
00318 inline void ICEngine::SetFindAllPatternDominators(bool enable)
00319 {
00320     m_find_all_pattern_dominators = enable;
00321 }
00322 
00323 inline bool ICEngine::UseHandCodedPatterns() const
00324 {
00325     return m_use_handcoded_patterns;
00326 }
00327 
00328 inline void ICEngine::SetUseHandCodedPatterns(bool enable)
00329 {
00330     m_use_handcoded_patterns = enable;
00331 }
00332 
00333 inline bool ICEngine::BackupOpponentDead() const
00334 {
00335     return m_backup_opponent_dead;
00336 }
00337 
00338 inline void ICEngine::SetBackupOpponentDead(bool enable)
00339 {
00340     m_backup_opponent_dead = enable;
00341 }
00342 
00343 inline bool ICEngine::FindThreeSidedDeadRegions() const
00344 {
00345     return m_find_three_sided_dead_regions;
00346 }
00347 
00348 inline void ICEngine::SetFindThreeSidedDeadRegions(bool enable)
00349 {
00350     m_find_three_sided_dead_regions = enable;
00351 }
00352 
00353 inline bool ICEngine::IterativeDeadRegions() const
00354 {
00355     return m_iterative_dead_regions;
00356 }
00357 
00358 inline void ICEngine::SetIterativeDeadRegions(bool enable)
00359 {
00360     m_iterative_dead_regions = enable;
00361 }
00362 
00363 //----------------------------------------------------------------------------
00364 
00365 /** Utilities needed by ICE. */
00366 namespace IceUtil 
00367 {
00368     /** Adds the inferior cell info from in to the inferior cell info
00369         of out. */
00370     void Update(InferiorCells& out, const InferiorCells& in);
00371 }
00372 
00373 //----------------------------------------------------------------------------
00374 
00375 _END_BENZENE_NAMESPACE_
00376 
00377 #endif // ICENGINE_H


6 Jan 2011 Doxygen 1.6.3