| 1 |
/* checkmateRecorder.h |
| 2 |
*/ |
| 3 |
#ifndef _CHECKMATERECORDER_H |
| 4 |
#define _CHECKMATERECORDER_H |
| 5 |
|
| 6 |
#include "osl/move.h" |
| 7 |
#include <iosfwd> |
| 8 |
|
| 9 |
namespace osl |
| 10 |
{ |
| 11 |
namespace state |
| 12 |
{ |
| 13 |
class SimpleState; |
| 14 |
} |
| 15 |
namespace hash |
| 16 |
{ |
| 17 |
class HashKey; |
| 18 |
} |
| 19 |
class PathEncoding; |
| 20 |
namespace checkmate |
| 21 |
{ |
| 22 |
class CheckHashRecord; |
| 23 |
class CheckMove; |
| 24 |
using state::SimpleState; |
| 25 |
using hash::HashKey; |
| 26 |
/** |
| 27 |
* 詰将棋の記録を取るクラス. |
| 28 |
* 現在は全てクラスメソッド.並列化の際は, CheckmateSearcher* から |
| 29 |
* CheckmateRecorder を選ぶしかけが必要? |
| 30 |
*/ |
| 31 |
class CheckmateRecorder |
| 32 |
{ |
| 33 |
public: |
| 34 |
static CheckMove *nextMove; |
| 35 |
static const char *leaveReason; |
| 36 |
static const SimpleState *currentState; |
| 37 |
|
| 38 |
static std::ostream& stream(); |
| 39 |
static void dumpStack(); |
| 40 |
static void dumpRecord(const SimpleState& state, |
| 41 |
const CheckHashRecord *record, |
| 42 |
unsigned int proofLimit, |
| 43 |
unsigned int disproofLimit, |
| 44 |
unsigned int currentProofNumber, |
| 45 |
unsigned int currentDisproofNumber); |
| 46 |
|
| 47 |
static void stat(const char *msg, Player P, unsigned int tableSize, |
| 48 |
unsigned int totalNodeCount, unsigned int totalNodeLimit); |
| 49 |
/** root での情報を記録 */ |
| 50 |
static void rootLog( |
| 51 |
#ifdef CHECKMATE_DEBUG |
| 52 |
const char *msg, unsigned int tableSize, |
| 53 |
unsigned int continuousNoExpandLoop |
| 54 |
#else |
| 55 |
const char *, unsigned int, unsigned int |
| 56 |
#endif |
| 57 |
) |
| 58 |
{ |
| 59 |
#ifdef CHECKMATE_DEBUG |
| 60 |
writeRootLog(msg, tableSize, continuousNoExpandLoop); |
| 61 |
#endif |
| 62 |
} |
| 63 |
static void writeRootLog(const char *msg, unsigned int tableSize, |
| 64 |
unsigned int continuousNoExpandLoop); |
| 65 |
/** attack/defense に入る時記録 */ |
| 66 |
static void enter(int depth, const char *name, |
| 67 |
CheckHashRecord *record, const HashKey& key, |
| 68 |
const PathEncoding& path, |
| 69 |
unsigned int proofLimit, unsigned int disproofLimit); |
| 70 |
/** attack/defense から帰る時記録 */ |
| 71 |
static void leave(int depth, const char *name, |
| 72 |
const CheckHashRecord *record); |
| 73 |
static void setNextMove(CheckMove * |
| 74 |
#ifdef CHECKMATE_DEBUG |
| 75 |
m |
| 76 |
#endif |
| 77 |
) |
| 78 |
{ |
| 79 |
#ifdef CHECKMATE_DEBUG |
| 80 |
nextMove = m; |
| 81 |
#endif |
| 82 |
} |
| 83 |
static void setLeaveReason(const char * |
| 84 |
#ifdef CHECKMATE_DEBUG |
| 85 |
reason |
| 86 |
#endif |
| 87 |
) |
| 88 |
{ |
| 89 |
#ifdef CHECKMATE_DEBUG |
| 90 |
leaveReason = reason; |
| 91 |
#endif |
| 92 |
} |
| 93 |
static void setState(const SimpleState * |
| 94 |
#ifdef CHECKMATE_DEBUG |
| 95 |
state |
| 96 |
#endif |
| 97 |
) |
| 98 |
{ |
| 99 |
#ifdef CHECKMATE_DEBUG |
| 100 |
currentState = state; |
| 101 |
#endif |
| 102 |
} |
| 103 |
struct DepthTracer |
| 104 |
{ |
| 105 |
static int depth; |
| 106 |
static int maxLogDepth; |
| 107 |
static int maxVerboseLogDepth; |
| 108 |
static std::ostream& stream(); |
| 109 |
|
| 110 |
CheckHashRecord *record; |
| 111 |
const char *name; |
| 112 |
DepthTracer(const char *n, |
| 113 |
CheckHashRecord *r, |
| 114 |
const HashKey& key, |
| 115 |
const PathEncoding& path, |
| 116 |
unsigned int proofLimit, |
| 117 |
unsigned int disproofLimit) |
| 118 |
: record(r), name(n) |
| 119 |
{ |
| 120 |
++depth; |
| 121 |
if (depth < maxLogDepth) |
| 122 |
enter(depth, name, record, key, path, proofLimit, disproofLimit); |
| 123 |
} |
| 124 |
~DepthTracer() |
| 125 |
{ |
| 126 |
if (depth < maxLogDepth) |
| 127 |
{ |
| 128 |
leave(depth, name, record); |
| 129 |
} |
| 130 |
depth--; |
| 131 |
} |
| 132 |
}; |
| 133 |
struct NullTracer |
| 134 |
{ |
| 135 |
NullTracer(const char *, const CheckHashRecord *, |
| 136 |
const HashKey&, const PathEncoding&, |
| 137 |
unsigned int, unsigned int) |
| 138 |
{ |
| 139 |
} |
| 140 |
~NullTracer() |
| 141 |
{ |
| 142 |
} |
| 143 |
}; |
| 144 |
#ifdef CHECKMATE_DEBUG |
| 145 |
typedef DepthTracer Tracer; |
| 146 |
#else |
| 147 |
typedef NullTracer Tracer; |
| 148 |
#endif |
| 149 |
}; |
| 150 |
} // namespace checkmate |
| 151 |
} // namespace osl |
| 152 |
|
| 153 |
#endif /* _CHECKMATERECORDER_H */ |
| 154 |
// ;;; Local Variables: |
| 155 |
// ;;; mode:c++ |
| 156 |
// ;;; c-basic-offset:2 |
| 157 |
// ;;; End: |