Debian Codegraph @

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

raw
1 /* checkMoveGenerator.t.cc
2 */
3 #include "osl/checkmate/checkMoveGenerator.h"
4 #include "osl/checkmate/checkMoveList.h"
5 #include "osl/checkmate/checkMoveListProvider.h"
6 #include "osl/record/csaString.h"
7 #include "osl/state/hashEffectState.h"
8
9 #include <cppunit/TestCase.h>
10 #include <cppunit/extensions/HelperMacros.h>
11
12 #include <iostream>
13
14 class CheckMoveGeneratorTest : public CppUnit::TestFixture
15 {
16 CPPUNIT_TEST_SUITE(CheckMoveGeneratorTest);
17 CPPUNIT_TEST(testEscape);
18 CPPUNIT_TEST(testAttack);
19 CPPUNIT_TEST(testBug);
20 CPPUNIT_TEST_SUITE_END();
21 public:
22 void testEscape();
23 void testAttack();
24 void testBug();
25 };
26 CPPUNIT_TEST_SUITE_REGISTRATION(CheckMoveGeneratorTest);
27
28 using namespace osl;
29 using namespace osl::checkmate;
30 extern bool isShortTest;
31
32 void CheckMoveGeneratorTest::testBug()
33 {
34 SimpleState state = CsaString(
35 "P1-KY * * * * * * * +UM\n"
36 "P2 * +KI * * +HI * * * -KY\n"
37 "P3 * * -KE * * * * * * \n"
38 "P4-FU-OU * * -KI * * -FU-FU\n"
39 "P5 * +KE-GI-FU * * * +KE * \n"
40 "P6+FU+OU * * +FU+FU * * +FU\n"
41 "P7 * * * * +GI * * * * \n"
42 "P8 * * * * * * * +HI * \n"
43 "P9+KY * * -UM * * * * +KY\n"
44 "P+00FU00FU00FU00FU00FU00FU00FU00FU00KI\n"
45 "P-00FU00FU00KE00GI00GI00KI\n"
46 "+\n").getInitialState();
47 HashEffectState hState(state);
48 const Move last_move = Move(Square(7,5),SILVER,WHITE);
49 CheckMoveList moves;
50
51 CheckMoveListProvider src;
52 CheckMoveGenerator<WHITE>::generateEscape(hState, src, moves);
53 if (! isShortTest)
54 std::cerr << moves;
55
56 moves.clear();
57 CheckMoveGenerator<BLACK>::generateAttack(hState, src, moves);
58 if (! isShortTest)
59 std::cerr << moves;
60 }
61
62 void CheckMoveGeneratorTest::testEscape()
63 {
64 SimpleState state=CsaString(
65 "P1 * * * * * * * -KE-OU\n"
66 "P2 * * * * * * -FU-FU-KY\n"
67 "P3 * * * * * * * +KE * \n"
68 "P4 * * * * * +HI * * * \n"
69 "P5 * * * * * * * * * \n"
70 "P6 * * * * * * * * * \n"
71 "P7 * * * * * * * * * \n"
72 "P8 * * * * * * * * * \n"
73 "P9 * * +OU * * * * * * \n"
74 "P+00KE\n"
75 "P-00AL\n"
76 "-\n").getInitialState();
77 HashEffectState hState(state);
78 CheckMoveList moves;
79 CheckMoveListProvider src;
80 CheckMoveGenerator<BLACK>::generateEscape(hState, src, moves);
81 CPPUNIT_ASSERT_EQUAL((size_t)1u, moves.size());
82
83 SimpleState state2=CsaString(
84 "P1 * * * * * * * -KE-OU\n"
85 "P2 * * * * * * -FU-FU-KY\n"
86 "P3 * * * * * * * +KE * \n"
87 "P4 * * * * * +KA * * * \n"
88 "P5 * * * * * * * * * \n"
89 "P6 * * * * * * * * * \n"
90 "P7 * * * * * * * * * \n"
91 "P8 * * * * * * * * * \n"
92 "P9 * * +OU * * * * * * \n"
93 "P+00KE\n"
94 "P-00AL\n"
95 "-\n").getInitialState();
96 HashEffectState hState2(state2);
97 moves.clear();
98 CheckMoveGenerator<BLACK>::generateEscape(hState2, src, moves);
99 CPPUNIT_ASSERT_EQUAL((size_t)0u, moves.size());
100
101
102 SimpleState state3=CsaString(
103 "P1-KY-KE * -KI * * * +RY-KY\n"
104 "P2 * -GI-OU-FU * * * * * \n"
105 "P3-FU-FU * -KI * * * * * \n"
106 "P4 * * * * +FU * * * -FU\n"
107 "P5 * * * +FU * * * * * \n"
108 "P6 * * +FU * * * +GI-FU+FU\n"
109 "P7+FU * * * * * +KI-KE * \n"
110 "P8 * * * * * -RY+FU+OU * \n"
111 "P9+KY+KE * * * -GI-KA+KE+KY\n"
112 "P+00FU00FU00KI00KA\n"
113 "P-00FU00FU00FU00FU00FU00GI\n"
114 "+\n").getInitialState();
115 HashEffectState hState3(state3);
116 moves.clear();
117 CheckMoveGenerator<WHITE>::generateEscape(hState3, src, moves);
118 CPPUNIT_ASSERT_EQUAL((size_t)1u, moves.size());
119 }
120
121 void CheckMoveGeneratorTest::testAttack()
122 {
123 SimpleState state=CsaString(
124 "P1 * * * * * * * * * \n"
125 "P2 * * * * * * * * * \n"
126 "P3 * * * * * * * * * \n"
127 "P4 * * * * * -OU * * * \n"
128 "P5 * * * * * * * * * \n"
129 "P6 * * * * * +FU * * * \n"
130 "P7 * * * * +OU * * * * \n"
131 "P8 * * * * * * * * * \n"
132 "P9 * * * * * * * * * \n"
133 "P-00AL\n"
134 "+\n").getInitialState();
135 HashEffectState hState(state);
136 CheckMoveList moves;
137 CheckMoveListProvider src;
138 CheckMoveGenerator<BLACK>::generateAttack(hState, src, moves);
139 CPPUNIT_ASSERT_EQUAL((size_t)1u, moves.size());
140
141 SimpleState state2=CsaString(
142 "P1 * * * * * * * * * \n"
143 "P2 * * * * * * * * * \n"
144 "P3 * * * * * * * * * \n"
145 "P4 * * * * * -OU * * * \n"
146 "P5 * * * * * * -KA * * \n"
147 "P6 * * * * * +FU * * * \n"
148 "P7 * * * * +OU * * * * \n"
149 "P8 * * * * * * * * * \n"
150 "P9 * * * * * * * * * \n"
151 "P-00AL\n"
152 "+\n").getInitialState();
153 HashEffectState hState2(state2);
154 moves.clear();
155 CheckMoveGenerator<BLACK>::generateAttack(hState2, src, moves);
156 CPPUNIT_ASSERT_EQUAL((size_t)0u, moves.size());
157
158 SimpleState state3=CsaString(
159 "P1 * * * * * * * * * \n"
160 "P2 * * * * * * * * * \n"
161 "P3 * * * * * * * * * \n"
162 "P4-OU * * * * * * * * \n"
163 "P5 * * * * * * * * * \n"
164 "P6 * * * * * * * * * \n"
165 "P7 * * * * * * * * * \n"
166 "P8+OU * * * * -RY * * * \n"
167 "P9+KY+KE * * * * * * * \n"
168 "P+00AL\n"
169 "+\n").getInitialState();
170 HashEffectState hState3(state3);
171 moves.clear();
172 CheckMoveGenerator<BLACK>::generateAttack(hState3, src, moves);
173 CPPUNIT_ASSERT_EQUAL((size_t)2u, moves.size());
174 const Move counter1 = Move(Square(9,8),Square(8,7),KING,
175 PTYPE_EMPTY,false,BLACK);
176 const Move counter2 = Move(Square(5,8),BISHOP,BLACK);
177 CPPUNIT_ASSERT_EQUAL(counter1, moves[0].move);
178 CPPUNIT_ASSERT_EQUAL(counter2, moves[1].move);
179 }
180
181 /* ------------------------------------------------------------------------- */
182 // ;;; Local Variables:
183 // ;;; mode:c++
184 // ;;; c-basic-offset:2
185 // ;;; End: