00001 //---------------------------------------------------------------------------- 00002 /** @file PatternStateTest.cpp 00003 00004 @todo Test a black pattern. 00005 00006 @todo Test that the obtuse corner is both black and white. 00007 00008 @todo Test PatternHits::moves2() functionality. 00009 00010 @todo Test that an arbitrary carrier (more than 1 cell) is correct 00011 when returned in PatternHits::moves{1/2}(). 00012 00013 @todo Test that incremental updates work the same as complete updates. 00014 */ 00015 //---------------------------------------------------------------------------- 00016 00017 #include <boost/test/auto_unit_test.hpp> 00018 00019 #include "Hex.hpp" 00020 #include "PatternState.hpp" 00021 00022 using namespace benzene; 00023 00024 //--------------------------------------------------------------------------- 00025 00026 namespace { 00027 00028 BOOST_AUTO_TEST_CASE(PatternState_Tests) 00029 { 00030 // W ! 00031 // W * W [7/0] 00032 // 00033 // W * W 00034 // W ! [7m/0] 00035 std::string patstring 00036 = "v:1,0,1,0,0;1,0,0,1,0;1,0,1,0,0;1,0,1,0,0;0,0,0,0,0;0,0,0,0,0;"; 00037 Pattern pattern; 00038 BOOST_CHECK(pattern.unserialize(patstring)); 00039 PatternSet patterns; 00040 pattern.setName("pat"); 00041 patterns.push_back(pattern); 00042 pattern.mirror(); 00043 pattern.setName("mpat"); 00044 patterns.push_back(pattern); 00045 HashedPatternSet hashpat; 00046 hashpat.hash(patterns); 00047 00048 StoneBoard brd(11, 11); 00049 PatternState pastate(brd); 00050 00051 // 0x5765ad24894d45fc 00052 // a b c d e f g h i j k 00053 // 1\. . . . . . . . . . .\1 00054 // 2\. . . . . . . . . . .\2 00055 // 3\. . . . . . . W b . .\3 00056 // 4\f W . . . . W a W . .\4 00057 // 5\e . . . . . . . . . .\5 00058 // 6\. . . . . . . . . . .\6 W 00059 // W 7\. . . . . . . . . . .\7 00060 // 8\. . . . . . W c W . h\8 00061 // 9\. . . . . . W d . W g\9 00062 // 10\. . . . . . . . . . .\10 00063 // 11\. . . . . . . . . . .\11 00064 // a b c d e f g h i j k 00065 brd.PlayMove(WHITE, HEX_CELL_G4); 00066 brd.PlayMove(WHITE, HEX_CELL_H3); 00067 brd.PlayMove(WHITE, HEX_CELL_I4); 00068 00069 brd.PlayMove(WHITE, HEX_CELL_G8); 00070 brd.PlayMove(WHITE, HEX_CELL_G9); 00071 brd.PlayMove(WHITE, HEX_CELL_I8); 00072 00073 brd.PlayMove(WHITE, HEX_CELL_B4); 00074 00075 brd.PlayMove(WHITE, HEX_CELL_J9); 00076 pastate.Update(); 00077 00078 std::vector<PatternHits> hits(FIRST_INVALID); 00079 bitset_t found = pastate.MatchOnBoard(brd.GetEmpty(), hashpat, 00080 PatternState::MATCH_ALL, hits); 00081 00082 // Ensure a, d, e, g were found 00083 BOOST_CHECK_EQUAL(found.count(), 6u); 00084 BOOST_CHECK(found.test(HEX_CELL_H4)); 00085 BOOST_CHECK(found.test(HEX_CELL_H8)); 00086 BOOST_CHECK(found.test(HEX_CELL_A5)); 00087 BOOST_CHECK(found.test(HEX_CELL_K9)); 00088 00089 // (a->b) 00090 BOOST_CHECK_EQUAL(hits[HEX_CELL_H4].size(), 1u); 00091 BOOST_CHECK_EQUAL(hits[HEX_CELL_H4][0].moves1().size(), 1u); 00092 BOOST_CHECK_EQUAL(hits[HEX_CELL_H4][0].moves1()[0], HEX_CELL_I3); 00093 00094 // (d->c) 00095 BOOST_CHECK_EQUAL(hits[HEX_CELL_H8].size(), 1u); 00096 BOOST_CHECK_EQUAL(hits[HEX_CELL_H8][0].moves1().size(), 1u); 00097 BOOST_CHECK_EQUAL(hits[HEX_CELL_H8][0].moves1()[0], HEX_CELL_H9); 00098 00099 // (e<->f) 00100 BOOST_CHECK_EQUAL(hits[HEX_CELL_A5].size(), 1u); 00101 BOOST_CHECK_EQUAL(hits[HEX_CELL_A5][0].moves1().size(), 1u); 00102 BOOST_CHECK_EQUAL(hits[HEX_CELL_A5][0].moves1()[0], HEX_CELL_A4); 00103 00104 BOOST_CHECK_EQUAL(hits[HEX_CELL_A4].size(), 1u); 00105 BOOST_CHECK_EQUAL(hits[HEX_CELL_A4][0].moves1().size(), 1u); 00106 BOOST_CHECK_EQUAL(hits[HEX_CELL_A4][0].moves1()[0], HEX_CELL_A5); 00107 00108 // (g<->h) 00109 BOOST_CHECK_EQUAL(hits[HEX_CELL_K9].size(), 1u); 00110 BOOST_CHECK_EQUAL(hits[HEX_CELL_K9][0].moves1().size(), 1u); 00111 BOOST_CHECK_EQUAL(hits[HEX_CELL_K9][0].moves1()[0], HEX_CELL_K8); 00112 00113 BOOST_CHECK_EQUAL(hits[HEX_CELL_K8].size(), 1u); 00114 BOOST_CHECK_EQUAL(hits[HEX_CELL_K8][0].moves1().size(), 1u); 00115 BOOST_CHECK_EQUAL(hits[HEX_CELL_K8][0].moves1()[0], HEX_CELL_K9); 00116 } 00117 00118 } 00119 00120 //---------------------------------------------------------------------------