00001 //---------------------------------------------------------------------------- 00002 /** @file SgMiaiMap.h 00003 Efficient implementation of a consistent (not broken) SgMiaiStrategy. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #ifndef SG_MIAIMAP_H 00008 #define SG_MIAIMAP_H 00009 00010 #include "SgArray.h" 00011 #include "SgBlackWhite.h" 00012 #include "SgBWArray.h" 00013 #include "SgMiaiStrategy.h" 00014 #include "SgPoint.h" 00015 00016 //---------------------------------------------------------------------------- 00017 00018 /** Efficient implementation of a SgMiaiStrategy. 00019 The miai strategy must be achievable (not broken). 00020 Uses two boards, one for each color. 00021 Board entries either point to the miai point, 00022 or are set to SG_NULLPOINT if the point is not part of a miai. 00023 Can only be used going forward through a game - does not support undo. */ 00024 class SgMiaiMap 00025 { 00026 public: 00027 /** Initialize to empty map. */ 00028 SgMiaiMap(); 00029 00030 /** See SgStrategy::ExecuteMove */ 00031 void ExecuteMove(SgPoint p, SgBlackWhite player); 00032 00033 /** See m_forcedMove */ 00034 SgPoint ForcedMove() const {return m_forcedMove;} 00035 00036 /** See SgStrategyStatus */ 00037 SgStrategyStatus Status() const; 00038 00039 /** Convert SgMiaiStrategy into SgMiaiMap. 00040 The SgMiaiStrategy must not have overlapping threats. */ 00041 void ConvertFromSgMiaiStrategy(const SgMiaiStrategy& s); 00042 00043 /** Convert SgMiaiMap into SgMiaiStrategy. */ 00044 void ConvertToSgMiaiStrategy(SgMiaiStrategy* s) const; 00045 private: 00046 /** Move that must be played to stop or convert an open threat. 00047 Returns SG_NULLPOINT if no such move. */ 00048 SgPoint m_forcedMove; 00049 00050 /** Strategy has failed if opponent has occupied both points in a pair */ 00051 bool m_failed; 00052 00053 /** The maps, one for each color. */ 00054 SgBWArray<SgArray<int,SG_MAXPOINT> > m_map; 00055 }; 00056 00057 std::ostream& operator<<(std::ostream& stream, const SgStrategy& s); 00058 00059 //---------------------------------------------------------------------------- 00060 00061 #endif // SG_MIAIMAP_H