00001 #ifndef _MTDF_H
00002 #define _MTDF_H
00003
00004 #include "osl/search/searchTable.h"
00005 #include "osl/search/searchBase.h"
00006 #include "osl/search/searchFramework.h"
00007 #include "osl/search/nullWindowSearch.h"
00008 #include "osl/search/searchMoveSorter.h"
00009 #include "osl/search/hasTimer.h"
00010 #include "osl/checkmate/dualCheckmateSearcher.h"
00011 #include "osl/container/moveStack.h"
00012 #include "osl/eval/concept.h"
00013 #include "osl/misc/realTime.h"
00014
00015 namespace osl
00016 {
00017 namespace search
00018 {
00019 class SimpleHashTable;
00020 class SearchMove;
00021 class BigramKillerMove;
00022 class MtdfParShared;
00036 template<typename Eval, typename MoveGenerator,
00037 typename Table=SimpleHashTable,
00038 typename Recorder=CountRecorder,
00039 typename Probabilities=RealizationProbability>
00040 class MTDF
00041 : public SearchBase<Eval,Table,Recorder,Probabilities>,
00042 public HasTimer
00043 {
00044 BOOST_CLASS_REQUIRE(Eval, osl::eval, Concept);
00045 typedef SearchBase<Eval,Table,Recorder,Probabilities> base_t;
00046 public:
00047 typedef MTDF<Eval,MoveGenerator,Table,Recorder,Probabilities> mtdf_t;
00048 typedef NullWindowSearch<Eval,MoveGenerator,Table,Recorder,Probabilities> tester_t;
00049 typedef typename base_t::eval_t eval_t;
00050 typedef misc::RealTime RealTime;
00051 typedef DualCheckmateSearcher<> checkmate_t;
00052 #ifdef OSL_SMP
00053 boost::shared_ptr<CheckmateSearcherHolder<checkmate_t> > checkmate_holder;
00054 #endif
00055 private:
00056 int threshold;
00057 int lower_bound, upper_bound;
00058 checkmate_t *checkmate_searcher;
00059 tester_t memory_tester;
00060 RealTime timer;
00061 const MoveVector *root_ignore_moves;
00062 public:
00063 explicit MTDF(const HashEffectState& s,
00064 DualCheckmateSearcher<>& c,
00065 Table& t, Recorder& r);
00066 ~MTDF();
00067
00071 void setInitialGuess(int guess);
00073 void setInitialGuess();
00074 #ifdef OSL_SMP
00075 void setCheckmateSearcher(checkmate_t *c, const Worker *w);
00076 #endif
00077 bool isReasonableMove(Move move, int pawn_sacrifice=1);
00078
00079
00081 void setHistory(const MoveStack& history)
00082 {
00083 memory_tester.setHistory(history);
00084 }
00085 void setRootIgnoreMoves(const MoveVector *rim) { root_ignore_moves = rim; }
00090 const Move computeBestMove(int limit, const RealTime& timer=RealTime(60));
00097 const Move computeBestMoveIteratively(int limit,
00098 const int step=100,
00099 const int initialLimit=400,
00100 int nodeLimit=1600000,
00101 const misc::RealTime& timer
00102 =misc::RealTime(60));
00103
00104 const AlarmSwitch alarmSwitch();
00105 const BigramKillerMove& bigramKillerMove();
00106 void setBigramKillerMove(const BigramKillerMove& killers);
00107 private:
00108
00110 template<Player P>
00111 const Move computeBestMoveOfPlayer(int limit);
00113 template<Player P>
00114 const Move retryByLowerF(SimpleHashRecord *record, int limit,
00115 SearchMoveSorter<P>& lower_moves, SearchMoveSorter<P>& higher_moves);
00126 template<Player P>
00127 const Move selectBestMoveByHigherF(SimpleHashRecord *record, int limit,
00128 SearchMoveSorter<P>& lower_moves, SearchMoveSorter<P>& higher_moves);
00129 template <Player P>
00130 void triageMovesSpeculatively(SearchMoveSorter<P>& higher_moves, int limit,
00131 int jump);
00132 public:
00142 template<Player P>
00143 void examineMoves(const char *category_name, int& current_value,
00144 int limit, const SearchMoveVector& moves,
00145 SearchMoveSorter<P>& lower_moves,
00146 SearchMoveSorter<P>& higher_moves);
00147 #ifdef OSL_SMP
00148 template<Player P>
00149 void examineMovesParBlock(const boost::shared_ptr<MtdfParShared>&,
00150 int limit, size_t first, size_t last);
00151 template<Player P>
00152 void examineMovesPar(int& current_value,
00153 int limit, const SearchMoveVector& moves,
00154 SearchMoveSorter<P>& lower_moves,
00155 SearchMoveSorter<P>& higher_moves);
00156 #endif
00157
00160 void gatherMoves(const MoveLogProbVector& moves,
00161 SearchMoveSet& out);
00162 private:
00169 template<Player P>
00170 bool testMove(const SearchMove& move, int& val, int& max_value, int limit);
00171 public:
00172 const DualCheckmateSearcher<> *
00173 checkmateSearcher() const { return checkmate_searcher; }
00174 const HistoryTable& historyTable() const {
00175 return memory_tester.historyTable();
00176 }
00177 };
00178 }
00179 using search::MTDF;
00180 }
00181
00182 #endif
00183
00184
00185
00186