00001 //---------------------------------------------------------------------------- 00002 /** @file SgStrategy.h 00003 SgStrategy is a strategy for winning a specified goal. 00004 00005 An example of a strategy: keep a territory safe that was proven safe 00006 earlier on. The strategy contains answers to any opponent threat. 00007 Strategies can be generated, tracked, and enforced during search. 00008 */ 00009 //---------------------------------------------------------------------------- 00010 00011 #ifndef SG_STRATEGY_H 00012 #define SG_STRATEGY_H 00013 00014 #include "SgArray.h" 00015 #include "SgBlackWhite.h" 00016 #include "SgBWArray.h" 00017 #include "SgHash.h" 00018 #include "SgPointSet.h" 00019 00020 //---------------------------------------------------------------------------- 00021 00022 enum SgStrategyStatus 00023 { 00024 SGSTRATEGY_ACHIEVED, 00025 SGSTRATEGY_THREATENED, 00026 SGSTRATEGY_UNKNOWN, 00027 SGSTRATEGY_FAILED, 00028 _SGSTRATEGY_COUNT 00029 }; 00030 00031 std::ostream& operator<<(std::ostream& stream, SgStrategyStatus s); 00032 00033 //---------------------------------------------------------------------------- 00034 00035 /** Strategy for achieving a certain goal. 00036 Pure virtual class, see e.g. SgMiaiStrategy for an implementation. 00037 */ 00038 class SgStrategy 00039 { 00040 public: 00041 SgStrategy(SgBlackWhite player); 00042 00043 virtual ~SgStrategy() {} 00044 00045 /** See m_player */ 00046 SgBlackWhite Player() const 00047 { 00048 return m_player; 00049 } 00050 00051 /** remove all data, reset to empty strategy. */ 00052 virtual void Clear(); 00053 00054 /** all points on board that can possibly affect strategy */ 00055 virtual SgPointSet Dependency() const = 0; 00056 00057 /** check success of strategy on given board */ 00058 virtual SgStrategyStatus Status() const = 0; 00059 00060 /** update strategy with move */ 00061 virtual void ExecuteMove(SgMove p, SgBlackWhite player) = 0; 00062 00063 /** go back to strategy state before move */ 00064 virtual void UndoMove() = 0; 00065 00066 /** Write object to stream. Do not call directly, use operator<< */ 00067 virtual void Write(std::ostream& stream) const; 00068 00069 private: 00070 /** The player that this strategy is for */ 00071 SgBlackWhite m_player; 00072 00073 /** Hash code of board region for which strategy is defined */ 00074 SgHashCode m_code; 00075 }; 00076 00077 std::ostream& operator<<(std::ostream& stream, const SgStrategy& s); 00078 00079 //---------------------------------------------------------------------------- 00080 00081 #endif // SG_STRATEGY_H