ntesukiSearcher.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ntesukiSearcher.h
Go to the documentation of this file.
1 /* ntesukiSearcher.h
2 */
3 #ifndef _NTESUKI_SEACHER_H
4 #define _NTESUKI_SEACHER_H
5 #include "osl/state/numEffectState.h"
6 #include "osl/ntesuki/ntesukiTable.h"
7 #include "osl/ntesuki/ntesukiRecord.h"
8 #include "osl/ntesuki/ntesukiMoveGenerator.h"
9
10 #include "osl/ntesuki/ntesukiExceptions.h"
11 #include "osl/container/moveVector.h"
12 #include "osl/ntesuki/ntesukiSimulationSearcher.h"
13
14 #include <osl/stl/vector.h>
15
16 namespace osl
17 {
18 namespace ntesuki
19 {
20 class
21 NtesukiSearcher
22 {
23 public:
24 typedef NumEffectState State;
25
26 private:
27 State& state;
28
30 NtesukiMoveGenerator *mg;
31
33 NtesukiTable table;
34
36 NtesukiSimulationSearcher simulator;
37
39 unsigned int node_count;
40
42 unsigned int read_node_limit;
43
45 bool verbose;
46
48 volatile int *stop_flag;
49
51 PathEncoding path;
52
54 typedef std::vector<Move> moves_t;
55 moves_t moves_played;
56
58 typedef std::vector<NtesukiRecord *> nodes_t;
59 nodes_t nodes_played;
60
62 unsigned int max_pass;
63
64
65 public:
69 static bool delay_non_pass;
70 static bool ptt_invalid_defense;
71
72 static bool delay_interpose;
73 static bool delay_nopromote;
74 static bool delay_non_attack;
75 static bool read_attack_only;
76 static bool ptt_non_attack;
77
78 static bool ptt_siblings_fail;
79 static bool ptt_siblings_success;
80
81 static bool ptt_uncle;
82 static bool ptt_aunt;
83
84 static unsigned int dynamic_widening_width;
85
86 private:
88 NtesukiRecord::IWScheme iwscheme;
90 NtesukiRecord::PSScheme psscheme;
92 NtesukiRecord::ISScheme isscheme;
93
95 int tsumero_cost;
96
98 int tsumero_estimate;
99
101 double gc_ratio;
102
103 template<class Search,Player T> class AttackHelper;
104 template<class Search,Player T> class DefenseHelper;
105 template<class Search,Player T> class CallSimulationAttack;
106 template<class Search,Player T> class CallSimulationDefense;
107 template<class Search,Player T> class CallSimulationDefenseDisproof;
108
109 /* statistic information */
110 unsigned int blockByAttackBack;
111 unsigned int blockByPass;
112 unsigned int attack_node_count;
113 unsigned int attack_node_under_attack_count;
114 unsigned int attack_node_moves_count;
115 unsigned int defense_node_count;
116 unsigned int defense_node_under_attack_count;
117 unsigned int defense_node_moves_count;
118 unsigned int pass_count, pass_success_count;
119 unsigned int pass_attack_count, pass_attack_success_count;
120 unsigned int sibling_defense_count, sibling_defense_success_count;
121 unsigned int sibling_attack_count, sibling_attack_success_count;
122 unsigned int isshogi_defense_count, isshogi_defense_success_count;
123 unsigned int isshogi_attack_count, isshogi_attack_success_count;
124 unsigned int immediate_win, immediate_lose;
125 unsigned int attack_back_count;
126 unsigned int proof_without_inversion_count, proof_AND_count, disproof_by_inversion_count;
127
128 public:
129 static const int NtesukiNotFound = -1;
130 static const int ReadLimitReached = -2;
131 static const int TableLimitReached = -3;
132 private:
133 static const unsigned int INITIAL_PROOF_LIMIT =
134 ProofDisproof::PROOF_LIMIT / 4;
135 static const unsigned int INITIAL_DISPROOF_LIMIT =
136 ProofDisproof::DISPROOF_LIMIT / 4;
137
141 template <Player T>
142 NtesukiResult attack(NtesukiRecord* record,
143 const NtesukiRecord* oracle_attack,
144 const NtesukiRecord* oracle_defense,
145 unsigned int proofLimit,
146 unsigned int disproofLimit,
147 int pass_left,
148 const Move last_move);
149 template <Player T>
150 void attackWithOrder(NtesukiRecord* record,
151 const NtesukiRecord* oracle_attack,
152 const NtesukiRecord* oracle_defense,
153 unsigned int proofLimit,
154 unsigned int disproofLimit,
155 int pass_left,
156 const Move last_move);
157
158 template <Player T>
159 NtesukiMove* selectMoveAttack(NtesukiRecord* record,
160 unsigned int& best_proof,
161 unsigned int& sum_disproof,
162 unsigned int& second_proof,
163 unsigned int& best_disproof,
164 unsigned int& step_cost,
165 NtesukiMoveList& moves,
166 const int pass_left);
167
171 template <Player T>
172 NtesukiResult defense(NtesukiRecord* record,
173 const NtesukiRecord* oracle_attack,
174 const NtesukiRecord* oracle_defense,
175 unsigned int proofLimit,
176 unsigned int disproofLimit,
177 int pass_left,
178 const Move last_move);
179
180
181 template <Player T>
182 void defenseWithPlayer(NtesukiRecord* record,
183 const NtesukiRecord* oracle_attack,
184 const NtesukiRecord* oracle_defense,
185 unsigned int proofLimit,
186 unsigned int disproofLimit,
187 int pass_left,
188 const Move last_move);
189
190 template <Player T>
191 NtesukiMove* selectMoveDefense(NtesukiRecord* record,
192 unsigned int& best_disproof,
193 unsigned int& sum_proof,
194 unsigned int& second_disproof,
195 unsigned int& best_proof,
196 unsigned int& step_cost,
197 NtesukiMoveList& moves,
198 const int pass_left,
199 const Move last_move);
200
208 template <Player T> void simulateSiblingsSuccess(NtesukiRecord *record,
209 NtesukiRecord *record_best,
210 int pass_left,
211 unsigned int& success_count,
212 unsigned int& total_count);
213
218 template <Player T> void simulateSiblingsFail(NtesukiRecord *record,
219 NtesukiRecord *record_best,
220 int pass_left,
221 unsigned int& success_count,
222 unsigned int& total_count);
226 template <Player T> void handleNonAttack(NtesukiRecord *record,
227 int pass_left);
231 template <Player T> void handleTonshi(NtesukiRecord *record,
232 int pass_left,
233 const Move last_move);
237 template <Player T> void handleInterpose(NtesukiRecord *record,
238 int pass_left);
239
240 public:
241 /* ======================
242 * 外から呼ばれる関数
243 */
244 NtesukiSearcher(State& state,
245 NtesukiMoveGenerator *mg,
246 unsigned int table_limit,
247 volatile int *stop_flag,
248 bool verbose,
249 int maxPass = NtesukiRecord::SIZE,
250 NtesukiRecord::IWScheme iwscheme = NtesukiRecord::pn_iw,
251 NtesukiRecord::PSScheme psscheme = NtesukiRecord::no_ps,
252 NtesukiRecord::ISScheme isscheme = NtesukiRecord::no_is,
253 int tsumero_cost = 0,
254 int tsumero_estimate = 0,
255 double gc_ratio = 0.33);
256 ~NtesukiSearcher();
257
258
259 template <Player T> int search();
260
261 int searchSlow(Player attacker, int rnl = 160000)
262 {
263 read_node_limit = rnl;
264 if (attacker == BLACK)
265 return search<BLACK>();
266 else
267 return search<WHITE>();
268 }
269
270 NtesukiTable& getTable();
271 int getNodeCount() const { return node_count; }
272 bool exceedReadNodeLimit() const {return node_count > read_node_limit;}
273
274 };
275 } //ntesuki
276 } //osl
277
278 #endif /* _NTESUKI_SEACHER_H */
279 // ;;; Local Variables:
280 // ;;; mode:c++
281 // ;;; c-basic-offset:2
282 // ;;; End: