00001 //---------------------------------------------------------------------------- 00002 /** @file SgSearchTracer.h 00003 Trace search for SgSearch. 00004 00005 SgSearchTracer stores the whole search in a game tree using SgNode's. */ 00006 //---------------------------------------------------------------------------- 00007 00008 #ifndef SG_SEARCHTRACER_H 00009 #define SG_SEARCHTRACER_H 00010 00011 #include "SgBlackWhite.h" 00012 #include "SgMove.h" 00013 #include "SgNode.h" 00014 00015 //---------------------------------------------------------------------------- 00016 00017 /** Traces a search. */ 00018 class SgSearchTracer 00019 { 00020 public: 00021 SgSearchTracer(SgNode* root); 00022 00023 virtual ~SgSearchTracer(); 00024 00025 /** Adds the given move as a new node to the trace tree and goes 00026 to that node. Doesn't do anything if m_traceNode is 0. */ 00027 void AddTraceNode(SgMove move, SgBlackWhite player); 00028 00029 /** Current node */ 00030 SgNode* TraceNode() const; 00031 00032 /** Add comment to current tracenode */ 00033 void TraceComment(const char* comment) const; 00034 00035 void StartOfDepth(int depth); 00036 00037 /** Adds move property to node (game-dependent). 00038 The default implementation stores the move in a SgMoveProp. 00039 Override this method for other games. */ 00040 virtual void AddMoveProp(SgNode* node, SgMove move, 00041 SgBlackWhite player); 00042 00043 /** Add value as a comment to current tracenode */ 00044 void TraceValue(int value, SgBlackWhite toPlay) const; 00045 00046 /** Add value and text as a comment to current tracenode */ 00047 void TraceValue(int value, SgBlackWhite toPlay, 00048 const char* comment, bool isExact) const; 00049 00050 /** Go one move up in the trace tree. 00051 Don't do anything if m_traceNode is null. 00052 To be called from the client's TakeBack method. */ 00053 void TakeBackTraceNode(); 00054 00055 /** Is tracing on? Default implementation always returns true. */ 00056 virtual bool TraceIsOn() const; 00057 00058 /** Creates a new root node for tracing. Override to add information */ 00059 virtual void InitTracing(const std::string& type); 00060 00061 /** Move trace tree to a subtree of toNode, and set m_traceNode = 0 */ 00062 void AppendTrace(SgNode* toNode); 00063 00064 protected: 00065 /** Current node in tracing. */ 00066 SgNode* m_traceNode; 00067 00068 private: 00069 /** Not implemented */ 00070 SgSearchTracer(const SgSearchTracer&); 00071 00072 /** Not implemented */ 00073 SgSearchTracer& operator=(const SgSearchTracer&); 00074 }; 00075 00076 inline SgNode* SgSearchTracer::TraceNode() const 00077 { 00078 return m_traceNode; 00079 } 00080 00081 inline bool SgSearchTracer::TraceIsOn() const 00082 { 00083 return true; 00084 } 00085 00086 //---------------------------------------------------------------------------- 00087 00088 #endif // SG_SEARCH_H