File: chesswrappedtest.cpp

package info (click to toggle)
tagua 1.0~alpha2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 7,178
  • sloc: cpp: 26,149; ansic: 13,039; makefile: 182; ruby: 87; sh: 39
file content (117 lines) | stat: -rw-r--r-- 3,252 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "chesswrappedtest.h"
#include "hlvariant/tagua_wrapped.h"
#include "hlvariant/chess/variant.h"
#include "hlvariant/variantdata.h"

#define MOVE(x) { MovePtr _tmp = m_pos->getMove(#x);     \
                  CPPUNIT_ASSERT(_tmp);                  \
                  m_pos->move(_tmp); }

CPPUNIT_TEST_SUITE_REGISTRATION(ChessWrappedTest);

typedef HLVariant::Chess::Variant Chess;
typedef VariantData<Chess>::LegalityCheck LegalityCheck;
typedef VariantData<Chess>::MoveGenerator MoveGenerator;
typedef LegalityCheck::GameState GameState;
typedef GameState::Move ChessMove;
typedef VariantData<Chess>::Piece ChessPiece;

void ChessWrappedTest::setUp() {
  m_pos = PositionPtr(new HLVariant::WrappedPosition<Chess>(GameState()));
}

void ChessWrappedTest::tearDown() {
  m_pos.reset();
}

void ChessWrappedTest::test_setup() {
  m_pos->setup();
  
  CPPUNIT_ASSERT(m_pos->get(Point(4, 1)));
  CPPUNIT_ASSERT_EQUAL(QString("black_pawn"), m_pos->get(Point(4, 1))->name());
  
  CPPUNIT_ASSERT(m_pos->get(Point(4, 6)));
  CPPUNIT_ASSERT(m_pos->get(Point(4, 6))->name() == "white_pawn");
  
  CPPUNIT_ASSERT(!m_pos->get(Point(5, 5)));
  
  CPPUNIT_ASSERT(m_pos->get(Point(0, 0)));
  CPPUNIT_ASSERT(m_pos->get(Point(0, 0))->name() == "black_rook");
}

void ChessWrappedTest::test_move() {
  m_pos->setup();
  
  MovePtr move(new HLVariant::WrappedMove<Chess>(ChessMove(Point(4, 6), Point(4, 4))));
  CPPUNIT_ASSERT(m_pos->testMove(move));
  
  m_pos->move(move);
  
  CPPUNIT_ASSERT(!m_pos->get(Point(4, 6)));
  CPPUNIT_ASSERT(m_pos->get(Point(4, 4))->name() == "white_pawn");
}
void ChessWrappedTest::test_movable() {
  m_pos->setup();
  
  TurnTest test;
  CPPUNIT_ASSERT_EQUAL(NoAction, m_pos->movable(test, Point(4, 6)));
  CPPUNIT_ASSERT_EQUAL(NoAction, m_pos->droppable(test, 0));
  
  test.setSimplePolicy(0, true);  
  CPPUNIT_ASSERT_EQUAL(Moving, m_pos->movable(test, Point(4, 6)));
  CPPUNIT_ASSERT_EQUAL(NoAction, m_pos->movable(test, Point(5, 5)));
  CPPUNIT_ASSERT_EQUAL(NoAction, m_pos->movable(test, Point(7, 1)));
  
  CPPUNIT_ASSERT_EQUAL(Moving, m_pos->droppable(test, 0));
  CPPUNIT_ASSERT_EQUAL(NoAction, m_pos->droppable(test, 1));
  
  test.setSimplePolicy(1, true);
  CPPUNIT_ASSERT_EQUAL(Premoving, m_pos->movable(test, Point(6, 0)));
}

void ChessWrappedTest::test_san1() {
  m_pos->setup();
  
  MovePtr move(new HLVariant::WrappedMove<Chess>(ChessMove(Point(4, 6), Point(4, 4))));
  CPPUNIT_ASSERT_EQUAL(QString("e4"), move->SAN(m_pos));
}

void ChessWrappedTest::test_get_move1() {
  m_pos->setup();
  
  MovePtr move = m_pos->getMove("e4");
  CPPUNIT_ASSERT_EQUAL(QString("e4"), move->SAN(m_pos));
}

void ChessWrappedTest::test_fools_mate() {
  m_pos->setup();
  
  MOVE(f3);
  MOVE(e5);
  MOVE(g4);
  MOVE(Qh4);
  
  HLVariant::WrappedPosition<Chess>* pos = 
    dynamic_cast<HLVariant::WrappedPosition<Chess>*>(m_pos.get());

  CPPUNIT_ASSERT(pos);
  
  MoveGenerator generator(pos->inner());
  CPPUNIT_ASSERT(generator.check(static_cast<ChessPiece::Color>(m_pos->turn())));
  CPPUNIT_ASSERT(generator.stalled());
}

void ChessWrappedTest::test_check() {
  m_pos->setup();
  
  MOVE(e4);
  MOVE(d5);
  MOVE(Bb5);
  
  CPPUNIT_ASSERT(!m_pos->getMove("Na6"));
  CPPUNIT_ASSERT(m_pos->getMove("Nc6"));
}



#undef MOVE