00001 //--------------------------------------------------------------------------- 00002 /** @file StoneBoardTest.cpp 00003 */ 00004 //--------------------------------------------------------------------------- 00005 00006 #include <boost/test/auto_unit_test.hpp> 00007 00008 #include "StoneBoard.hpp" 00009 00010 using namespace benzene; 00011 00012 //--------------------------------------------------------------------------- 00013 00014 namespace { 00015 00016 BOOST_AUTO_TEST_CASE(StoneBoard_numStones) 00017 { 00018 BOOST_REQUIRE(MAX_WIDTH >= 5 && MAX_HEIGHT >= 5); 00019 00020 StoneBoard b(5, 5); 00021 BOOST_CHECK_EQUAL(b.NumStones(), 0); 00022 00023 b.PlayMove(BLACK, FIRST_CELL); 00024 BOOST_CHECK_EQUAL(b.NumStones(), 1); 00025 00026 b.PlayMove(WHITE, HEX_CELL_A2); 00027 BOOST_CHECK_EQUAL(b.NumStones(), 2); 00028 00029 b.SetColor(BLACK, HEX_CELL_A3); 00030 BOOST_CHECK_EQUAL(b.NumStones(), 2); 00031 } 00032 00033 BOOST_AUTO_TEST_CASE(StoneBoard_AddRemoveSetColor) 00034 { 00035 BOOST_REQUIRE(MAX_WIDTH >= 8 && MAX_HEIGHT >= 8); 00036 StoneBoard sb = StoneBoard(8, 8); 00037 bitset_t b; 00038 00039 // test addColor 00040 sb.AddColor(BLACK, b); 00041 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00042 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 2u); 00043 BOOST_CHECK(sb.GetWhite().test(WEST)); 00044 BOOST_CHECK(sb.GetWhite().test(EAST)); 00045 b.set(FIRST_CELL); 00046 b.set(HEX_CELL_A3); 00047 sb.AddColor(BLACK, b); 00048 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00049 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 2u); 00050 b.reset(); 00051 b.set(HEX_CELL_A2); 00052 sb.AddColor(WHITE, b); 00053 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00054 BOOST_CHECK(sb.GetBlack().test(FIRST_CELL)); 00055 BOOST_CHECK(sb.GetBlack().test(HEX_CELL_A3)); 00056 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00057 BOOST_CHECK(sb.GetWhite().test(HEX_CELL_A2)); 00058 00059 // test removeColor when nothing removed 00060 b.flip(); 00061 b &= sb.Const().GetCells(); 00062 sb.RemoveColor(WHITE, b); 00063 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00064 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00065 00066 // test setColor with EMPTY 00067 sb.SetColor(EMPTY, FIRST_CELL); 00068 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00069 BOOST_CHECK(sb.GetBlack().test(HEX_CELL_A3)); 00070 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00071 sb.SetColor(EMPTY, HEX_CELL_A2); 00072 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00073 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 2u); 00074 00075 // test setColor with BLACK/WHITE 00076 b.reset(); 00077 b.set(FIRST_CELL); 00078 b.set(HEX_CELL_A4); 00079 sb.SetColor(WHITE, b); 00080 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00081 BOOST_CHECK(sb.GetBlack().test(HEX_CELL_A3)); 00082 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 2u); 00083 BOOST_CHECK(sb.GetWhite().test(FIRST_CELL)); 00084 BOOST_CHECK(sb.GetWhite().test(HEX_CELL_A4)); 00085 00086 // test removeColor under normal conditions 00087 b.reset(); 00088 b.set(FIRST_CELL); 00089 sb.RemoveColor(WHITE, b); 00090 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00091 BOOST_CHECK(sb.GetBlack().test(HEX_CELL_A3)); 00092 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 1u); 00093 BOOST_CHECK(sb.GetWhite().test(HEX_CELL_A4)); 00094 b.set(HEX_CELL_A3); 00095 b.set(HEX_CELL_A4); 00096 sb.RemoveColor(BLACK, b); 00097 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00098 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 1u); 00099 BOOST_CHECK(sb.GetWhite().test(HEX_CELL_A4)); 00100 } 00101 00102 BOOST_AUTO_TEST_CASE(StoneBoard_PlayAndUndoMoves) 00103 { 00104 BOOST_REQUIRE(MAX_WIDTH >= 9 && MAX_HEIGHT >= 9); 00105 00106 StoneBoard sb = StoneBoard(9, 9); 00107 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00108 BOOST_CHECK(sb.IsWhite(EAST)); 00109 BOOST_CHECK(sb.IsWhite(WEST)); 00110 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 4u); 00111 BOOST_CHECK(sb.IsPlayed(NORTH)); 00112 BOOST_CHECK(sb.IsPlayed(EAST)); 00113 00114 // test PlayMove 00115 sb.PlayMove(BLACK, FIRST_CELL); 00116 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00117 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 2u); 00118 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 5u); 00119 BOOST_CHECK(sb.IsBlack(FIRST_CELL)); 00120 BOOST_CHECK(sb.IsPlayed(FIRST_CELL)); 00121 sb.PlayMove(WHITE, HEX_CELL_A9); 00122 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00123 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00124 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 6u); 00125 BOOST_CHECK(sb.IsWhite(HEX_CELL_A9)); 00126 BOOST_CHECK(sb.IsPlayed(HEX_CELL_A9)); 00127 00128 // test UndoMove 00129 sb.UndoMove(FIRST_CELL); 00130 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00131 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00132 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 5u); 00133 BOOST_CHECK(!sb.IsBlack(FIRST_CELL)); 00134 BOOST_CHECK(!sb.IsPlayed(FIRST_CELL)); 00135 sb.PlayMove(WHITE, HEX_CELL_A5); 00136 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00137 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 4u); 00138 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 6u); 00139 BOOST_CHECK(sb.IsWhite(HEX_CELL_A5)); 00140 BOOST_CHECK(sb.IsPlayed(HEX_CELL_A5)); 00141 sb.UndoMove(HEX_CELL_A9); 00142 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 2u); 00143 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00144 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 5u); 00145 BOOST_CHECK(!sb.IsWhite(HEX_CELL_A9)); 00146 BOOST_CHECK(!sb.IsPlayed(HEX_CELL_A9)); 00147 00148 // check that RESIGN and SWAP_PIECES have no effect on board 00149 // status, or ability to keep playing moves, although they 00150 // can affect which moves are legal 00151 sb.StartNewGame(); 00152 BOOST_CHECK(!sb.IsLegal(SWAP_PIECES)); 00153 sb.PlayMove(BLACK, HEX_CELL_A5); 00154 BOOST_CHECK(sb.IsLegal(SWAP_PIECES)); 00155 sb.PlayMove(WHITE, SWAP_PIECES); 00156 BOOST_CHECK(!sb.IsLegal(SWAP_PIECES)); 00157 BOOST_CHECK(sb.IsBlack(HEX_CELL_A5)); 00158 BOOST_CHECK(sb.IsLegal(RESIGN)); 00159 BOOST_CHECK(sb.IsLegal(HEX_CELL_F6)); 00160 sb.PlayMove(BLACK, RESIGN); 00161 BOOST_CHECK(!sb.IsLegal(RESIGN)); 00162 BOOST_CHECK(!sb.IsLegal(HEX_CELL_F6)); 00163 sb.PlayMove(WHITE, HEX_CELL_F6); 00164 BOOST_CHECK(sb.IsBlack(HEX_CELL_A5)); 00165 BOOST_CHECK(sb.IsWhite(HEX_CELL_F6)); 00166 } 00167 00168 BOOST_AUTO_TEST_CASE(StoneBoard_RotateAndMirrorBoard) 00169 { 00170 BOOST_REQUIRE(MAX_WIDTH >= 8 && MAX_HEIGHT >= 8); 00171 StoneBoard sb = StoneBoard(5, 6); 00172 00173 // test rotateBoard on non-square board 00174 sb.PlayMove(BLACK, HEX_CELL_A5); 00175 sb.PlayMove(WHITE, HEX_CELL_B3); 00176 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00177 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00178 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 6u); 00179 BOOST_CHECK(sb.IsBlack(HEX_CELL_A5)); 00180 BOOST_CHECK(sb.IsPlayed(HEX_CELL_A5)); 00181 BOOST_CHECK(sb.IsWhite(HEX_CELL_B3)); 00182 BOOST_CHECK(sb.IsPlayed(HEX_CELL_B3)); 00183 sb.RotateBoard(); 00184 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 3u); 00185 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00186 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 6u); 00187 BOOST_CHECK(sb.IsBlack(HEX_CELL_E2)); 00188 BOOST_CHECK(sb.IsPlayed(HEX_CELL_E2)); 00189 BOOST_CHECK(sb.IsWhite(HEX_CELL_D4)); 00190 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D4)); 00191 BOOST_CHECK(sb.IsBlack(NORTH)); 00192 BOOST_CHECK(sb.IsWhite(WEST)); 00193 BOOST_CHECK(sb.IsWhite(EAST)); 00194 BOOST_CHECK(sb.IsPlayed(SOUTH)); 00195 00196 // test rotateBoard on square board 00197 sb = StoneBoard(8, 8); 00198 sb.PlayMove(BLACK, HEX_CELL_B2); 00199 sb.PlayMove(WHITE, HEX_CELL_D4); 00200 sb.PlayMove(BLACK, HEX_CELL_D5); 00201 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00202 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00203 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 7u); 00204 BOOST_CHECK(sb.IsBlack(HEX_CELL_D5)); 00205 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D4)); 00206 sb.RotateBoard(); 00207 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00208 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00209 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 7u); 00210 BOOST_CHECK(sb.IsBlack(HEX_CELL_E4)); 00211 BOOST_CHECK(sb.IsBlack(HEX_CELL_G7)); 00212 BOOST_CHECK(sb.IsWhite(HEX_CELL_E5)); 00213 BOOST_CHECK(sb.IsPlayed(HEX_CELL_E4)); 00214 BOOST_CHECK(sb.IsPlayed(HEX_CELL_G7)); 00215 BOOST_CHECK(sb.IsPlayed(HEX_CELL_E5)); 00216 BOOST_CHECK(sb.IsBlack(NORTH)); 00217 BOOST_CHECK(sb.IsBlack(SOUTH)); 00218 BOOST_CHECK(sb.IsWhite(EAST)); 00219 BOOST_CHECK(sb.IsWhite(EAST)); 00220 BOOST_CHECK(sb.IsPlayed(NORTH)); 00221 BOOST_CHECK(sb.IsPlayed(SOUTH)); 00222 BOOST_CHECK(sb.IsPlayed(EAST)); 00223 BOOST_CHECK(sb.IsPlayed(WEST)); 00224 BOOST_CHECK(!sb.IsPlayed(RESIGN)); 00225 sb.PlayMove(WHITE, RESIGN); 00226 sb.RotateBoard(); 00227 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00228 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00229 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 8u); 00230 BOOST_CHECK(sb.IsBlack(HEX_CELL_D5)); 00231 BOOST_CHECK(sb.IsBlack(HEX_CELL_B2)); 00232 BOOST_CHECK(sb.IsWhite(HEX_CELL_D4)); 00233 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D5)); 00234 BOOST_CHECK(sb.IsPlayed(HEX_CELL_B2)); 00235 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D4)); 00236 BOOST_CHECK(sb.IsPlayed(RESIGN)); 00237 BOOST_CHECK(sb.IsBlack(NORTH)); 00238 BOOST_CHECK(sb.IsBlack(SOUTH)); 00239 BOOST_CHECK(sb.IsWhite(EAST)); 00240 BOOST_CHECK(sb.IsWhite(WEST)); 00241 BOOST_CHECK(sb.IsPlayed(NORTH)); 00242 BOOST_CHECK(sb.IsPlayed(SOUTH)); 00243 BOOST_CHECK(sb.IsPlayed(EAST)); 00244 BOOST_CHECK(sb.IsPlayed(WEST)); 00245 00246 // test mirror on square board 00247 sb.MirrorBoard(); 00248 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00249 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 3u); 00250 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 8u); 00251 BOOST_CHECK(sb.IsBlack(HEX_CELL_E4)); 00252 BOOST_CHECK(sb.IsBlack(HEX_CELL_B2)); 00253 BOOST_CHECK(sb.IsWhite(HEX_CELL_D4)); 00254 BOOST_CHECK(sb.IsPlayed(HEX_CELL_E4)); 00255 BOOST_CHECK(sb.IsPlayed(HEX_CELL_B2)); 00256 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D4)); 00257 BOOST_CHECK(sb.IsPlayed(RESIGN)); 00258 BOOST_CHECK(sb.IsWhite(NORTH)); 00259 BOOST_CHECK(sb.IsWhite(SOUTH)); 00260 BOOST_CHECK(sb.IsBlack(EAST)); 00261 BOOST_CHECK(sb.IsBlack(WEST)); 00262 BOOST_CHECK(sb.IsPlayed(NORTH)); 00263 BOOST_CHECK(sb.IsPlayed(SOUTH)); 00264 BOOST_CHECK(sb.IsPlayed(EAST)); 00265 BOOST_CHECK(sb.IsPlayed(WEST)); 00266 sb.PlayMove(WHITE, HEX_CELL_F2); 00267 sb.MirrorBoard(); 00268 BOOST_CHECK_EQUAL(sb.GetBlack().count(), 4u); 00269 BOOST_CHECK_EQUAL(sb.GetWhite().count(), 4u); 00270 BOOST_CHECK_EQUAL(sb.GetPlayed().count(), 9u); 00271 BOOST_CHECK(sb.IsBlack(HEX_CELL_D5)); 00272 BOOST_CHECK(sb.IsBlack(HEX_CELL_B2)); 00273 BOOST_CHECK(sb.IsWhite(HEX_CELL_D4)); 00274 BOOST_CHECK(sb.IsWhite(HEX_CELL_B6)); 00275 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D5)); 00276 BOOST_CHECK(sb.IsPlayed(HEX_CELL_B2)); 00277 BOOST_CHECK(sb.IsPlayed(HEX_CELL_D4)); 00278 BOOST_CHECK(sb.IsPlayed(HEX_CELL_B6)); 00279 BOOST_CHECK(sb.IsPlayed(RESIGN)); 00280 BOOST_CHECK(sb.IsBlack(NORTH)); 00281 BOOST_CHECK(sb.IsBlack(SOUTH)); 00282 BOOST_CHECK(sb.IsWhite(EAST)); 00283 BOOST_CHECK(sb.IsWhite(WEST)); 00284 BOOST_CHECK(sb.IsPlayed(NORTH)); 00285 BOOST_CHECK(sb.IsPlayed(SOUTH)); 00286 BOOST_CHECK(sb.IsPlayed(EAST)); 00287 BOOST_CHECK(sb.IsPlayed(WEST)); 00288 } 00289 00290 BOOST_AUTO_TEST_CASE(StoneBoard_SelfRotation) 00291 { 00292 StoneBoard brd(3, 3); 00293 BOOST_CHECK(brd.IsSelfRotation()); 00294 brd.PlayMove(BLACK, HEX_CELL_A1); 00295 BOOST_CHECK(!brd.IsSelfRotation()); 00296 brd.PlayMove(BLACK, HEX_CELL_C3); 00297 BOOST_CHECK(brd.IsSelfRotation()); 00298 brd.PlayMove(WHITE, HEX_CELL_B2); 00299 BOOST_CHECK(brd.IsSelfRotation()); 00300 brd.PlayMove(WHITE, HEX_CELL_A2); 00301 BOOST_CHECK(!brd.IsSelfRotation()); 00302 00303 brd = StoneBoard(9, 9); 00304 brd.PlayMove(BLACK, HEX_CELL_E5); 00305 BOOST_CHECK(brd.IsSelfRotation()); 00306 } 00307 00308 BOOST_AUTO_TEST_CASE(StoneBoard_Hash) 00309 { 00310 BOOST_REQUIRE(MAX_WIDTH >= 5 && MAX_HEIGHT >= 5); 00311 StoneBoard sb = StoneBoard(5, 5); 00312 00313 hash_t h1,h2; 00314 h1 = sb.Hash(); 00315 00316 // check that playmove modifies the hash 00317 sb.PlayMove(BLACK, HEX_CELL_A1); 00318 sb.PlayMove(WHITE, HEX_CELL_A2); 00319 sb.PlayMove(BLACK, HEX_CELL_A3); 00320 sb.PlayMove(WHITE, HEX_CELL_A4); 00321 h2 = sb.Hash(); 00322 BOOST_CHECK(h1 != h2); 00323 00324 // addColor does not modify hash 00325 bitset_t bs; 00326 bs.set(HEX_CELL_A5); 00327 sb.AddColor(BLACK, bs); 00328 BOOST_CHECK(h2 == sb.Hash()); 00329 00330 // removeColor (even of a played move) 00331 // does not modify hash. 00332 bs.reset(); 00333 bs.set(HEX_CELL_A4); 00334 sb.RemoveColor(WHITE, bs); 00335 BOOST_CHECK(h2 == sb.Hash()); 00336 00337 // set color does not modify hash. 00338 bs.reset(); 00339 bs.set(HEX_CELL_A3); 00340 sb.SetColor(BLACK, bs); 00341 BOOST_CHECK(h2 == sb.Hash()); 00342 } 00343 00344 BOOST_AUTO_TEST_CASE(StoneBoard_WhoseTurn) 00345 { 00346 BOOST_REQUIRE(MAX_WIDTH >= 5 && MAX_HEIGHT >= 5); 00347 StoneBoard sb = StoneBoard(5, 5); 00348 00349 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00350 00351 sb.PlayMove(FIRST_TO_PLAY, FIRST_CELL); 00352 BOOST_CHECK_EQUAL(sb.WhoseTurn(), !FIRST_TO_PLAY); 00353 00354 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A2); 00355 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00356 00357 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A3); 00358 BOOST_CHECK_EQUAL(sb.WhoseTurn(), !FIRST_TO_PLAY); 00359 00360 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A4); 00361 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00362 00363 // check that swap is handled properly 00364 sb.StartNewGame(); 00365 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00366 00367 sb.PlayMove(FIRST_TO_PLAY, FIRST_CELL); 00368 BOOST_CHECK_EQUAL(sb.WhoseTurn(), !FIRST_TO_PLAY); 00369 00370 sb.PlayMove(!FIRST_TO_PLAY, SWAP_PIECES); 00371 BOOST_CHECK_EQUAL(sb.WhoseTurn(), !FIRST_TO_PLAY); 00372 00373 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A2); 00374 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00375 00376 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A3); 00377 BOOST_CHECK_EQUAL(sb.WhoseTurn(), !FIRST_TO_PLAY); 00378 00379 sb.PlayMove(sb.WhoseTurn(), HEX_CELL_A4); 00380 BOOST_CHECK_EQUAL(sb.WhoseTurn(), FIRST_TO_PLAY); 00381 } 00382 00383 BOOST_AUTO_TEST_CASE(StoneBoard_IsStandardPosition) 00384 { 00385 StoneBoard brd(5, 5); 00386 BOOST_CHECK(brd.IsStandardPosition()); 00387 brd.PlayMove(BLACK, HEX_CELL_A1); 00388 BOOST_CHECK(brd.IsStandardPosition()); 00389 brd.PlayMove(WHITE, HEX_CELL_A2); 00390 BOOST_CHECK(brd.IsStandardPosition()); 00391 brd.PlayMove(WHITE, HEX_CELL_A3); 00392 BOOST_CHECK(!brd.IsStandardPosition()); 00393 brd.PlayMove(BLACK, HEX_CELL_A4); 00394 BOOST_CHECK(brd.IsStandardPosition()); 00395 brd.PlayMove(BLACK, HEX_CELL_A5); 00396 BOOST_CHECK(brd.IsStandardPosition()); 00397 } 00398 00399 //--------------------------------------------------------------------------- 00400 00401 BOOST_AUTO_TEST_CASE(StoneBoard_SetStateString) 00402 { 00403 std::string str(". . w" 00404 " B b\n ." 00405 ". W\tB "); 00406 StoneBoard brd(3, 3, str); 00407 BOOST_CHECK(brd.IsEmpty(HEX_CELL_A1)); 00408 BOOST_CHECK(brd.IsEmpty(HEX_CELL_B1)); 00409 BOOST_CHECK(brd.IsWhite(HEX_CELL_C1)); 00410 BOOST_CHECK(!brd.IsPlayed(HEX_CELL_C1)); 00411 BOOST_CHECK(brd.IsBlack(HEX_CELL_A2)); 00412 BOOST_CHECK(brd.IsPlayed(HEX_CELL_A2)); 00413 BOOST_CHECK(brd.IsBlack(HEX_CELL_B2)); 00414 BOOST_CHECK(!brd.IsPlayed(HEX_CELL_B2)); 00415 BOOST_CHECK(brd.IsEmpty(HEX_CELL_C2)); 00416 BOOST_CHECK(brd.IsEmpty(HEX_CELL_A3)); 00417 BOOST_CHECK(brd.IsWhite(HEX_CELL_B3)); 00418 BOOST_CHECK(brd.IsPlayed(HEX_CELL_B3)); 00419 BOOST_CHECK(brd.IsBlack(HEX_CELL_C3)); 00420 BOOST_CHECK(brd.IsPlayed(HEX_CELL_C3)); 00421 } 00422 00423 //--------------------------------------------------------------------------- 00424 00425 BOOST_AUTO_TEST_CASE(StoneBoard_BoardID) 00426 { 00427 BOOST_REQUIRE(MAX_WIDTH >= 2 && MAX_HEIGHT >= 2); 00428 00429 // check each color is encoded/decoded correctly 00430 // on a 1x1 board. 00431 for (ColorIterator color; color; ++color) 00432 { 00433 StoneBoard b1(1, 1); 00434 StoneBoard b2(1, 1); 00435 00436 if (*color != EMPTY) 00437 b1.PlayMove(*color, HEX_CELL_A1); 00438 00439 BoardID id = b1.GetBoardID(); 00440 BOOST_CHECK_EQUAL(id.size(), 1u); 00441 00442 b2.SetPosition(id); 00443 BOOST_CHECK(b1 == b2); 00444 } 00445 00446 // check a 5x3 state 00447 { 00448 std::string str("B..W." 00449 ".WB.." 00450 "BW..W"); 00451 StoneBoard b1(5, 3, str); 00452 StoneBoard b2(5, 3); 00453 BoardID id = b1.GetBoardID(); 00454 BOOST_CHECK_EQUAL(id.size(), 4u); 00455 b2.SetPosition(id); 00456 BOOST_CHECK(b1 == b2); 00457 } 00458 } 00459 00460 } 00461 00462 //---------------------------------------------------------------------------