| 1 |
#include "osl/checkmate/analyzer/proofTreeDepth.h" |
| 2 |
#include "osl/checkmate/dualCheckmateSearcher.h" |
| 3 |
#include "osl/state/hashEffectState.h" |
| 4 |
#include "osl/record/csaString.h" |
| 5 |
#include <cppunit/TestCase.h> |
| 6 |
#include <cppunit/extensions/HelperMacros.h> |
| 7 |
|
| 8 |
using namespace osl; |
| 9 |
using namespace osl::checkmate; |
| 10 |
using namespace osl::checkmate::analyzer; |
| 11 |
|
| 12 |
class ProofTreeDepthTest : public CppUnit::TestFixture |
| 13 |
{ |
| 14 |
CPPUNIT_TEST_SUITE(ProofTreeDepthTest); |
| 15 |
CPPUNIT_TEST(testConstruction); |
| 16 |
CPPUNIT_TEST(testZero); |
| 17 |
CPPUNIT_TEST(testOne); |
| 18 |
CPPUNIT_TEST(testThree); |
| 19 |
CPPUNIT_TEST_SUITE_END(); |
| 20 |
public: |
| 21 |
void testConstruction() |
| 22 |
{ |
| 23 |
ProofTreeDepth depth_analyzer; |
| 24 |
} |
| 25 |
void testZero(); |
| 26 |
void testOne(); |
| 27 |
void testThree(); |
| 28 |
}; |
| 29 |
|
| 30 |
CPPUNIT_TEST_SUITE_REGISTRATION(ProofTreeDepthTest); |
| 31 |
|
| 32 |
const size_t limit = 400000; |
| 33 |
void ProofTreeDepthTest::testZero() |
| 34 |
{ |
| 35 |
SimpleState sstate=CsaString( |
| 36 |
"P1 * * * * * * * -OU * \n" |
| 37 |
"P2 * * * * * * * +KI * \n" |
| 38 |
"P3 * * * * * * * +FU * \n" |
| 39 |
"P4 * * * * * * * * * \n" |
| 40 |
"P5 * * * * * * * * * \n" |
| 41 |
"P6 * * * * * * * * * \n" |
| 42 |
"P7 * * * * * * * * * \n" |
| 43 |
"P8 * * * * * * * * * \n" |
| 44 |
"P9 * * +OU * * * * * * \n" |
| 45 |
"P-00AL\n" |
| 46 |
"-\n").getInitialState(); |
| 47 |
HashEffectState state(sstate); |
| 48 |
DualCheckmateSearcher<> checker(limit); |
| 49 |
const PathEncoding path(WHITE); |
| 50 |
const bool lose = checker.isLosingState(10, state, state.getHash(), path); |
| 51 |
CPPUNIT_ASSERT_EQUAL(true, lose); |
| 52 |
|
| 53 |
const CheckHashTable& table = checker.getTable(BLACK); |
| 54 |
const CheckHashRecord *record = table.find(state.getHash()); |
| 55 |
ProofTreeDepth depth_analyzer; |
| 56 |
CPPUNIT_ASSERT_EQUAL(0, depth_analyzer.depth(record, false)); |
| 57 |
} |
| 58 |
|
| 59 |
void ProofTreeDepthTest::testOne() |
| 60 |
{ |
| 61 |
SimpleState sstate=CsaString( |
| 62 |
"P1 * * * * * * * -OU * \n" |
| 63 |
"P2 * * * * * * * * * \n" |
| 64 |
"P3 * * * * * * * +FU * \n" |
| 65 |
"P4 * * * * * * * * * \n" |
| 66 |
"P5 * * * * * * * * * \n" |
| 67 |
"P6 * * * * * * * * * \n" |
| 68 |
"P7 * * * * * * * * * \n" |
| 69 |
"P8 * * * * * * * * * \n" |
| 70 |
"P9 * * +OU * * * * * * \n" |
| 71 |
"P+00KI\n" |
| 72 |
"P-00AL\n" |
| 73 |
"+\n").getInitialState(); |
| 74 |
HashEffectState state(sstate); |
| 75 |
DualCheckmateSearcher<> checker(100); |
| 76 |
const PathEncoding path(BLACK); |
| 77 |
Move check_move; |
| 78 |
AttackOracleAges oracle_age; |
| 79 |
const bool win = checker.isWinningState(10, state, state.getHash(), path, |
| 80 |
check_move, oracle_age); |
| 81 |
CPPUNIT_ASSERT_EQUAL(true, win); |
| 82 |
|
| 83 |
const CheckHashTable& table = checker.getTable(BLACK); |
| 84 |
const CheckHashRecord *record = table.find(state.getHash()); |
| 85 |
ProofTreeDepth depth_analyzer; |
| 86 |
CPPUNIT_ASSERT_EQUAL(1, depth_analyzer.depth(record, true)); |
| 87 |
} |
| 88 |
|
| 89 |
void ProofTreeDepthTest::testThree() |
| 90 |
{ |
| 91 |
SimpleState sstate=CsaString( |
| 92 |
"P1 * * * * * * * * * \n" |
| 93 |
"P2 * * * * * * * -OU * \n" |
| 94 |
"P3 * * * * * * * * * \n" |
| 95 |
"P4 * * * * * * * +FU * \n" |
| 96 |
"P5 * * * * * * * * * \n" |
| 97 |
"P6 * * * * * * * * * \n" |
| 98 |
"P7 * * * * * * * * * \n" |
| 99 |
"P8 * * * * * * * * * \n" |
| 100 |
"P9 * * +OU * * * * * * \n" |
| 101 |
"P+00KI00KI\n" |
| 102 |
"P-00AL\n" |
| 103 |
"+\n").getInitialState(); |
| 104 |
HashEffectState state(sstate); |
| 105 |
DualCheckmateSearcher<> checker(100); |
| 106 |
const PathEncoding path(BLACK); |
| 107 |
Move check_move; |
| 108 |
AttackOracleAges oracle_age; |
| 109 |
const bool win = checker.isWinningState(50, state, state.getHash(), path, |
| 110 |
check_move, oracle_age); |
| 111 |
CPPUNIT_ASSERT_EQUAL(true, win); |
| 112 |
|
| 113 |
const CheckHashTable& table = checker.getTable(BLACK); |
| 114 |
const CheckHashRecord *record = table.find(state.getHash()); |
| 115 |
ProofTreeDepth depth_analyzer; |
| 116 |
CPPUNIT_ASSERT_EQUAL(3, depth_analyzer.depth(record, true)); |
| 117 |
} |
| 118 |
|
| 119 |
// ;;; Local Variables: |
| 120 |
// ;;; mode:c++ |
| 121 |
// ;;; c-basic-offset:2 |
| 122 |
// ;;; End: |