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 <boost/scoped_ptr.hpp>
00009 #include <iosfwd>
00010 namespace osl
00011 {
00012 class MoveLogProb;
00013 namespace state
00014 {
00015 class SimpleState;
00016 }
00017 namespace search
00018 {
00026 class CountRecorder
00027 {
00028 int node_count;
00029 int quiescence_count;
00030 int checkmate_count;
00031 public:
00032 CountRecorder();
00033 virtual ~CountRecorder();
00034
00036 void addNodeCount(int count=1) { node_count += count; }
00037 void addQuiescenceCount(int count=1) { quiescence_count += count; }
00038 void addCheckmateCount(int count=1) { checkmate_count += count; }
00039 void setCheckmateCount(int count=1) { checkmate_count = count; }
00040
00041 void resetNodeCount();
00042 int nodeCount() const { return node_count; }
00043 int quiescenceCount() const { return quiescence_count; }
00044 int checkmateCount() const { return checkmate_count; }
00045
00047 void tryMove(const MoveLogProb& , int , int ) const {}
00049 void retryMove(const MoveLogProb& , int , int ,
00050 int ) const {}
00052 void recordValue(const MoveLogProb&, int , bool ,
00053 int ) const {}
00054
00056 void recordTopLevelLowFail(const MoveLogProb& , int ) const {}
00057 void recordTopLevelHighFail(const MoveLogProb& , int ) const {}
00058
00059 void tableHitLowerBound(Player, int, int , int ) const {}
00060 void tableHitUpperBound(Player, int, int , int ) const {}
00061
00062 void tableStoreLowerBound(Player, const MoveLogProb&, int, int) const {}
00063 void tableStoreUpperBound(Player, const MoveLogProb&, int, int) const {}
00064
00065
00066 void startSearch(int ) const {}
00068 virtual void finishSearch(Move best, double seconds_consumed,
00069 bool verbose) const;
00070
00071 void recordInvalidMoveInTable(const state::SimpleState&,
00072 const MoveLogProb&, int limit) const;
00073 void newCategory(const char *, int ) const {}
00074
00076 void gotoCheckmateSearch(const state::SimpleState&, int) const {}
00077 void backFromCheckmateSearch() const {}
00078
00079 void reportCount(std::ostream&, double seconds) const;
00080 void reportCount(std::ostream&) const;
00081 };
00082
00083 class SearchRecorder : public CountRecorder
00084 {
00085 class Recorder;
00087 boost::scoped_ptr<Recorder> recorder;
00088 public:
00089 explicit SearchRecorder(const char *filename="mtdf.log");
00090 ~SearchRecorder();
00091
00093 void setLogMargin(int margin=500);
00094
00095 void tryMove(const MoveLogProb& m, int last_f, int limit) const;
00096 void retryMove(const MoveLogProb& m, int last_f, int limit,
00097 int retryCount) const;
00098
00099 void recordValue(const MoveLogProb& m, int val, bool betterMove, int limit) const;
00100
00101 void tableHitLowerBound(Player p, int val, int last_f, int limit) const;
00102 void tableHitUpperBound(Player p, int val, int last_f, int limit) const;
00103
00104 void tableStoreLowerBound(Player p, const MoveLogProb& best_move, int val, int limit) const;
00105 void tableStoreUpperBound(Player p, const MoveLogProb& best_move, int val, int limit) const;
00106
00107 void recordTopLevelLowFail(const MoveLogProb& , int last_f) const;
00108 void recordTopLevelHighFail(const MoveLogProb& best_move, int last_f) const;
00109
00110 void startSearch(int limit) const;
00111 void finishSearch(Move best_move, double seconds_consumed, bool verbose) const;
00112
00113 void newCategory(const char *name, int limit) const;
00114
00115 void gotoCheckmateSearch(const state::SimpleState&, int nodeLimit) const;
00116 void backFromCheckmateSearch() const;
00117
00119 std::ostream& stream() const;
00120 };
00121 }
00122
00123 using search::CountRecorder;
00124 using search::SearchRecorder;
00125 }
00126
00127
00128 #endif
00129
00130
00131
00132