00001
00002
00003 #ifndef _CHECKMATERECORDER_H
00004 #define _CHECKMATERECORDER_H
00005
00006 #include "osl/move.h"
00007 #include <iosfwd>
00008
00009 namespace osl
00010 {
00011 namespace state
00012 {
00013 class SimpleState;
00014 }
00015 namespace hash
00016 {
00017 class HashKey;
00018 }
00019 class PathEncoding;
00020 namespace checkmate
00021 {
00022 class CheckHashRecord;
00023 class CheckMove;
00024 using state::SimpleState;
00025 using hash::HashKey;
00031 class CheckmateRecorder
00032 {
00033 public:
00034 static CheckMove *nextMove;
00035 static const char *leaveReason;
00036 static const SimpleState *currentState;
00037
00038 static std::ostream& stream();
00039 static void dumpStack();
00040 static void dumpRecord(const SimpleState& state,
00041 const CheckHashRecord *record,
00042 unsigned int proofLimit,
00043 unsigned int disproofLimit,
00044 unsigned int currentProofNumber,
00045 unsigned int currentDisproofNumber);
00046
00047 static void stat(const char *msg, Player P, unsigned int tableSize,
00048 unsigned int totalNodeCount, unsigned int totalNodeLimit);
00050 static void rootLog(
00051 #ifdef CHECKMATE_DEBUG
00052 const char *msg, unsigned int tableSize,
00053 unsigned int continuousNoExpandLoop
00054 #else
00055 const char *, unsigned int, unsigned int
00056 #endif
00057 )
00058 {
00059 #ifdef CHECKMATE_DEBUG
00060 writeRootLog(msg, tableSize, continuousNoExpandLoop);
00061 #endif
00062 }
00063 static void writeRootLog(const char *msg, unsigned int tableSize,
00064 unsigned int continuousNoExpandLoop);
00066 static void enter(int depth, const char *name,
00067 CheckHashRecord *record, const HashKey& key,
00068 const PathEncoding& path,
00069 unsigned int proofLimit, unsigned int disproofLimit);
00071 static void leave(int depth, const char *name,
00072 const CheckHashRecord *record);
00073 static void setNextMove(CheckMove *
00074 #ifdef CHECKMATE_DEBUG
00075 m
00076 #endif
00077 )
00078 {
00079 #ifdef CHECKMATE_DEBUG
00080 nextMove = m;
00081 #endif
00082 }
00083 static void setLeaveReason(const char *
00084 #ifdef CHECKMATE_DEBUG
00085 reason
00086 #endif
00087 )
00088 {
00089 #ifdef CHECKMATE_DEBUG
00090 leaveReason = reason;
00091 #endif
00092 }
00093 static void setState(const SimpleState *
00094 #ifdef CHECKMATE_DEBUG
00095 state
00096 #endif
00097 )
00098 {
00099 #ifdef CHECKMATE_DEBUG
00100 currentState = state;
00101 #endif
00102 }
00103 struct DepthTracer
00104 {
00105 static int depth;
00106 static int maxLogDepth;
00107 static int maxVerboseLogDepth;
00108 static std::ostream& stream();
00109
00110 CheckHashRecord *record;
00111 const char *name;
00112 DepthTracer(const char *n,
00113 CheckHashRecord *r,
00114 const HashKey& key,
00115 const PathEncoding& path,
00116 unsigned int proofLimit,
00117 unsigned int disproofLimit)
00118 : record(r), name(n)
00119 {
00120 ++depth;
00121 if (depth < maxLogDepth)
00122 enter(depth, name, record, key, path, proofLimit, disproofLimit);
00123 }
00124 ~DepthTracer()
00125 {
00126 if (depth < maxLogDepth)
00127 {
00128 leave(depth, name, record);
00129 }
00130 depth--;
00131 }
00132 };
00133 struct NullTracer
00134 {
00135 NullTracer(const char *, const CheckHashRecord *,
00136 const HashKey&, const PathEncoding&,
00137 unsigned int, unsigned int)
00138 {
00139 }
00140 ~NullTracer()
00141 {
00142 }
00143 };
00144 #ifdef CHECKMATE_DEBUG
00145 typedef DepthTracer Tracer;
00146 #else
00147 typedef NullTracer Tracer;
00148 #endif
00149 };
00150 }
00151 }
00152
00153 #endif
00154
00155
00156
00157