00001
00002
00003 #ifndef _MTDF_RECORDER_H
00004 #define _MTDF_RECORDER_H
00005
00006 #include "osl/player.h"
00007 #include "osl/move.h"
00008 #include "osl/misc/lightMutex.h"
00009 #include <boost/scoped_ptr.hpp>
00010 #include <iosfwd>
00011 namespace osl
00012 {
00013 class MoveLogProb;
00014 namespace state
00015 {
00016 class SimpleState;
00017 }
00018 namespace search
00019 {
00027 class CountRecorder
00028 {
00029 size_t node_count;
00030 size_t quiescence_count;
00031 size_t checkmate_count;
00032 #ifdef OSL_SMP
00033 mutable LightMutex mutex;
00034 #endif
00035 public:
00036 CountRecorder();
00037 virtual ~CountRecorder();
00038
00040 void addNodeCount(int count=1) {
00041 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00042 SCOPED_LOCK(lk,mutex);
00043 #endif
00044 node_count += count;
00045 }
00046 void addQuiescenceCount(int count=1) {
00047 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00048 SCOPED_LOCK(lk,mutex);
00049 #endif
00050 quiescence_count += count;
00051 }
00052 void addCheckmateCount(int count=1) {
00053 #ifdef OSL_SMP
00054 SCOPED_LOCK(lk,mutex);
00055 #endif
00056 checkmate_count += count;
00057 }
00058 void setCheckmateCount(int count=1) {
00059 #ifdef OSL_SMP
00060 SCOPED_LOCK(lk,mutex);
00061 #endif
00062 checkmate_count = count;
00063 }
00064
00065 void resetNodeCount();
00066 size_t nodeCount() const {
00067 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00068 SCOPED_LOCK(lk,mutex);
00069 #endif
00070 return node_count;
00071 }
00072 size_t quiescenceCount() const {
00073 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00074 SCOPED_LOCK(lk,mutex);
00075 #endif
00076 return quiescence_count;
00077 }
00078 size_t checkmateCount() const {
00079 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00080 SCOPED_LOCK(lk,mutex);
00081 #endif
00082 return checkmate_count;
00083 }
00084 size_t allNodeCount() const {
00085 #if (defined OSL_SMP) && (defined OSL_USE_RACE_DETECTOR)
00086 SCOPED_LOCK(lk,mutex);
00087 #endif
00088 return node_count + quiescence_count + checkmate_count;
00089 }
00091 void tryMove(const MoveLogProb& , int , int ) const {}
00093 void retryMove(const MoveLogProb& , int , int ,
00094 int ) const {}
00096 void recordValue(const MoveLogProb&, int , bool ,
00097 int ) const {}
00098
00100 void recordTopLevelLowFail(const MoveLogProb& , int ) const {}
00101 void recordTopLevelHighFail(const MoveLogProb& , int ) const {}
00102
00103 void tableHitLowerBound(Player, int, int , int ) const {}
00104 void tableHitUpperBound(Player, int, int , int ) const {}
00105
00106 void tableStoreLowerBound(Player, const MoveLogProb&, int, int) const {}
00107 void tableStoreUpperBound(Player, const MoveLogProb&, int, int) const {}
00108
00109
00110 void startSearch(int ) const {}
00112 virtual void finishSearch(Move best, double seconds_consumed,
00113 bool verbose) const;
00114
00115 void recordInvalidMoveInTable(const state::SimpleState&,
00116 const MoveLogProb&, int limit) const;
00117 void newCategory(const char * , int ) const {}
00118
00120 void gotoCheckmateSearch(const state::SimpleState&, int) const {}
00121 void backFromCheckmateSearch() const {}
00122
00123 void reportCount(std::ostream&, double seconds) const;
00124 void reportCount(std::ostream&) const;
00125 };
00126
00127 class SearchRecorder : public CountRecorder
00128 {
00129 class Recorder;
00131 boost::scoped_ptr<Recorder> recorder;
00132 public:
00133 explicit SearchRecorder(const char *filename="mtdf.log");
00134 ~SearchRecorder();
00135
00137 void setLogMargin(int margin=500);
00138
00139 void tryMove(const MoveLogProb& m, int last_f, int limit) const;
00140 void retryMove(const MoveLogProb& m, int last_f, int limit,
00141 int retryCount) const;
00142
00143 void recordValue(const MoveLogProb& m, int val, bool betterMove, int limit) const;
00144
00145 void tableHitLowerBound(Player p, int val, int last_f, int limit) const;
00146 void tableHitUpperBound(Player p, int val, int last_f, int limit) const;
00147
00148 void tableStoreLowerBound(Player p, const MoveLogProb& best_move, int val, int limit) const;
00149 void tableStoreUpperBound(Player p, const MoveLogProb& best_move, int val, int limit) const;
00150
00151 void recordTopLevelLowFail(const MoveLogProb& , int last_f) const;
00152 void recordTopLevelHighFail(const MoveLogProb& best_move, int last_f) const;
00153
00154 void startSearch(int limit) const;
00155 void finishSearch(Move best_move, double seconds_consumed, bool verbose) const;
00156
00157 void newCategory(const char *name, int limit) const;
00158
00159 void gotoCheckmateSearch(const state::SimpleState&, int nodeLimit) const;
00160 void backFromCheckmateSearch() const;
00161
00163 std::ostream& stream() const;
00164 };
00165 }
00166
00167 using search::CountRecorder;
00168 using search::SearchRecorder;
00169 }
00170
00171
00172 #endif
00173
00174
00175
00176