ntesukiRecord.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ntesukiRecord.cc
Go to the documentation of this file.
1 #include "osl/ntesuki/ntesukiRecord.h"
2 #include "osl/ntesuki/ntesukiRecord.tcc"
3 #include "osl/player.h"
4 #include <iostream>
5 #include <algorithm>
6
7
8 unsigned int osl::ntesuki::NtesukiRecord::
9 fixed_search_depth = 0;
10
11 unsigned int osl::ntesuki::NtesukiRecord::
12 inversion_cost = 0;
13
14 bool osl::ntesuki::NtesukiRecord::
15 use_dominance = false;
16
17 osl::ntesuki::NtesukiTable *
18 osl::ntesuki::NtesukiRecord::table = NULL;
19
20 osl::NumEffectState *
21 osl::ntesuki::NtesukiRecord::state = NULL;
22
23 osl::ntesuki::NtesukiMoveGenerator *
24 osl::ntesuki::NtesukiRecord::mg = NULL;
25
26 int osl::ntesuki::NtesukiRecord::
27 pass_count = 0;
28
29 bool osl::ntesuki::NtesukiRecord::
30 max_for_split = false;
31
32 bool osl::ntesuki::NtesukiRecord::
33 use_rzone_move_generation= false;
34
35 bool osl::ntesuki::NtesukiRecord::
36 delay_lame_long = false;
37
38 bool osl::ntesuki::NtesukiRecord::
39 use_9rzone = false;
40
41 unsigned int osl::ntesuki::NtesukiRecord::
42 split_count = 0;
43
44 unsigned int osl::ntesuki::NtesukiRecord::
45 confluence_count = 0;
46
47 /* constructor
48 */
49 osl::ntesuki::NtesukiRecord::
50 NtesukiRecord(signed short distance,
51 const HashKey& key,
52 const PieceStand& white_stand,
53 RecordList* same_board_list)
54 : black_stand(key.getPieceStand()), white_stand(white_stand),
55 distance(distance), key(key), same_board_list(same_board_list),
56 rev_refcount(0),
57 child_count(0), read_count(0), written_count(0),
58 visited(false), by_simulation(false),
59 by_fixed_black(false), by_fixed_white(false),
60 already_set_up(false),
61 final(false), is_split(false),
62 do_oracle_attack(true),
63 do_oracle_aunt(true),
64 rzone_move_generation(use_rzone_move_generation)
65 {
66 std::fill(values_black.begin(), values_black.end(), ProofDisproof(1, 1));
67 std::fill(values_white.begin(), values_white.end(), ProofDisproof(1, 1));
68
69 std::fill(read_interpose.begin(), read_interpose.end(), false);
70 std::fill(read_check_defense.begin(), read_check_defense.end(), false);
71 std::fill(read_non_attack.begin(), read_non_attack.end(), false);
72
73 std::fill(is_ntesuki_black.begin(), is_ntesuki_black.end(), false);
74 std::fill(is_ntesuki_white.begin(), is_ntesuki_white.end(), false);
75
76 std::fill(propagated_oracle_black.begin(), propagated_oracle_black.end(), false);
77 std::fill(propagated_oracle_white.begin(), propagated_oracle_white.end(), false);
78
79 std::fill(use_old_black.begin(), use_old_black.end(), false);
80 std::fill(use_old_white.begin(), use_old_white.end(), false);
81
82 if (use_dominance)
83 {
84 lookup_same_board_list();
85 }
86 }
87
88 void
89 osl::ntesuki::NtesukiRecord::
90 updateWithChild(osl::ntesuki::NtesukiRecord* child,
91 int pass_left)
92 {
93 for (unsigned int i = pass_left; i < SIZE; i++)
94 {
95 rzone<BLACK>()[i].update(child->rzone<BLACK>()[i]);
96 rzone<WHITE>()[i].update(child->rzone<WHITE>()[i]);
97 }
98 }
99 void
100 osl::ntesuki::NtesukiRecord::
101 lookup_same_board_list()
102 {
103 for (RecordList::iterator it = same_board_list->begin();
104 it != same_board_list->end(); it++)
105 {
106 if (&(*it) == this) continue;
107
108 for (size_t pass_left = 0; pass_left < SIZE; pass_left++)
109 {
110 if (isDominatedByProofPieces<BLACK>(&(*it), pass_left))
111 {
112 PieceStand ps = it->getPDPieces<BLACK>(pass_left);
113 TRY_DFPN;
114 setResult<BLACK>(pass_left, it->getValue<BLACK>(pass_left),
115 it->getBestMove<BLACK>(pass_left), false, &ps);
116 CATCH_DFPN;
117 return;
118 }
119 else if (isDominatedByProofPieces<WHITE>(&(*it), pass_left))
120 {
121 PieceStand ps = it->getPDPieces<WHITE>(pass_left);
122 TRY_DFPN;
123 setResult<WHITE>(pass_left, it->getValue<WHITE>(pass_left),
124 it->getBestMove<WHITE>(pass_left), false, &ps);
125 CATCH_DFPN;
126 return;
127 }
128 }
129 for (int pass_left = (int)SIZE - 1; pass_left >= 0; pass_left--)
130 {
131 if (isDominatedByDisproofPieces<BLACK>(&(*it), pass_left))
132 {
133 PieceStand ps = it->getPDPieces<BLACK>(pass_left);
134 TRY_DFPN;
135 setResult<BLACK>(pass_left, it->getValue<BLACK>(pass_left),
136 it->getBestMove<BLACK>(pass_left), false, &ps);
137 CATCH_DFPN;
138 return;
139 }
140 else if (isDominatedByDisproofPieces<WHITE>(&(*it), pass_left))
141 {
142 PieceStand ps = it->getPDPieces<WHITE>(pass_left);
143 const NtesukiMove& best_move = it->getBestMove<WHITE>(pass_left);
144 TRY_DFPN;
145 setResult<WHITE>(pass_left, it->getValue<WHITE>(pass_left),
146 best_move, false, &ps);
147 CATCH_DFPN;
148 return;
149 }
150 }
151 }
152 }
153
154
155 /* =============================================================================
156 * 'slow' accessors
157 */
158 const osl::ntesuki::NtesukiResult
159 osl::ntesuki::NtesukiRecord::
160 getValueSlow(const Player player, int i) const
161 {
162 if (BLACK == player)
163 return values<BLACK>()[i];
164 else
165 return values<WHITE>()[i];
166 }
167
168 const osl::ntesuki::NtesukiResult
169 osl::ntesuki::NtesukiRecord::
170 getValueOfTurn(int i) const
171 {
172 return getValueSlow(turn(), i);
173 }
174
175 const osl::ntesuki::NtesukiResult
176 osl::ntesuki::NtesukiRecord::
177 valueBeforeFinal() const
178 {
179 return value_before_final;
180 }
181
182 const osl::ntesuki::NtesukiMove&
183 osl::ntesuki::NtesukiRecord::
184 getBestMoveSlow(Player P, int i) const
185 {
186 if (BLACK == P)
187 return getBestMove<BLACK>(i);
188 else
189 return getBestMove<WHITE>(i);
190 }
191
192 bool
193 osl::ntesuki::NtesukiRecord::
194 isByFixedSlow(Player P) const
195 {
196 if (P == BLACK)
197 return isByFixed<BLACK>();
198 else
199 return isByFixed<WHITE>();
200 }
201
202 osl::PieceStand
203 osl::ntesuki::NtesukiRecord::
204 getPDPiecesSlow(Player p, int pass_left) const
205 {
206 if (p == BLACK)
207 return pdpieces<BLACK>()[pass_left];
208 else
209 return pdpieces<WHITE>()[pass_left];
210 }
211
212 /* =============================================================================
213 * explicit instantiation
214 */
215 namespace osl
216 {
217 namespace ntesuki
218 {
219 template
220 void NtesukiRecord::
221 setResult<BLACK>(int i,
222 const NtesukiResult& r,
223 const NtesukiMove& m,
224 bool bs,
225 const PieceStand* ps);
226 template
227 void NtesukiRecord::
228 setResult<WHITE>(int i,
229 const NtesukiResult& r,
230 const NtesukiMove& m,
231 bool bs,
232 const PieceStand* ps);
233
234 template
235 bool NtesukiRecord::
236 setUpNode<BLACK>();
237
238 template
239 bool NtesukiRecord::
240 setUpNode<WHITE>();
241
242 template
243 void NtesukiRecord::
244 generateMoves<BLACK>(NtesukiMoveList& moves,
245 int pass_left,
246 bool all_moves);
247
248 template
249 void NtesukiRecord::
250 generateMoves<WHITE>(NtesukiMoveList& moves,
251 int pass_left,
252 bool all_moves);
253
254 template
255 bool NtesukiRecord::
256 isNtesuki<BLACK>(int pass_left) const;
257
258 template
259 bool NtesukiRecord::
260 isNtesuki<WHITE>(int pass_left) const;
261
262 template
263 void NtesukiRecord::
264 setNtesuki<BLACK>(int pass_left);
265
266 template
267 void NtesukiRecord::
268 setNtesuki<WHITE>(int pass_left);
269
270 template
271 bool NtesukiRecord::
272 hasTriedPropagatedOracle<BLACK>(int pass_left) const;
273
274 template
275 bool NtesukiRecord::
276 hasTriedPropagatedOracle<WHITE>(int pass_left) const;
277
278 template
279 void NtesukiRecord::
280 triedPropagatedOracle<BLACK>(int pass_left);
281
282 template
283 void NtesukiRecord::
284 triedPropagatedOracle<WHITE>(int pass_left);
285
286 template
287 bool NtesukiRecord::
288 useOld<BLACK>(int pass_left) const;
289
290 template
291 bool NtesukiRecord::
292 useOld<WHITE>(int pass_left) const;
293
294 template
295 void NtesukiRecord::
296 setUseOld<BLACK>(int pass_left, bool b);
297
298 template
299 void NtesukiRecord::
300 setUseOld<WHITE>(int pass_left, bool b);
301
302 template
303 PieceStand NtesukiRecord::
304 getPDPieces<BLACK>(int pass_left) const;
305
306 template
307 PieceStand NtesukiRecord::
308 getPDPieces<WHITE>(int pass_left) const;
309
310 template
311 void NtesukiRecord::
312 setPDPieces<BLACK>(int pass_left,
313 const PieceStand p);
314 template
315 void NtesukiRecord::
316 setPDPieces<WHITE>(int pass_left,
317 const PieceStand p);
318
319 template
320 bool NtesukiRecord::
321 isLoopWithPath<BLACK>(int pass_left,
322 const PathEncoding& path) const;
323 template
324 bool NtesukiRecord::
325 isLoopWithPath<WHITE>(int pass_left,
326 const PathEncoding& path) const;
327
328 template
329 void NtesukiRecord::
330 setLoopWithPath<BLACK>(int pass_left,
331 const PathEncoding& path);
332
333 template
334 void NtesukiRecord::
335 setLoopWithPath<WHITE>(int pass_left,
336 const PathEncoding& path);
337
338 template
339 const NtesukiResult NtesukiRecord::
340 getValueWithPath<BLACK>(int max_pass_left, const PathEncoding path) const;
341
342 template
343 const NtesukiResult NtesukiRecord::
344 getValueWithPath<WHITE>(int max_pass_left, const PathEncoding pat) const;
345
346 template
347 const NtesukiResult NtesukiRecord::
348 getValueOr<BLACK>(int max_pass_left, const PathEncoding path,
349 IWScheme iwscheme) const;
350
351 template
352 const NtesukiResult NtesukiRecord::
353 getValueOr<WHITE>(int max_pass_left, const PathEncoding pat,
354 IWScheme iwscheme) const;
355
356 template
357 const NtesukiResult NtesukiRecord::
358 getValueAnd<BLACK>(int max_pass_left, const PathEncoding pat,
359 IWScheme iwscheme, PSScheme psscheme) const;
360
361 template
362 const NtesukiResult NtesukiRecord::
363 getValueAnd<WHITE>(int max_pass_left, const PathEncoding pat,
364 IWScheme iwscheme, PSScheme psscheme) const;
365
366
367 std::ostream&
368 operator<<(std::ostream& os, const NtesukiRecord& record)
369 {
370 os << "player:\t" << record.key.turn() << "\n"
371 << "visited:\t" << record.isVisited() << "\n"
372 << "distance:\t" << record.distance << "\n"
373 << "subtree:\t" << record.getChildCount() << "\n"
374 << record.key << "\nBS"
375 << record.black_stand << "\nWS"
376 << record.white_stand << "\n";
377
378
379 for(size_t i = 0; i < NtesukiRecord::SIZE; ++i)
380 {
381 os << i << " B\tmove("
382 << record.getBestMove<BLACK>(i) << ")\t"
383 << record.getValue<BLACK>(i) << "\tdom("
384 << record.getPDPieces<BLACK>(i)
385 << "\n"
386 << i << " W\tmove("
387 << record.getBestMove<WHITE>(i) << ")\t"
388 << record.getValue<WHITE>(i) << "\tdom("
389 << record.getPDPieces<WHITE>(i)
390 << "\n";
391 }
392
393 return os;
394 }
395
396 std::ostream&
397 operator<<(std::ostream& os,
398 const NtesukiRecord::IWScheme& s)
399 {
400 switch (s)
401 {
402 case NtesukiRecord::no_iw: os << "no_widening";
403 break;
404 case NtesukiRecord::strict_iw: os << "iterative_widening";
405 break;
406 case NtesukiRecord::pn_iw: os << "pnbased_widening";
407 break;
408 default:
409 throw std::runtime_error("cannot parse string");
410 }
411 return os;
412 }
413
414 std::istream&
415 operator>>(std::istream& is,
416 NtesukiRecord::IWScheme& s)
417 {
418 std::string token;
419 is >> token;
420
421 switch (token[0])
422 {
423 case 'n':
424 s = NtesukiRecord::no_iw;
425 break;
426 case 'i':
427 s = NtesukiRecord::strict_iw;
428 break;
429 case 'p':
430 s = NtesukiRecord::pn_iw;
431 break;
432 default:
433 throw std::runtime_error("cannot parse string");
434 }
435 return is;
436 }
437
438 std::ostream&
439 operator<<(std::ostream& os,
440 const NtesukiRecord::PSScheme& s)
441 {
442 switch (s)
443 {
444 case NtesukiRecord::no_ps: os << "single_lambda";
445 break;
446 case NtesukiRecord::pn_ps: os << "dual_lambda";
447 break;
448 default:
449 throw std::runtime_error("cannot parse string");
450 }
451 return os;
452 }
453
454 std::istream&
455 operator>>(std::istream& is,
456 NtesukiRecord::PSScheme& s)
457 {
458 std::string token;
459 is >> token;
460
461 switch (token[0])
462 {
463 case 'n':
464 case 's':
465 s = NtesukiRecord::no_ps;
466 break;
467 case 'p':
468 case 'd':
469 s = NtesukiRecord::pn_ps;
470 break;
471 default:
472 throw std::runtime_error("cannot parse string");
473 }
474 return is;
475 }
476
477 std::ostream&
478 operator<<(std::ostream& os,
479 const NtesukiRecord::ISScheme& s)
480 {
481 switch (s)
482 {
483 case NtesukiRecord::no_is: os << "katagyoku";
484 break;
485 case NtesukiRecord::tonshi_is: os << "tonshi-only";
486 break;
487 case NtesukiRecord::delay_is: os << "delay-inversion";
488 break;
489 case NtesukiRecord::normal_is: os << "full-inversion";
490 break;
491 default:
492 throw std::runtime_error("cannot parse string");
493 }
494
495 return os;
496 }
497
498 std::istream&
499 operator>>(std::istream& is,
500 NtesukiRecord::ISScheme& s)
501 {
502 std::string token;
503 is >> token;
504
505 switch (token[0])
506 {
507 case 'n':
508 s = NtesukiRecord::no_is;
509 break;
510 case 't':
511 s = NtesukiRecord::tonshi_is;
512 break;
513 case 'd':
514 s = NtesukiRecord::delay_is;
515 break;
516 case 'f':
517 s = NtesukiRecord::normal_is;
518 break;
519 default:
520 throw std::runtime_error("cannot parse string");
521 }
522 return is;
523 }
524
525 }
526 }