1 #include "chessgamestatetest.h"
4 #include <defaultstate.h>
7 #include <statefactory.h>
8 #include <types/chess/pawn.h>
9 #include <types/chess/king.h>
10 #include <types/chess/queen.h>
11 #include <types/chess/rook.h>
12 #include <types/chess/knight.h>
13 #include <types/chess/bishop.h>
16 #include "test_utils.h"
18 CPPUNIT_TEST_SUITE_REGISTRATION(ChessGameStateTest
);
20 Variant
* chess_variant_factory();
22 using namespace Chess
;
24 void ChessGameStateTest::setUp() {
25 m_chess
= chess_variant_factory();
26 IStateFactory
* fact
= requestComponent
<IStateFactory
>(
27 m_chess
, "state_factory");
28 m_state
= dynamic_cast<IDefaultState
*>(fact
->createState());
32 void ChessGameStateTest::tearDown() {
37 void ChessGameStateTest::test_setup() {
38 for (int i
= 0; i
< 8; i
++) {
40 Piece(Black::self(), Pawn::self()),
41 m_state
->board()->get(Point(i
, 1)));
43 Piece(White::self(), Pawn::self()),
44 m_state
->board()->get(Point(i
, 6)));
45 CPPUNIT_ASSERT_EQUAL(Piece(),
46 m_state
->board()->get(Point(i
, 4)));
50 Piece(Black::self(), Rook::self()),
51 m_state
->board()->get(Point(0, 0)));
53 Piece(White::self(), King::self()),
54 m_state
->board()->get(Point(4, 7)));
57 void ChessGameStateTest::test_simple_move() {
58 m_state
->move(Move(Point(4, 6), Point(4, 5))); // e3
59 CPPUNIT_ASSERT_EQUAL(Piece(),
60 m_state
->board()->get(Point(4, 6)));
62 Piece(White::self(), Pawn::self()),
63 m_state
->board()->get(Point(4, 5)));
66 void ChessGameStateTest::test_capture() {
67 m_state
->move(Move(Point(4, 6), Point(4, 4))); // e4
68 m_state
->move(Move(Point(3, 1), Point(3, 3))); // d5
69 m_state
->move(Move(Point(4, 4), Point(3, 3))); // exd5
72 Piece(White::self(), Pawn::self()),
73 m_state
->board()->get(Point(3, 3)));
76 void ChessGameStateTest::test_en_passant() {
77 m_state
->move(Move(Point(4, 6), Point(4, 4))); // e4
78 m_state
->move(Move(Point(7, 1), Point(7, 2))); // h6
79 m_state
->move(Move(Point(4, 4), Point(4, 3))); // e5
81 Move
d5(Point(3, 1), Point(3, 3));
82 d5
.setType("en_passant_trigger");
87 m_state
->flags().get("en_passant_square").value
<Point
>());
89 Move
exd6(Point(4, 3), Point(3, 2));
90 exd6
.setType("en_passant_capture");
93 CPPUNIT_ASSERT_EQUAL(Piece(),
94 m_state
->board()->get(Point(3, 3)));
97 void ChessGameStateTest::test_kingside_castling() {
98 Move
oo(Point(4, 7), Point(6, 7));
99 oo
.setType("king_side_castling");
102 CPPUNIT_ASSERT_EQUAL(
103 Piece(White::self(), King::self()),
104 m_state
->board()->get(Point(6, 7)));
105 CPPUNIT_ASSERT_EQUAL(
106 Piece(White::self(), Rook::self()),
107 m_state
->board()->get(Point(5, 7)));
108 CPPUNIT_ASSERT_EQUAL(Piece(),
109 m_state
->board()->get(Point(7, 7)));
112 void ChessGameStateTest::test_queenside_castling() {
113 Move
oo(Point(4, 7), Point(2, 7));
114 oo
.setType("queen_side_castling");
117 CPPUNIT_ASSERT_EQUAL(
118 Piece(White::self(), King::self()),
119 m_state
->board()->get(Point(2, 7)));
120 CPPUNIT_ASSERT_EQUAL(
121 Piece(White::self(), Rook::self()),
122 m_state
->board()->get(Point(3, 7)));
123 CPPUNIT_ASSERT_EQUAL(Piece(),
124 m_state
->board()->get(Point(0, 7)));
127 void ChessGameStateTest::test_promotion() {
128 m_state
->board()->set(Point(7, 1), Piece(White::self(), Pawn::self()));
129 Move
h8B(Point(7, 1), Point(7, 0), Bishop::self());
132 CPPUNIT_ASSERT_EQUAL(
133 Piece(White::self(), Bishop::self()),
134 m_state
->board()->get(Point(7, 0)));