Debian Codegraph @

old-sample/legacy-checkmate/test/oracleDisprover.t.cc

raw
1 /* oracleDisproverTest.cc
2 */
3 #include "osl/checkmate/oracleDisprover.h"
4 #include "osl/checkmate/dualCheckmateSearcher.h"
5 #include "osl/checkmate/analyzer/checkTableAnalyzer.h"
6 #include "osl/checkmate/checkmateRecorder.h"
7 #include "osl/state/hashEffectState.h"
8 #include "osl/record/csaString.h"
9
10 #include <cppunit/TestCase.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <fstream>
13
14 class OracleDisproverTest : public CppUnit::TestFixture
15 {
16 CPPUNIT_TEST_SUITE(OracleDisproverTest);
17 CPPUNIT_TEST(testNoCheckLong);
18 CPPUNIT_TEST(testAdjustAttack);
19 CPPUNIT_TEST(testPawnCheckmate);
20 CPPUNIT_TEST(testPawnCheckmateLose);
21 CPPUNIT_TEST(testDistance);
22 CPPUNIT_TEST(testNoCheck);
23 CPPUNIT_TEST(testCheck);
24 CPPUNIT_TEST(testAdjustMove);
25 CPPUNIT_TEST_SUITE_END();
26 public:
27 void testDistance();
28 void testAdjustMove();
29 void testAdjustAttack();
30 void testNoCheck();
31 void testNoCheckLong();
32 void testCheck();
33 void testPawnCheckmate();
34 void testPawnCheckmateLose();
35 };
36 CPPUNIT_TEST_SUITE_REGISTRATION(OracleDisproverTest);
37
38 using namespace osl;
39 using namespace osl::checkmate;
40 extern bool isShortTest;
41 const size_t limit = 400000;
42
43 template <class Table, class State>
44 static void logNoCheckmate(Table& table, State& state2,
45 const PathEncoding& path,
46 const CheckHashRecord *record,
47 const PathEncoding& path2)
48 {
49 CheckmateRecorder::DepthTracer::maxVerboseLogDepth = 20;
50 OracleDisprover<Table> disprover(table);
51 disprover.proofNoCheckmate(state2, path, record, path2);
52 CheckmateRecorder::DepthTracer::maxVerboseLogDepth = 1;
53 }
54
55 void OracleDisproverTest::testDistance()
56 {
57 // bug 35
58 SimpleState sstate=CsaString(
59 "P1 * * * * * * * -OU * \n"
60 "P2 * * * * * * * * * \n"
61 "P3 * * * * * * * +FU * \n"
62 "P4 * * * * * * * * * \n"
63 "P5 * * * * * * * * * \n"
64 "P6 * * * * * * * * * \n"
65 "P7 * * * * * * * * * \n"
66 "P8 * * * * * * * * * \n"
67 "P9 * * +OU * * * * * * \n"
68 "P-00AL\n"
69 "+\n").getInitialState();
70 HashEffectState state(sstate);
71 const int distance = 3;
72 const PathEncoding path(BLACK, distance);
73 DualCheckmateSearcher<> checker(limit);
74 checker.setVerbose(!isShortTest);
75 Move check_move = Move::INVALID();
76 AttackOracleAges oracle_age;
77 const bool win = checker.isWinningState<BLACK>(100, state, state.getHash(),
78 path, check_move, oracle_age);
79 CPPUNIT_ASSERT_EQUAL(false, win);
80
81 SimpleState sstate_similar=CsaString(
82 "P1 * * * * * * * -OU * \n"
83 "P2 * * * * * * * * * \n"
84 "P3 * * * * * * -FU+FU * \n"
85 "P4 * * * * * * * * * \n"
86 "P5 * * * * * * * * * \n"
87 "P6 * * * * * * * * * \n"
88 "P7 * * * * * * * * * \n"
89 "P8 * * * * * * * * * \n"
90 "P9 * * +OU * * * * * * \n"
91 "P-00AL\n"
92 "+\n").getInitialState();
93 HashEffectState state_similar(sstate_similar);
94
95 CheckHashTable& table = checker.getTable(BLACK);
96 OracleDisprover<CheckHashTable> disprover(table);
97 const CheckHashRecord *record = table.find(state.getHash());
98 DisproofOracleAttack<BLACK> oracle(record);
99
100 const int distance_similar = 30;
101 const PathEncoding path_similar(BLACK, distance_similar);
102 const bool result =
103 disprover.proofNoCheckmate(state_similar, state_similar.getHash(),
104 path_similar, oracle);
105 CPPUNIT_ASSERT_EQUAL(true, result);
106
107 const CheckHashRecord *record_similar = table.find(state_similar.getHash());
108 CPPUNIT_ASSERT_EQUAL(distance, static_cast<int>(record->distance));
109 CPPUNIT_ASSERT_EQUAL(distance_similar, static_cast<int>(record_similar->distance));
110 }
111
112 void OracleDisproverTest::testAdjustMove()
113 {
114 SimpleState sstate=CsaString(
115 "P1 * * * * * * * -OU * \n"
116 "P2 * * * * * * * +NK * \n"
117 "P3 * * * * * * * * * \n"
118 "P4 * * * * * * * * * \n"
119 "P5 * * * * * * * * * \n"
120 "P6 * * * * * * * * * \n"
121 "P7 * * * * * * * * * \n"
122 "P8 * * * * * * * * * \n"
123 "P9 * +OU * * * * * * * \n"
124 "P-00AL\n"
125 "-\n").getInitialState();
126 HashEffectState state(sstate);
127 const PathEncoding path(WHITE);
128 const Move last_move = Move(Square(3,4), Square(2,2),
129 PKNIGHT, PTYPE_EMPTY, true, BLACK);
130 DualCheckmateSearcher<> checker(limit);
131 checker.setVerbose(!isShortTest);
132 CheckHashTable& table = checker.getTable(BLACK);
133 AttackOracleAges oracle_age;
134 const bool lose = checker.isLosingState<WHITE>
135 (500, state, state.getHash(), path, last_move);
136 CPPUNIT_ASSERT(! lose);
137 CheckHashRecord *record = table.find(state.getHash());
138 CPPUNIT_ASSERT(record);
139 DisproofOracleDefense<BLACK> oracle(record);
140
141 // 取る駒が違っても詰まない
142 SimpleState sstate2=CsaString(
143 "P1 * * * * * * * -OU * \n"
144 "P2 * * * * * * * +KI * \n"
145 "P3 * * * * * * * * * \n"
146 "P4 * * * * * * * * * \n"
147 "P5 * * * * * * * * * \n"
148 "P6 * * * * * * * * * \n"
149 "P7 * * * * * * * * * \n"
150 "P8 * * * * * * * * * \n"
151 "P9 * +OU * * * * * * * \n"
152 "P-00AL\n"
153 "-\n").getInitialState();
154 HashEffectState state2(sstate2);
155
156 OracleDisprover<CheckHashTable> disprover(table);
157 Move escape_move;
158 const bool result =
159 disprover.proofEscape(state2, state2.getHash(),
160 path, oracle, escape_move, last_move);
161 CPPUNIT_ASSERT_EQUAL(true, result);
162 CPPUNIT_ASSERT_EQUAL(Square(2,1), escape_move.from());
163 CPPUNIT_ASSERT_EQUAL(Square(2,2), escape_move.to());
164 CPPUNIT_ASSERT_EQUAL(GOLD, escape_move.capturePtype());
165 }
166
167 void OracleDisproverTest::testAdjustAttack()
168 {
169 SimpleState sstate=CsaString(
170 "P1 * * * * * * +HI-KI-OU\n"
171 "P2 * * * * * * * -KE-KI\n"
172 "P3 * * * * * * * * * \n"
173 "P4 * * * * * * * * * \n"
174 "P5 * * * * * * * * * \n"
175 "P6 * * * * * * * * * \n"
176 "P7 * * * * * * * * * \n"
177 "P8 * * * * * * * * * \n"
178 "P9 * +OU * * * * * * * \n"
179 "P-00AL\n"
180 "+\n").getInitialState();
181 HashEffectState state(sstate);
182 const PathEncoding path(BLACK);
183 DualCheckmateSearcher<> checker(limit);
184 checker.setVerbose(!isShortTest);
185 CheckHashTable& table = checker.getTable(BLACK);
186 Move check_move;
187 AttackOracleAges oracle_age;
188 const bool win = checker.isWinningState<BLACK>(500, state, state.getHash(), path, check_move,
189 oracle_age);
190 CPPUNIT_ASSERT(! win);
191 CheckHashRecord *record = table.find(state.getHash());
192 CPPUNIT_ASSERT(record);
193 CPPUNIT_ASSERT(record->proofDisproof().isCheckmateFail());
194 DisproofOracleAttack<BLACK> oracle(record);
195 OracleDisprover<CheckHashTable> disprover(table);
196
197 // 遠くから王手 + 余計な駒
198 SimpleState sstate2=CsaString(
199 "P1+HI * * * * * * -KI-OU\n"
200 "P2 * * * * * * * -KE-KI\n"
201 "P3 * * * * * * * * * \n"
202 "P4 * * * * * -FU * * * \n"
203 "P5 * * * * * * * * * \n"
204 "P6 * * * * * * * * * \n"
205 "P7 * * * * * * * * * \n"
206 "P8 * * * * * * * * * \n"
207 "P9 * +OU * * * * * * * \n"
208 "P-00AL\n"
209 "+\n").getInitialState();
210 HashEffectState state2(sstate2);
211
212 const bool result =
213 disprover.proofNoCheckmate<BLACK>(state2, state2.getHash(), path, oracle);
214 CPPUNIT_ASSERT_EQUAL(true, result);
215
216 // 龍でもよい,銀を取った後,金の変わりに32に打っても大丈夫
217 SimpleState sstate3=CsaString(
218 "P1 * +RY * * * * * -GI-OU\n"
219 "P2 * * * * * * * -KE-KI\n"
220 "P3 * * * * * * * * * \n"
221 "P4 * * * * * -FU * * * \n"
222 "P5 * * * * * -KY * * * \n"
223 "P6 * * * * * * * * * \n"
224 "P7 * * * * * * * * * \n"
225 "P8 * * * * * * * * * \n"
226 "P9 * +OU * * * * * * * \n"
227 "P-00AL\n"
228 "+\n").getInitialState();
229 HashEffectState state3(sstate3);
230
231 const bool result3 =
232 disprover.proofNoCheckmate<BLACK>(state3, state3.getHash(),
233 path, oracle);
234 CPPUNIT_ASSERT_EQUAL(true, result3);
235
236 // 角だと?
237 SimpleState sstate4=CsaString(
238 "P1 * * * * * * * -GI-OU\n"
239 "P2 * * * * * * * -KE-KI\n"
240 "P3 * * * * * +KA * * * \n"
241 "P4 * * * * * -FU * * * \n"
242 "P5 * * * * * -KY * * * \n"
243 "P6 * * * * * -KE * * * \n"
244 "P7 * * * * * * * * * \n"
245 "P8 * * * * * * * * * \n"
246 "P9 * +OU * * * * * * * \n"
247 "P-00AL\n"
248 "+\n").getInitialState();
249 HashEffectState state4(sstate4);
250
251 const bool result4 =
252 disprover.proofNoCheckmate<BLACK>(state4, state4.getHash(),
253 path, oracle);
254 CPPUNIT_ASSERT_EQUAL(true, result4);
255 }
256
257 void OracleDisproverTest::testCheck()
258 {
259 SimpleState sstate=CsaString(
260 "P1 * * * * * * * -OU * \n"
261 "P2 * * * * * * * +NK * \n"
262 "P3 * * * * * * * * * \n"
263 "P4 * * * * * * * * * \n"
264 "P5 * * * * * * * * * \n"
265 "P6 * * * * * * * * * \n"
266 "P7 * * * * * * * * * \n"
267 "P8 * * * * * * * * * \n"
268 "P9 * +OU * * * * * * * \n"
269 "P-00AL\n"
270 "-\n").getInitialState();
271 HashEffectState state(sstate);
272 const PathEncoding path(WHITE);
273 const Move last_move = Move(Square(3,4), Square(2,2),
274 PKNIGHT, PTYPE_EMPTY, true, BLACK);
275 DualCheckmateSearcher<> checker(limit);
276 checker.setVerbose(!isShortTest);
277 CheckHashTable& table = checker.getTable(BLACK);
278 const bool lose = checker.isLosingState<WHITE>
279 (500, state, state.getHash(), path, last_move);
280 CPPUNIT_ASSERT(! lose);
281 CheckHashRecord *record = table.find(state.getHash());
282 CPPUNIT_ASSERT(record);
283 DisproofOracleDefense<BLACK> oracle(record);
284
285 // 取る駒が違っても詰まない
286 SimpleState sstate2=CsaString(
287 "P1 * * * * * * * -OU * \n"
288 "P2 * * * * * * * +NK * \n"
289 "P3 * * * * * * * +FU * \n"
290 "P4 * * * * * * * * * \n"
291 "P5 * * * * * * * * * \n"
292 "P6 * * * * * * * * * \n"
293 "P7 * * * * * * * * * \n"
294 "P8 * * * * * * * * * \n"
295 "P9 * +OU * * * * * * * \n"
296 "P-00AL\n"
297 "-\n").getInitialState();
298 HashEffectState state2(sstate2);
299
300 OracleDisprover<CheckHashTable> disprover(table);
301 Move escape_move;
302 const bool result =
303 disprover.proofEscape(state2, state2.getHash(),
304 path, oracle, escape_move, last_move);
305 CPPUNIT_ASSERT_EQUAL(false, result);
306 }
307
308 void OracleDisproverTest::testNoCheck()
309 {
310 SimpleState sstate=CsaString(
311 "P1 * * * * * * * -OU * \n"
312 "P2 * * * * * * * +NK * \n"
313 "P3 * * * * * * * * * \n"
314 "P4 * * * * * * * * * \n"
315 "P5 * * * * * * * * * \n"
316 "P6 * * * * * * * * * \n"
317 "P7 * * * * * * * * * \n"
318 "P8 * * * * * * * * * \n"
319 "P9 * +OU * * * * * * * \n"
320 "P-00AL\n"
321 "-\n").getInitialState();
322 HashEffectState state(sstate);
323 const PathEncoding path(WHITE);
324 const Move last_move = Move(Square(3,4), Square(2,2),
325 PKNIGHT, PTYPE_EMPTY, true, BLACK);
326 DualCheckmateSearcher<> checker(limit);
327 checker.setVerbose(!isShortTest);
328 CheckHashTable& table = checker.getTable(BLACK);
329 const bool lose = checker.isLosingState<WHITE>
330 (500, state, state.getHash(), path, last_move);
331 CPPUNIT_ASSERT(! lose);
332 CheckHashRecord *record = table.find(state.getHash());
333 CPPUNIT_ASSERT(record);
334 DisproofOracleDefense<BLACK> oracle(record);
335
336 SimpleState sstate2=CsaString(
337 "P1 * * * * * * * -OU * \n"
338 "P2 * * * * * * * +KI * \n"
339 "P3 * * * * * +FU * * * \n"
340 "P4 * * * * * * * * * \n"
341 "P5 * * * * * * * * * \n"
342 "P6 * * * * * * * * * \n"
343 "P7 * * * * * * * * * \n"
344 "P8 * * * * * * * * * \n"
345 "P9 * +OU * * * * * * * \n"
346 "P-00AL\n"
347 "-\n").getInitialState();
348 HashEffectState state2(sstate2);
349
350 OracleDisprover<CheckHashTable> disprover(table);
351 Move escape_move;
352 const bool result =
353 disprover.proofEscape(state2, state2.getHash(),
354 path, oracle, escape_move, last_move);
355 CPPUNIT_ASSERT(result);
356 CPPUNIT_ASSERT_EQUAL(escape_move.from(), Square(2,1));
357 CPPUNIT_ASSERT_EQUAL(escape_move.to(), Square(2,2));
358 }
359
360 static bool isNoCheckmate(const char *org, const char *similar)
361 {
362 HashEffectState state(CsaString(org).getInitialState());
363
364 const size_t limit = 100000;
365 DualCheckmateSearcher<> checker(limit);
366 checker.setVerbose(!isShortTest);
367 CheckHashTable& table = checker.getTable(state.turn());
368 Move check_move;
369 const PathEncoding path(state.turn());
370 AttackOracleAges oracle_age;
371 const bool win = checker.isWinningState(limit, state, state.getHash(), path, check_move,
372 oracle_age);
373 CPPUNIT_ASSERT(! win);
374 const CheckHashRecord *record = table.find(state.getHash());
375 CPPUNIT_ASSERT(record);
376 CPPUNIT_ASSERT(record->proofDisproof().isCheckmateFail()
377 || record->findLoop(path, table.getTwinTable()));
378 CheckTableAnalyzer analyzer(table.getTwinTable());
379 CPPUNIT_ASSERT(analyzer.disproofTreeSize(record, state.getHash(), path, false));
380
381 HashEffectState state2(CsaString(similar).getInitialState());
382 OracleDisprover<CheckHashTable> disprover(table);
383
384 PathEncoding path2(alt(state2.turn()));
385 path2.pushMove(Move(Square(5,5),PAWN,alt(state2.turn())));
386 CPPUNIT_ASSERT(path != path2);
387
388 const bool result = disprover.proofNoCheckmate(state2, path2, record, path);
389 if (result)
390 {
391 const HashKey& key2 = state2.getHash();
392 const CheckHashRecord *record2 = table.find(key2);
393 const size_t tree_size = analyzer.disproofTreeSize(record2, key2, path2, false);
394 CPPUNIT_ASSERT(tree_size);
395 }
396 if ((! result) && (! isShortTest))
397 {
398 CheckTableAnalyzer analyzer(table.getTwinTable());
399 std::ofstream os("oracleDisproverTest.log");
400 analyzer.showProofTree(record,state2.getHash(),path,false,os);
401 logNoCheckmate(table, state2, path, record, path);
402 }
403 return result;
404 }
405
406 void OracleDisproverTest::testNoCheckLong()
407 {
408 // この辺のテストがfail したら。
409 // - -DCHECKMATE_DEBUG つきでコンパイル
410 // - CheckmateRecorder::maxVerboseLogDepth あたりを増やす
411 // - 該当テスト以外を #if 0 で囲み、oracleDiprover.t を実行
412 // - simplationのログが test/checkmate.log に、
413 // simulationのお手本が、同/oracleDisproverTest.log に出来ているので比較
414 // - emacs で開くと、outline-mode になっている/自分でする必要がある。
415 // ファイルが大きい場合は、font-lock-mode をoffに。
416 // - C-c d 閉じる C-c i 1レベル開く
417 // - 局面が違うせいで思わぬ王手が現れていたら問題が悪い:(
418 CPPUNIT_ASSERT(! isNoCheckmate(
419 "P1-OU-KE * * * * * +UM * \n"
420 "P2 * -KI+NK * * * * * * \n"
421 "P3 * * * +TO * * * -FU-FU\n"
422 "P4-KY * -FU * -FU * -HI * * \n"
423 "P5-FU-FU * * * * -GI+FU * \n"
424 "P6 * * +KI * -NK-FU-FU * +FU\n"
425 "P7 * +FU * * * * * * * \n"
426 "P8 * +GI * -FU * * * * * \n"
427 "P9+KY+OU+GI * * * -UM * +KY\n"
428 "P+00FU00GI\n"
429 "P-00FU00FU00FU00FU00KE00KI00KI00KY00HI\n"
430 "+\n",
431 // これは一瞬で詰むダミー
432 "P1-OU-KE * * * * * +UM * \n"
433 "P2 * * +NK * * * * * * \n"
434 "P3+FU * * +TO * * * -FU-FU\n"
435 "P4-KY * -FU * -FU * -HI * * \n"
436 "P5-FU-FU * * * * -GI+FU * \n"
437 "P6 * * +KI * -NK-FU-FU * +FU\n"
438 "P7 * +FU * * * * * * * \n"
439 "P8 * +GI+GI-FU * * * * * \n"
440 "P9+KY+OU * * * * -UM * +KY\n"
441 "P+00FU00GI\n"
442 "P-00FU00FU00FU00KE00KI00KI00KY00HI00KI\n"
443 "+\n"));
444 CPPUNIT_ASSERT(isNoCheckmate(
445 "P1-OU-KE * * * * * +UM * \n"
446 "P2 * -KI+NK * * * * * * \n"
447 "P3 * * * +TO * * * -FU-FU\n"
448 "P4-KY * -FU * -FU * -HI * * \n"
449 "P5-FU-FU * * * * -GI+FU * \n"
450 "P6 * * +KI * -NK-FU-FU * +FU\n"
451 "P7 * +FU * * * * * * * \n"
452 "P8 * +GI * -FU * * * * * \n"
453 "P9+KY+OU+GI * * * -UM * +KY\n"
454 "P+00FU00GI\n"
455 "P-00FU00FU00FU00FU00KE00KI00KI00KY00HI\n"
456 "+\n",
457 "P1-OU-KE * * * * * +UM * \n"
458 "P2 * -KI+NK * * * * * * \n"
459 "P3 * * * +TO * * * -FU-FU\n"
460 "P4-KY * -FU * -FU * -HI * * \n"
461 "P5-FU-FU * * * * -GI+FU * \n"
462 "P6 * * +KI * -NK-FU-FU * +FU\n"
463 "P7 * +FU * * * * * * * \n"
464 "P8 * +GI * -FU * * * * * \n"
465 "P9+KY+OU+GI * -TO * -UM * +KY\n"
466 "P+00FU00GI\n"
467 "P-00FU00FU00FU00KE00KI00KI00KY00HI\n"
468 "+\n"));
469 CPPUNIT_ASSERT(isNoCheckmate(
470 "P1-KY-KE * +KA * -KI-GI-KE-KY\n"
471 "P2 * +HI * -FU * * -OU * * \n"
472 "P3-FU * * * +TO-FU * -FU-FU\n"
473 "P4 * * * * * * -FU * * \n"
474 "P5 * -UM * -RY-FU * * * * \n"
475 "P6 * * * * * * * * * \n"
476 "P7+FU * -TO * * +FU+FU+FU+FU\n"
477 "P8 * * * * +KI * * * +KY\n"
478 "P9+KY * * * * +KI+GI+KE+OU\n"
479 "P-00FU00FU00FU00KE00GI\n"
480 "P+00FU00GI00KI\n"
481 "+\n",
482 "P1-KY-KE * +KA * -KI-GI-KE-KY\n"
483 "P2 * +HI * -FU * * -OU * * \n"
484 "P3-FU * * * +TO-FU * -FU-FU\n"
485 "P4 * * * * * * -FU * * \n"
486 "P5 * -UM * -RY-FU * * * * \n"
487 "P6 * * * * * * * * * \n"
488 "P7+FU * -TO * * +FU+FU+FU+FU\n"
489 "P8 * * * * +KI * * +OU+KY\n"
490 "P9+KY * * * * +KI+GI+KE * \n"
491 "P-00FU00FU00FU00KE00GI\n"
492 "P+00FU00GI00KI\n"
493 "+\n"));
494 CPPUNIT_ASSERT(isNoCheckmate(
495 "P1-KY-KE * * * +KA * -KE-KY\n"
496 "P2 * -HI * * * * -KI-OU * \n"
497 "P3 * * * -FU * -KI-GI-FU-FU\n"
498 "P4-FU * * * -FU-FU-FU * * \n"
499 "P5 * * * * * * * * * \n"
500 "P6+FU * +FU+FU+FU+GI+FU+FU+FU\n"
501 "P7 * +FU * * * +FU+KE * * \n"
502 "P8 * +KI * +KI-UM * * * +KY\n"
503 "P9+KY+KE+OU+HI-GI * * * * \n"
504 "P+00FU00GI\n"
505 "P-00FU\n"
506 "+\n",
507 "P1-KY-KE * * * +KA * -KE-KY\n"
508 "P2 * -HI * * * * -KI-OU * \n"
509 "P3 * * * -FU * -KI-GI-FU-FU\n"
510 "P4-FU * * * -FU-FU-FU * * \n"
511 "P5 * * * * * * * * * \n"
512 "P6+FU * +FU+FU+FU+GI+FU+FU+FU\n"
513 "P7 * +FU * * * +FU+KE * * \n"
514 "P8 * +KI+OU+KI-UM * * * +KY\n"
515 "P9+KY+KE * +HI-GI * * * * \n"
516 "P+00FU00GI\n"
517 "P-00FU\n"
518 "+\n"));
519 CPPUNIT_ASSERT(isNoCheckmate(
520 "P1+TO * * * * -OU * -KE-KY\n"
521 "P2 * -FU-KE * * * -KI-GI * \n"
522 "P3 * * -GI-FU-FU-FU * -FU-FU\n"
523 "P4 * * * * * * * * * \n"
524 "P5 * * * * * * * +FU+FU\n"
525 "P6+KY+OU * +FU+KY+KE-HI * * \n"
526 "P7 * +FU * * +FU+FU+KE * * \n"
527 "P8+KI * * * * * +GI * * \n"
528 "P9 * * * * * +KI * +HI+KY\n"
529 "P-00FU00FU00KA\n"
530 "P+00FU00FU00FU00GI00KI00KA\n"
531 "+\n",
532 "P1+TO * * * * -OU * -KE-KY\n"
533 "P2 * -FU-KE * * * -KI-GI * \n"
534 "P3 * * -GI-FU-FU-FU * -FU-FU\n"
535 "P4 * * * * * * * * * \n"
536 "P5 * * * * * * * +FU+FU\n"
537 "P6+KY+OU * +FU+KY+KE-HI * * \n"
538 "P7 * +FU * * +FU+FU+KE * * \n"
539 "P8+KI * * * * * +GI * * \n"
540 "P9-TO * * * * +KI * +HI+KY\n"
541 "P-00FU00FU00KA\n"
542 "P+00FU00FU00GI00KI00KA\n"
543 "+\n"));
544 CPPUNIT_ASSERT(isNoCheckmate(
545 "P1+NY+RY * * * * -KI-KE-OU\n"
546 "P2+RY-FU * * +NG * -KI-GI-KY\n"
547 "P3 * -KE * * -FU * * -FU-FU\n"
548 "P4-FU-KA * +FU * * -FU * * \n"
549 "P5 * * * * * * * * * \n"
550 "P6+FU+FU * * * -FU * * * \n"
551 "P7 * * * * * * +FU+FU+FU\n"
552 "P8 * * * * * * +GI+OU * \n"
553 "P9 * * * -NK * * +KI+KE+KY\n"
554 "P+00FU00FU00FU00KA\n"
555 "P-00FU00FU00GI00KI00KY\n"
556 "-\n",
557 "P1 * +RY * * * * -KI-KE-OU\n"
558 "P2+RY-FU * * +NG * -KI-GI-KY\n"
559 "P3 * -KE * * -FU * * -FU-FU\n"
560 "P4-FU-KA * +FU * * -FU * * \n"
561 "P5 * * * * * * * * * \n"
562 "P6+FU+FU * * * -FU * * * \n"
563 "P7 * * * * * * +FU+FU+FU\n"
564 "P8 * * * * * * +GI+OU * \n"
565 "P9 * * * -NK * * +KI+KE+KY\n"
566 "P+00FU00FU00FU00KY00KA\n"
567 "P-00FU00FU00GI00KI00KY\n"
568 "-\n"));
569 CPPUNIT_ASSERT(isNoCheckmate(
570 "P1-KY-KE * * * -OU * * -KY\n"
571 "P2 * * * * -KI * -KI-GI * \n"
572 "P3 * * * -FU-GI-FU-KE * * \n"
573 "P4-FU * * * * * * * -FU\n"
574 "P5 * +FU-HI * * * * * * \n"
575 "P6+FU+KA * * +HI * * * +FU\n"
576 "P7 * * * +FU+FU+FU+FU * * \n"
577 "P8 * * +KI * +OU+GI+KI * * \n"
578 "P9+KY * +GI * * * * +KE+KY\n"
579 "P-00FU00FU00FU00FU00KE00KA\n"
580 "P+00FU00FU00FU\n"
581 "-\n",
582 "P1-KY-KE * * * * -OU * -KY\n"
583 "P2 * * * * -KI * -KI-GI * \n"
584 "P3 * * * -FU-GI-FU-KE * * \n"
585 "P4-FU * * * * * * * -FU\n"
586 "P5 * +FU-HI * * * * * * \n"
587 "P6+FU+KA * * +HI * * * +FU\n"
588 "P7 * * * +FU+FU+FU+FU * * \n"
589 "P8 * * +KI * +OU+GI+KI * * \n"
590 "P9+KY * +GI * * * * +KE+KY\n"
591 "P-00FU00FU00FU00FU00KE00KA\n"
592 "P+00FU00FU00FU\n"
593 "-\n"));
594 }
595
596 void OracleDisproverTest::testPawnCheckmate()
597 {
598 SimpleState sstate=CsaString(
599 "P1 * * * * * * -KY-OU-KY\n"
600 "P2 * * * * * * -KE * -KE \n"
601 "P3 * * * * * * * * * \n"
602 "P4 * * * * * * +KE * * \n"
603 "P5 * * * * * * * * * \n"
604 "P6 * * * * * * * * * \n"
605 "P7 * * * * * * * * * \n"
606 "P8 * * * * * * * * * \n"
607 "P9 * +OU * * * * * * * \n"
608 "P+00FU\n"
609 "P-00AL\n"
610 "+\n").getInitialState();
611 HashEffectState state(sstate);
612 const PathEncoding path(BLACK);
613
614 DualCheckmateSearcher<> checker(limit);
615 checker.setVerbose(!isShortTest);
616 CheckHashTable& table = checker.getTable(BLACK);
617 Move check_move = Move::INVALID();
618 AttackOracleAges oracle_age;
619 const bool win = checker.isWinningState<BLACK>(500, state, state.getHash(), path, check_move,
620 oracle_age);
621 CPPUNIT_ASSERT(! win);
622 const CheckHashRecord *record = table.find(state.getHash());
623 CPPUNIT_ASSERT(record);
624 CPPUNIT_ASSERT(record->proofDisproof().isCheckmateFail()
625 || record->findLoop(path, table.getTwinTable()));
626 CPPUNIT_ASSERT((ProofDisproof::PawnCheckmate() == record->proofDisproof())
627 || record->filter.isTarget(MoveFlags::NoPromote));
628 DisproofOracleAttack<BLACK> oracle(record,path);
629
630 SimpleState sstate2=CsaString(
631 "P1 * * * * * * -KY-OU-KY\n"
632 "P2 * * * * * * -KE * -KE \n"
633 "P3 * * * * * +FU * * * \n"
634 "P4 * * * * * * +KE * * \n"
635 "P5 * * * * * * * * * \n"
636 "P6 * * * * * * * * * \n"
637 "P7 * * * * * * * * * \n"
638 "P8 * * * * * * * * * \n"
639 "P9 * +OU * * * * * * * \n"
640 "P+00FU\n"
641 "P-00AL\n"
642 "+\n").getInitialState();
643 HashEffectState state2(sstate2);
644
645 OracleDisprover<CheckHashTable> disprover(table);
646 const bool result =
647 disprover.proofNoCheckmate(state2, state2.getHash(),
648 path, oracle);
649 if (! result)
650 {
651 logNoCheckmate(table, state2, path, record, path);
652 record->dump();
653 }
654 CPPUNIT_ASSERT(result);
655
656 // 同じ手順では打歩詰にならない
657 SimpleState sstate3=CsaString(
658 "P1 * * * * * * * -OU-KY\n"
659 "P2 * * * * * * -KE * -KE \n"
660 "P3 * * * * * +FU * * * \n"
661 "P4 * * * * * * +KE * * \n"
662 "P5 * * * * * * * * * \n"
663 "P6 * * * * * * * * * \n"
664 "P7 * * * * * * * * * \n"
665 "P8 * * * * * * * * * \n"
666 "P9 * +OU * * * * * * * \n"
667 "P+00FU\n"
668 "P-00AL\n"
669 "+\n").getInitialState();
670 HashEffectState state3(sstate3);
671
672 const bool result3 =
673 disprover.proofNoCheckmate(state3, state3.getHash(),
674 path, oracle);
675 CPPUNIT_ASSERT(! result3);
676 }
677
678 void OracleDisproverTest::testPawnCheckmateLose()
679 {
680 SimpleState sstate=CsaString(
681 "P1 * * * * * * -KY * -KY\n"
682 "P2 * * * * * * -KE-OU-KE \n"
683 "P3 * * * * * * * * * \n"
684 "P4 * * * * * * +KE+KI * \n"
685 "P5 * * * * * * * * * \n"
686 "P6 * * * * * * * * * \n"
687 "P7 * * * * * * * * * \n"
688 "P8 * * * * * * * * * \n"
689 "P9 * +OU * * * * * * * \n"
690 "P+00FU\n"
691 "P-00AL\n"
692 "-\n").getInitialState();
693 HashEffectState state(sstate);
694 const PathEncoding path(WHITE);
695 const Move last_move = Move(Square(3,4), PKNIGHT, BLACK);
696 DualCheckmateSearcher<> checker(limit);
697 checker.setVerbose(!isShortTest);
698 CheckHashTable& table = checker.getTable(BLACK);
699 const bool lose = checker.isLosingState<WHITE>
700 (500, state, state.getHash(), path, last_move);
701 CPPUNIT_ASSERT(! lose);
702 CheckHashRecord *record = table.find(state.getHash());
703 CPPUNIT_ASSERT(record);
704 DisproofOracleDefense<BLACK> oracle(record);
705
706 SimpleState sstate2=CsaString(
707 "P1 * * * * * * -KY * -KY\n"
708 "P2 * * * * * * -KE-OU-KE \n"
709 "P3 * * * * * +FU * * * \n"
710 "P4 * * * * * * +KE+KI * \n"
711 "P5 * * * * * * * * * \n"
712 "P6 * * * * * * * * * \n"
713 "P7 * * * * * * * * * \n"
714 "P8 * * * * * * * * * \n"
715 "P9 * +OU * * * * * * * \n"
716 "P+00FU\n"
717 "P-00AL\n"
718 "-\n").getInitialState();
719 HashEffectState state2(sstate2);
720
721 OracleDisprover<CheckHashTable> disprover(table);
722 Move escape_move;
723 const bool result2 =
724 disprover.proofEscape(state2, state2.getHash(),
725 path, oracle, escape_move, last_move);
726 CPPUNIT_ASSERT(result2);
727
728 // 同じ手順では打歩詰にならない
729 SimpleState sstate3=CsaString(
730 "P1 * * * * * * * * -KY\n"
731 "P2 * * * * * * -KE-OU-KE \n"
732 "P3 * * * * * +FU * * * \n"
733 "P4 * * * * * * +KE+KI * \n"
734 "P5 * * * * * * * * * \n"
735 "P6 * * * * * * * * * \n"
736 "P7 * * * * * * * * * \n"
737 "P8 * * * * * * * * * \n"
738 "P9 * +OU * * * * * * * \n"
739 "P+00FU\n"
740 "P-00AL\n"
741 "-\n").getInitialState();
742 HashEffectState state3(sstate3);
743
744 const bool result3 =
745 disprover.proofEscape(state3, state3.getHash(),
746 path, oracle, escape_move, last_move);
747 CPPUNIT_ASSERT(! result3);
748 }
749
750 /* ------------------------------------------------------------------------- */
751 // ;;; Local Variables:
752 // ;;; mode:c++
753 // ;;; c-basic-offset:2
754 // ;;; End: