searchWindow.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
searchWindow.h
Go to the documentation of this file.
1 /* searchWindow.h
2 */
3 #ifndef _SEARCHWINDOW_H
4 #define _SEARCHWINDOW_H
5
6 #include "osl/search/simpleHashRecord.h"
7 #include "osl/eval/evalTraits.h"
8 namespace osl
9 {
10 namespace search
11 {
12 enum TableHit { NO_HIT=0, LOWER_HIT, UPPER_HIT };
13 struct AlphaBetaWindow
14 {
15 int alpha_value, beta_value;
16 explicit AlphaBetaWindow(int a, int b) : alpha_value(a), beta_value(b)
17 {
18 assert(a % 2);
19 assert(b % 2);
20 }
21 int& alpha() { return alpha_value; }
22 int& beta() { return beta_value; }
23 int alpha() const { return alpha_value; }
24 int beta() const { return beta_value; }
25 const AlphaBetaWindow flipPlayer() const
26 {
27 return AlphaBetaWindow(beta(), alpha());
28 }
29 bool isConsistent(Player P) const
30 {
31 return eval::notLessThan(P, beta(), alpha());
32 }
33 bool null() const { return alpha() == beta(); }
34 void dump() const;
35 };
36
37 template <Player P, class EvalBase>
38 struct AlphaBetaWindowUtil
39 {
40 typedef typename EvalBase::eval_t eval_t;
44 template <class Recorder>
45 static
46 TableHit isOutOfWindow(const SimpleHashRecord& record, int limit,
47 AlphaBetaWindow& w, int& val,
48 const Recorder& recorder)
49 {
50 #ifdef __APPLE__
51 int table_value=0;
52 #else
53 int table_value;
54 #endif
55 if (record.template hasGreaterLowerBound<P>(limit, w.alpha(),
56 table_value))
57 {
58 assert(eval::isConsistentValue(table_value));
59 w.alpha() = table_value + EvalTraits<P>::delta;
60 if (EvalTraits<P>::betterThan(table_value, w.beta()))
61 {
62 recorder.tableHitLowerBound(P, table_value, w.beta(), limit);
63 val = table_value;
64 return LOWER_HIT;
65 }
66 }
67 if (record.template hasLesserUpperBound<P>(limit, w.beta(), table_value))
68 {
69 assert(eval::isConsistentValue(table_value));
70 w.beta() = table_value - EvalTraits<P>::delta;
71 if (EvalTraits<P>::betterThan(w.alpha(), table_value))
72 {
73 recorder.tableHitUpperBound(P, table_value, w.alpha(), limit);
74 val = table_value;
75 return UPPER_HIT;
76 }
77 }
78 return NO_HIT;
79 }
80 };
81
82
83 struct NullWindow
84 {
85 int value;
86
87 explicit NullWindow(int v) :value(v)
88 {
89 }
90 int& alpha() { return value; }
91 int& beta() { return value; }
92 int alpha() const { return value; }
93 int beta() const { return value; }
94 bool isConsistent(Player) const { return true; }
95 void dump() const;
96 };
97
98 template <Player P, class EvalBase, bool best_move_extension>
99 struct NullWindowUtil
100 {
101 typedef typename EvalBase::eval_t eval_t;
110 template <class Recorder>
111 static
112 TableHit isOutOfWindow(const SimpleHashRecord& record, int limit,
113 NullWindow w,
114 int& val, const Recorder& recorder)
115 {
116 const int lookUpLimit = (best_move_extension ? limit + 200 : limit);
117 #ifdef __APPLE__
118 int table_value=0;
119 #else
120 int table_value;
121 #endif
122 if (record.template hasGreaterLowerBound<P>
123 (lookUpLimit, w.beta(), table_value))
124 {
125 assert(eval::isConsistentValue(table_value));
126 recorder.tableHitLowerBound(P, table_value, w.beta(), limit);
127
128 val = table_value;
129 return LOWER_HIT;
130 }
131 if (record.template hasLesserUpperBound<P>
132 (lookUpLimit, w.alpha(), table_value))
133 {
134 assert(eval::isConsistentValue(table_value));
135 recorder.tableHitUpperBound(P, table_value, w.alpha(), limit);
136
137 val = table_value;
138 return UPPER_HIT;
139 }
140 return NO_HIT;
141 }
142
143 };
144
145 } // namespace search
146 } // namespace osl
147
148
149 #endif /* _SEARCHWINDOW_H */
150 // ;;; Local Variables:
151 // ;;; mode:c++
152 // ;;; c-basic-offset:2
153 // ;;; End: