quiescenceSearch2.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
quiescenceSearch2.h
Go to the documentation of this file.
1 /* quiescenceSearch2.h
2 */
3 #ifndef _QUIESCENCESEARCH2_H
4 #define _QUIESCENCESEARCH2_H
5
6 #include "osl/search/fixedEval.h"
7 #include "osl/search/quiescenceRecord.h"
8 #include "osl/search/searchState2.h"
9 #include "osl/eval/pieceEval.h"
10 #include "osl/state/numEffectState.h"
11 #include "osl/pathEncoding.h"
12 namespace osl
13 {
14 namespace container
15 {
16 class MoveVector;
17 }
18 namespace hash
19 {
20 class HashKey;
21 }
22 namespace search
23 {
24 class SimpleHashTable;
25
40 template <class EvalT>
41 class QuiescenceSearch2 : protected FixedEval, private QSearchTraits
42 {
43 typedef FixedEval base_t;
44 SearchState2Core& state;
45 SimpleHashTable& table;
46 int root_depth;
47 int max_depth;
51 int node_count;
53 int depthFromRoot() const
54 {
55 return state.path().getDepth() - root_depth;
56 }
58 int depth() const
59 {
60 return max_depth - depthFromRoot();
61 }
62 public:
63 typedef EvalT eval_t;
64 typedef NumEffectState effect_state_t;
65 using base_t::isWinValue;
66
67 typedef container::MoveVector MoveVector;
68
69 QuiescenceSearch2(SearchState2Core& s, SimpleHashTable& t)
70 : state(s), table(t), root_depth(s.path().getDepth()),
71 max_depth(QSearchTraits::MaxDepth), node_count(0)
72 {
73 }
74 template <Player P>
75 int search(eval_t& ev, Move last_move,
76 int depth=QSearchTraits::MaxDepth)
77 {
78 assert(last_move.player() == alt(P));
79 assert(state.state().turn() == P);
80 max_depth = depth;
81 return searchInternal<P>(base_t::winThreshold(alt(P)),
82 base_t::winThreshold(P),
83 ev, last_move);
84 }
85 int search(Player P, eval_t& ev, Move last_move,
86 int depth=QSearchTraits::MaxDepth)
87 {
88 if (P == BLACK)
89 return search<BLACK>(ev, last_move, depth);
90 else
91 return search<WHITE>(ev, last_move, depth);
92 }
93 template <Player P>
94 int searchIteratively(eval_t& ev, Move last_move,
95 int depth=QSearchTraits::MaxDepth)
96 {
97 assert(last_move.player() == alt(P));
98 assert(state.state().turn() == P);
99 return searchIteratively<P>(base_t::winThreshold(alt(P)),
100 base_t::winThreshold(P),
101 ev, last_move, depth);
102 }
103 int searchIteratively(Player P, eval_t& ev, Move last_move,
104 int depth=QSearchTraits::MaxDepth)
105 {
106 if (P == BLACK)
107 return searchIteratively<BLACK>(ev, last_move, depth);
108 else
109 return searchIteratively<WHITE>(ev, last_move, depth);
110 }
111
112 template <Player P>
113 int searchIteratively(int alpha, int beta, eval_t& ev, Move last_move,
114 int depth)
115 {
116 assert(depth >= 2);
117 int result=0;
118 for (int i=2; i<=depth; i+=2)
119 {
120 max_depth = i;
121 result=searchInternal<P>(alpha, beta, ev, last_move);
122 }
123 return result;
124 }
125 template <Player P>
126 int search(int alpha, int beta, eval_t& ev, Move last_move,
127 int depth=QSearchTraits::MaxDepth)
128 {
129 max_depth = depth;
130 return searchInternal<P>(alpha, beta, ev, last_move);
131 }
132 int search(Player P, int alpha, int beta, eval_t& ev, Move last_move, int depth){
133 if (P == BLACK)
134 return search<BLACK>(alpha, beta, ev, last_move, depth);
135 else
136 return search<WHITE>(alpha, beta, ev, last_move, depth);
137 }
138 template <Player P>
139 int searchProbCut(int alpha, int beta, eval_t& ev, Move last_move);
140 int searchProbCut(Player P, int alpha, int beta, eval_t& ev, Move last_move)
141 {
142 if (P == BLACK)
143 return searchProbCut<BLACK>(alpha, beta, ev, last_move);
144 else
145 return searchProbCut<WHITE>(alpha, beta, ev, last_move);
146 }
147
148 enum EvalUpdateState { AfterUpdate, BeforeUpdate };
149 template <Player P>
150 int searchInternal(int alpha, int beta, eval_t& ev, Move last_move,
151 int additional_depth=0, EvalUpdateState need_eval_update=AfterUpdate);
152 private:
153 template <Player P, bool has_record>
154 int searchMain(QuiescenceRecord *record,
155 int alpha, int beta, eval_t& ev, Move last_move,
156 int additional_depth, EvalUpdateState& need_eval_update);
161 template <Player P, Ptype PTYPE, bool has_record>
162 bool examineCapture(QuiescenceRecord *record,
163 int& curVal, MoveVector& working, int& alpha,
164 int beta, eval_t const& ev, Piece last_piece,
165 int additional_depth);
166 public:
167 template <Player P, bool has_record>
168 int staticValue(eval_t const& ev, int alpha, int beta, QuiescenceRecord *record);
169 private:
170 template <Player P>
171 int passValue(int alpha, int beta, eval_t const& ev);
172 int currentValueWithLastThreat(eval_t const& ev, Piece last_move_piece);
173 public:
179 template <Player P, bool has_record, bool has_dont_capture, MoveType move_type>
180 bool examineMoves(QuiescenceRecord *record, int& curVal,
181 const Move *first, const Move *last,
182 int& alpha, int beta, eval_t const& ev,
183 int additional_depth,
184 Square dont_capture=Square::STAND());
191 template <Player P>
192 int takeBackValue(int alpha, int beta, eval_t const& ev, Move last_move);
193 template <Player P>
194 bool examineTakeBack(const MoveVector& moves,
195 int& cur_val, int& alpha, int beta, eval_t const& ev);
196
204 template <Player P, bool calm_move_only, bool first_nolmal_move_only>
205 bool examineTakeBack2(const MoveVector& moves,
206 QuiescenceThreat& threat2,
207 QuiescenceThreat& threat1,
208 int beta, int beta2, eval_t const& ev);
212 template <Player P, Ptype PTYPE>
213 bool generateAndExamineTakeBack2(MoveVector& moves,
214 QuiescenceThreat& threat2,
215 QuiescenceThreat& threat1,
216 int beta1, int beta2, eval_t const& ev);
217
221 template <Player P>
222 int takeBackOrChase(int alpha, int beta, eval_t const& ev, Move last_move);
223
224 template <Player P>
225 int staticValueWithThreat(eval_t const& ev, int alpha,
226 QuiescenceThreat& threat1,
227 QuiescenceThreat& threat2);
228 template <Player P>
229 int staticValueWithThreat(eval_t const& ev)
230 {
231 QuiescenceThreat t1, t2;
232 return staticValueWithThreat<P>(ev, base_t::winThreshold(alt(P)),
233 t1, t2);
234 }
235 int staticValueWithThreat(eval_t const& ev)
236 {
237 if (state.state().turn() == BLACK)
238 return staticValueWithThreat<BLACK>(ev);
239 else
240 return staticValueWithThreat<WHITE>(ev);
241 }
242 int nodeCount() const { return node_count; }
243 const NumEffectState& currentState() const { return state.state(); }
244 };
245
246 } // namespace search
247 using search::QuiescenceSearch2;
248 } // namespace osl
249
250
251 #endif /* _QUIESCENCESEARCH2_H */
252 // ;;; Local Variables:
253 // ;;; mode:c++
254 // ;;; c-basic-offset:2
255 // ;;; End: