00001
00002
00003 #ifndef SEARCH_NULLWINDOWSEARCHPOLICY
00004 #define SEARCH_NULLWINDOWSEARCHPOLICY
00005
00006 #include "osl/search/nullWindowSearch.h"
00007 namespace osl
00008 {
00009 namespace search
00010 {
00011 namespace null_window
00012 {
00016 template <typename NullWindowSearch, Player P,
00017 bool best_move_extension>
00018 struct NullWindowSearchPolicy
00019 {
00020 typedef NullWindow window_t;
00021 typedef NullWindowSearch searcher_t;
00022
00023 NullWindowSearch *searcher;
00024 NullWindow my_window;
00025 NullWindowSearchPolicy(NullWindowSearch *s, NullWindow window)
00026 : searcher(s), my_window(window)
00027 {
00028 }
00029 void setSearcher(NullWindowSearch *new_searcher){
00030 searcher = new_searcher;
00031 }
00033 bool searchWithMove(const SearchMove& ml, int& max_value,
00034 SearchMove& best_move) const
00035 {
00036 return (*searcher).template
00037 nullWindowSearch<P,best_move_extension>
00038 (ml, max_value, best_move);
00039 }
00040 static const bool isBestMoveExtension = best_move_extension;
00041 const NullWindow window() const { return my_window; }
00042 template <class Recorder>
00043 TableHit isOutOfWindow(Player
00044 #ifndef NDEBUG
00045 p
00046 #endif
00047 , const SimpleHashRecord& record,
00048 int limit, int& val, const Recorder& recorder) const
00049 {
00050 assert(P == p);
00051 return NullWindowUtil<P,NullWindowSearch,best_move_extension>::
00052 isOutOfWindow(record, limit, my_window, val, recorder);
00053 }
00054 void recordToTable(Player
00055 #ifndef NDEBUG
00056 p
00057 #endif
00058 ,
00059 SimpleHashRecord *record, int limit,
00060 const SearchMove& best_move, int val) const
00061 {
00062 assert(P == p);
00063 assert(record);
00064 assert(limit >= 0);
00065 if (EvalTraits<P>::betterThan(val, my_window.alpha()))
00066 {
00067 searcher->recordLowerBound(P, record, limit, best_move, val);
00068 }
00069 else
00070 {
00071 assert(EvalTraits<P>::betterThan(my_window.alpha(), val));
00072 searcher->recordUpperBound(P, record, limit, best_move, val);
00073 }
00074 }
00075 };
00076
00081 template <typename NullWindowSearch, Player P, bool best_move_extension>
00082 struct DoUndoNullWindow
00083 {
00084 NullWindowSearch *searcher;
00085 const SearchMove& moved;
00086 int max_value;
00087 int *result;
00088 DoUndoNullWindow(NullWindowSearch *s, const SearchMove& md, int m)
00089 : searcher(s), moved(md), max_value(m)
00090 {
00091 assert(P == md.getMove().player());
00092 }
00093 void setResultAddress(int *result)
00094 {
00095 this->result = result;
00096 }
00097 void operator()(Position )
00098 {
00099 #ifndef NDEBUG
00100 const int cur_limit = searcher->curLimit();
00101 #endif
00102 *result = (*searcher).template
00103 nullWindowSearchAfterMove<P,best_move_extension>(moved, max_value);
00104 assert(cur_limit == searcher->curLimit());
00105 }
00106 };
00107 }
00108 }
00109 }
00110
00111
00112 #endif
00113
00114
00115
00116