Debian Codegraph @

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

raw
1 /* sameBoardList.t.cc
2 */
3 #include "osl/checkmate/sameBoardList.h"
4 #include "osl/state/hashEffectState.h"
5 #include "osl/record/csaString.h"
6
7 #include <cppunit/TestCase.h>
8 #include <cppunit/extensions/HelperMacros.h>
9
10 using namespace osl;
11 using namespace osl::checkmate;
12
13 struct SameBoardListTest : public CppUnit::TestFixture
14 {
15 CPPUNIT_TEST_SUITE(SameBoardListTest);
16 CPPUNIT_TEST(testFindIneffectiveDropLoop);
17 CPPUNIT_TEST(testAllocateBlack);
18 CPPUNIT_TEST(testAllocateWhite);
19 CPPUNIT_TEST_SUITE_END();
20
21 void testFindIneffectiveDropLoop();
22 void testAllocateBlack();
23 void testAllocateWhite();
24 };
25 CPPUNIT_TEST_SUITE_REGISTRATION(SameBoardListTest);
26
27 void SameBoardListTest::testFindIneffectiveDropLoop()
28 {
29 SameBoardList l;
30 PieceStand empty, black_silver, white_stand;
31 black_silver.add(SILVER);
32 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(black_silver) == 0);
33 PathEncoding path;
34 size_t counter;
35 CheckHashRecord *black_silverRecord
36 = l.allocate<BLACK>(black_silver, white_stand, path, counter);
37 CPPUNIT_ASSERT(black_silverRecord);
38
39 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(black_silver) == 0);
40 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(empty) == 0);
41 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<WHITE>(black_silver) == 0);
42 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<WHITE>(empty) == 0);
43
44 black_silverRecord->isVisited = true;
45
46 CPPUNIT_ASSERT(black_silverRecord
47 == (l.findIneffectiveDropLoop<BLACK>(empty)));
48 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(black_silver) == 0);
49 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<WHITE>(black_silver) == 0);
50 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<WHITE>(empty) == 0);
51
52 black_silverRecord->isVisited = false;
53 CheckHashRecord *emptyRecord
54 = l.allocate<BLACK>(empty, white_stand, path, counter);
55 emptyRecord->isVisited = true;
56 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(black_silver) == 0);
57 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<BLACK>(empty) == 0);
58 CPPUNIT_ASSERT(emptyRecord
59 == (l.findIneffectiveDropLoop<WHITE>(black_silver)));
60 CPPUNIT_ASSERT(l.findIneffectiveDropLoop<WHITE>(empty) == 0);
61 }
62
63 static const ProofDisproof normalPdp(3,5);
64
65 /** 先手番 */
66 void SameBoardListTest::testAllocateBlack()
67 {
68 HashEffectState state(CsaString(
69 "P1+NY+TO * * * * -OU-KE-KY\n"
70 "P2 * * * * * -GI-KI * *\n"
71 "P3 * +RY * * +UM * -KI-FU-FU\n"
72 "P4 * * +FU-FU * * * * *\n"
73 "P5 * * -KE * +FU * * +FU *\n"
74 "P6-KE * * +FU+GI-FU * * +FU\n"
75 "P7 * * -UM * * * * * *\n"
76 "P8 * * * * * * * * * \n"
77 "P9 * +OU * -GI * * * * -NG\n"
78 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU00FU\n"
79 "P-00KI00KY00FU00FU\n"
80 "P-00AL\n"
81 "+\n").getInitialState());
82 const PieceStand white_stand(WHITE, state);
83 const PathEncoding path_black(BLACK);
84 size_t counter = 0;
85 SameBoardList table;
86 CheckHashRecord *record
87 = table.allocate<BLACK>(state.getHash().blackStand(), white_stand,
88 path_black, counter);
89 CPPUNIT_ASSERT(record);
90 CPPUNIT_ASSERT_EQUAL(1u, record->proof());
91 CPPUNIT_ASSERT_EQUAL(1u, record->disproof());
92 CPPUNIT_ASSERT_EQUAL((size_t)1u, counter);
93
94 record->setProofDisproof(normalPdp);
95
96 HashEffectState state2(CsaString( // 先手の歩が1枚少ない
97 "P1+NY+TO * * * * -OU-KE-KY\n"
98 "P2 * * * * * -GI-KI * *\n"
99 "P3 * +RY * * +UM * -KI-FU-FU\n"
100 "P4 * * +FU-FU * * * * *\n"
101 "P5 * * -KE * +FU * * +FU *\n"
102 "P6-KE * * +FU+GI-FU * * +FU\n"
103 "P7 * * -UM * * * * * *\n"
104 "P8 * * * * * * * * * \n"
105 "P9 * +OU * -GI * * * * -NG\n"
106 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU\n"
107 "P-00KI00KY00FU00FU00FU\n"
108 "P-00AL\n"
109 "+\n").getInitialState());
110 const PieceStand white_stand2(WHITE, state2);
111 CheckHashRecord *record2
112 = table.allocate<BLACK>(state2.getHash().blackStand(), white_stand2,
113 path_black, counter);
114 CPPUNIT_ASSERT(record2);
115 CPPUNIT_ASSERT(record2 != record);
116 CPPUNIT_ASSERT_EQUAL((size_t)2u, counter);
117
118 CPPUNIT_ASSERT_EQUAL(3u, record2->proof());
119 CPPUNIT_ASSERT_EQUAL(1u, record2->disproof());
120
121 HashEffectState state3(CsaString( // 後手の歩が1枚少ない
122 "P1+NY+TO * * * * -OU-KE-KY\n"
123 "P2 * * * * * -GI-KI * *\n"
124 "P3 * +RY * * +UM * -KI-FU-FU\n"
125 "P4 * * +FU-FU * * * * *\n"
126 "P5 * * -KE * +FU * * +FU *\n"
127 "P6-KE * * +FU+GI-FU * * +FU\n"
128 "P7 * * -UM * * * * * *\n"
129 "P8 * * * * * * * * * \n"
130 "P9 * +OU * -GI * * * * -NG\n"
131 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU00FU00FU\n"
132 "P-00KI00KY00FU\n"
133 "P-00AL\n"
134 "+\n").getInitialState());
135 const PieceStand white_stand3(WHITE, state3);
136 CheckHashRecord *record3
137 = table.allocate<BLACK>(state3.getHash().blackStand(), white_stand3,
138 path_black, counter);
139 CPPUNIT_ASSERT(record3);
140 CPPUNIT_ASSERT(record3 != record);
141 CPPUNIT_ASSERT_EQUAL(1u, record3->proof());
142 CPPUNIT_ASSERT_EQUAL(5u, record3->disproof());
143 CPPUNIT_ASSERT_EQUAL((size_t)3u, counter);
144
145 // propagate test
146
147 record3->setProofPieces(record3->stand(BLACK));
148 record3->propagateCheckmate<BLACK>(ProofDisproof::Checkmate());
149 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record3->proofDisproof());
150 CPPUNIT_ASSERT(record2->proofDisproof() != ProofDisproof::Checkmate());
151 CPPUNIT_ASSERT(record->proofDisproof() != ProofDisproof::Checkmate());
152
153 record2->setProofPieces(record2->stand(BLACK));
154 record2->propagateCheckmate<BLACK>(ProofDisproof::Checkmate());
155 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record2->proofDisproof());
156 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record->proofDisproof());
157
158 // reset
159 SameBoardList *same_boards = record->sameBoards;
160 *record = CheckHashRecord(record->stand(BLACK), record->stand(WHITE));
161 *record2 = CheckHashRecord(record2->stand(BLACK), record2->stand(WHITE));
162 *record3 = CheckHashRecord(record3->stand(BLACK), record3->stand(WHITE));
163 record->setProofDisproof(normalPdp);
164 record2->setProofDisproof(normalPdp);
165 record3->setProofDisproof(normalPdp);
166 record->sameBoards = record2->sameBoards = record->sameBoards
167 = same_boards;
168
169 record->setProofPieces(record->stand(BLACK));
170 record->propagateCheckmate<BLACK>(ProofDisproof::Checkmate());
171 CPPUNIT_ASSERT_EQUAL(normalPdp, record2->proofDisproof());
172 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record->proofDisproof());
173 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record3->proofDisproof());
174
175 *record = CheckHashRecord(record->stand(BLACK), record->stand(WHITE));
176 *record2 = CheckHashRecord(record2->stand(BLACK), record2->stand(WHITE));
177 *record3 = CheckHashRecord(record3->stand(BLACK), record3->stand(WHITE));
178 record->setProofDisproof(normalPdp);
179 record2->setProofDisproof(normalPdp);
180 record3->setProofDisproof(normalPdp);
181 record->sameBoards = record2->sameBoards = record->sameBoards
182 = same_boards;
183
184 record->setDisproofPieces(record->stand(WHITE));
185 record->propagateNoCheckmate<BLACK>(ProofDisproof::NoCheckmate());
186 CPPUNIT_ASSERT_EQUAL(ProofDisproof::NoCheckmate(), record->proofDisproof());
187 CPPUNIT_ASSERT_EQUAL(ProofDisproof::NoCheckmate(), record2->proofDisproof());
188 CPPUNIT_ASSERT_EQUAL(normalPdp, record3->proofDisproof());
189 }
190
191 /** 後手番 */
192 void SameBoardListTest::testAllocateWhite()
193 {
194 HashEffectState state(CsaString(
195 "P1+NY+TO * * * * -OU-KE-KY\n"
196 "P2 * * * * * -GI-KI * *\n"
197 "P3 * +RY * * +UM * -KI-FU-FU\n"
198 "P4 * * +FU-FU * * * * *\n"
199 "P5 * * -KE * +FU * * +FU *\n"
200 "P6-KE * * +FU+GI-FU * * +FU\n"
201 "P7 * * -UM * * * * * *\n"
202 "P8 * * * * * * * * * \n"
203 "P9 * +OU * -GI * * * * -NG\n"
204 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU00FU\n"
205 "P-00KI00KY00FU00FU\n"
206 "P-00AL\n"
207 "-\n").getInitialState());
208 const PieceStand white_stand(WHITE, state);
209 const PathEncoding path_white(WHITE);
210 SameBoardList table;
211 size_t counter = 0;
212 CheckHashRecord *record
213 = table.allocate<WHITE>(state.getHash().blackStand(), white_stand,
214 path_white, counter);
215 CPPUNIT_ASSERT(record);
216 CPPUNIT_ASSERT_EQUAL(1u, record->proof());
217 CPPUNIT_ASSERT_EQUAL(1u, record->disproof());
218 CPPUNIT_ASSERT_EQUAL((size_t)1u, counter);
219 record->setProofDisproof(3,5);
220
221 HashEffectState state2(CsaString( // 先手の歩が1枚少ない
222 "P1+NY+TO * * * * -OU-KE-KY\n"
223 "P2 * * * * * -GI-KI * *\n"
224 "P3 * +RY * * +UM * -KI-FU-FU\n"
225 "P4 * * +FU-FU * * * * *\n"
226 "P5 * * -KE * +FU * * +FU *\n"
227 "P6-KE * * +FU+GI-FU * * +FU\n"
228 "P7 * * -UM * * * * * *\n"
229 "P8 * * * * * * * * * \n"
230 "P9 * +OU * -GI * * * * -NG\n"
231 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU\n"
232 "P-00KI00KY00FU00FU00FU\n"
233 "P-00AL\n"
234 "-\n").getInitialState());
235 const PieceStand white_stand2(WHITE, state2);
236 CheckHashRecord *record2
237 = table.allocate<WHITE>(state2.getHash().blackStand(), white_stand2,
238 path_white, counter);
239 CPPUNIT_ASSERT(record2);
240 CPPUNIT_ASSERT(record2 != record);
241 CPPUNIT_ASSERT_EQUAL(1u, record2->proof());
242 CPPUNIT_ASSERT_EQUAL(5u, record2->disproof());
243 CPPUNIT_ASSERT_EQUAL((size_t)2u, counter);
244
245 HashEffectState state3(CsaString( // 後手の歩が1枚少ない
246 "P1+NY+TO * * * * -OU-KE-KY\n"
247 "P2 * * * * * -GI-KI * *\n"
248 "P3 * +RY * * +UM * -KI-FU-FU\n"
249 "P4 * * +FU-FU * * * * *\n"
250 "P5 * * -KE * +FU * * +FU *\n"
251 "P6-KE * * +FU+GI-FU * * +FU\n"
252 "P7 * * -UM * * * * * *\n"
253 "P8 * * * * * * * * * \n"
254 "P9 * +OU * -GI * * * * -NG\n"
255 "P+00HI00KI00KE00KY00FU00FU00FU00FU00FU00FU00FU\n"
256 "P-00KI00KY00FU\n"
257 "P-00AL\n"
258 "-\n").getInitialState());
259 const PieceStand white_stand3(WHITE, state3);
260 CheckHashRecord *record3
261 = table.allocate<WHITE>(state3.getHash().blackStand(), white_stand3,
262 path_white, counter);
263 CPPUNIT_ASSERT(record3);
264 CPPUNIT_ASSERT(record3 != record);
265 CPPUNIT_ASSERT_EQUAL(3u, record3->proof());
266 CPPUNIT_ASSERT_EQUAL(1u, record3->disproof());
267 CPPUNIT_ASSERT_EQUAL((size_t)3u, counter);
268
269 // propagate test
270 record2->setProofPieces(record2->stand(WHITE));
271 record2->propagateCheckmate<WHITE>(ProofDisproof::Checkmate());
272 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record2->proofDisproof());
273 CPPUNIT_ASSERT(record3->proofDisproof() != ProofDisproof::Checkmate());
274 CPPUNIT_ASSERT(record->proofDisproof() != ProofDisproof::Checkmate());
275
276 record3->setProofPieces(record3->stand(WHITE));
277 record3->propagateCheckmate<WHITE>(ProofDisproof::Checkmate());
278 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record3->proofDisproof());
279 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record->proofDisproof());
280
281 // reset
282 SameBoardList *same_boards = record->sameBoards;
283 *record = CheckHashRecord(record->stand(BLACK), record->stand(WHITE));
284 *record2 = CheckHashRecord(record2->stand(BLACK), record2->stand(WHITE));
285 *record3 = CheckHashRecord(record3->stand(BLACK), record3->stand(WHITE));
286 record->setProofDisproof(normalPdp);
287 record2->setProofDisproof(normalPdp);
288 record3->setProofDisproof(normalPdp);
289 record->sameBoards = record2->sameBoards = record->sameBoards
290 = same_boards;
291
292 record->setProofPieces(record->stand(WHITE));
293 record->propagateCheckmate<WHITE>(ProofDisproof::Checkmate());
294 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record->proofDisproof());
295 CPPUNIT_ASSERT_EQUAL(ProofDisproof::Checkmate(), record2->proofDisproof());
296 CPPUNIT_ASSERT_EQUAL(normalPdp, record3->proofDisproof());
297
298 *record = CheckHashRecord(record->stand(BLACK), record->stand(WHITE));
299 *record2 = CheckHashRecord(record2->stand(BLACK), record2->stand(WHITE));
300 *record3 = CheckHashRecord(record3->stand(BLACK), record3->stand(WHITE));
301 record->setProofDisproof(normalPdp);
302 record2->setProofDisproof(normalPdp);
303 record3->setProofDisproof(normalPdp);
304 record->sameBoards = record2->sameBoards = record->sameBoards
305 = same_boards;
306
307 record->setDisproofPieces(record->stand(BLACK));
308 record->propagateNoCheckmate<WHITE>(ProofDisproof::NoCheckmate());
309 CPPUNIT_ASSERT_EQUAL(normalPdp, record2->proofDisproof());
310 CPPUNIT_ASSERT_EQUAL(ProofDisproof::NoCheckmate(), record->proofDisproof());
311 CPPUNIT_ASSERT_EQUAL(ProofDisproof::NoCheckmate(), record3->proofDisproof());
312 }
313
314 // ;;; Local Variables:
315 // ;;; mode:c++
316 // ;;; c-basic-offset:2
317 // ;;; End: