00001
00002
00003 #ifndef _SEARCH_FRAMEWORK_H
00004 #define _SEARCH_FRAMEWORK_H
00005
00006 #include "osl/search/realizationProbability.h"
00007 #include "osl/search/searchBase.h"
00008 #include "osl/search/searchState.h"
00009 #include "osl/search/searchWindow.h"
00010 #include "osl/search/passCounter.h"
00011 #include "osl/eval/evalTraits.h"
00012 #include "osl/eval/concept.h"
00013
00014 #ifdef OSL_SMP
00015 # include "osl/search/checkmateSearcherHolder.h"
00016 # include <boost/shared_ptr.hpp>
00017 #endif
00018
00019 namespace osl
00020 {
00021 namespace container
00022 {
00023 class MoveStack;
00024 class SearchMoveSet;
00025 class MoveLogProbVector;
00026 }
00027 namespace search
00028 {
00029 using namespace container;
00030
00031 class SimpleHashRecord;
00032 class SimpleHashTable;
00033 class SearchMoveVector;
00051 template<typename Eval, typename MoveGenerator,
00052 typename Table, typename Recorder,
00053 typename Probabilities=RealizationProbability>
00054 class SearchFramework
00055 : public SearchBase<Eval,Table,Recorder,Probabilities>,
00056 public SearchState
00057 {
00058 BOOST_CLASS_REQUIRE(Eval, osl::eval, Concept);
00059 typedef SearchBase<Eval,Table,Recorder,Probabilities> base_t;
00060 public:
00061 typedef Eval eval_t;
00062 typedef MoveGenerator MoveGenerator_t;
00063 typedef Probabilities Probabilities_t;
00064 protected:
00065 eval_t eval;
00066 private:
00067 PassCounter pass_count;
00068 #ifdef OSL_SMP
00069 typedef CheckmateSearcherHolder<checkmate_t> holder_t;
00070 boost::shared_ptr<holder_t> checkmate_holder;
00071 #endif
00072 size_t node_count;
00073 public:
00074 explicit SearchFramework(const HashEffectState& s, checkmate_t& checker,
00075 Table *t, Recorder& r);
00076 SearchFramework(const SearchFramework&);
00077 ~SearchFramework();
00078
00079 bool abort(Move) const;
00080 size_t nodeCount() const { return node_count; }
00081 protected:
00095 template<Player P, class Helper>
00096 int searchWithMove(const SearchMove& move, Helper& helper);
00097 public:
00098 const eval_t& getEval() const { return eval; }
00099 template<Player P, class Policy>
00100 int quiescenceValue(const Policy&);
00101 template<Player P>
00102 int quiescenceValue(int alpha, int beta, int depth=8 );
00107 bool isReasonableMove(Move move, int pawn_sacrifice);
00108
00121 template<Player P, class Policy>
00122 int searchAllMoves(SimpleHashRecord *& record,
00123 const Policy&, SearchMove& best_move);
00124
00136 template<Player P, class Helper, bool isKingEscape>
00137 bool examineMoves(const char *category_name, const MoveLogProbVector& moves,
00138 const Helper&, SearchMove& best_move,
00139 int& max_value, SearchMoveSet& tried);
00144 template<Player P, class Helper>
00145 bool examineMoves(const char *category_name, const SearchMoveVector& moves,
00146 const Helper&, SearchMove& best_move, int& max_value);
00147 template<Player P, class Helper>
00148 bool examineOneMove(const SearchMove& move,
00149 const Helper&, SearchMove& best_move, int& max_value);
00150 #ifdef OSL_SMP
00151
00155 template<Player P, class Helper>
00156 bool examineMovesPar(boost::shared_ptr<SearchMoveVector> moves,
00157 size_t index,
00158 const Helper&, SearchMove& best_move, int& max_value);
00159 void shareCheckmateHolder(boost::shared_ptr<holder_t>&);
00160 #endif
00161 };
00162 }
00163 }
00164
00165 #endif
00166
00167
00168
00169