1 #include "../../src/moves.h"
2 #include "../../src/board.h"
3 #include "../../src/position.h"
4 #include "gtest/gtest.h"
6 TEST(MoveListTest
, Size
)
8 int list_size
= (MAX_PLY
* MAX_MOVES
) * sizeof(ExtendedMove
);
9 int size
= list_size
+ sizeof(unsigned int);
11 // MoveList's internal array's size should not be a power of two
12 //EXPECT_NE(0, list_size & (list_size - 1));
14 EXPECT_EQ(128 * 256 * 4, list_size
);
15 EXPECT_EQ(list_size
+ 4, size
);
16 EXPECT_EQ(size
, sizeof(MoveList
));
19 TEST(MoveListTest
, Constructor
)
22 for (int i
= 0; i
< MAX_PLY
; ++i
) {
23 for (int j
= 0; j
< MAX_MOVES
; ++j
) {
25 EXPECT_TRUE(moves
[j
].is_null());
28 EXPECT_EQ(0, moves
[j
].value());
34 TEST(MoveListTest
, Assignement
)
38 for (int i
= 0; i
< MAX_PLY
; ++i
) {
39 for (int j
= 0; j
< MAX_MOVES
; ++j
) {
40 ExtendedMove
em1(m
, i
+ j
);
42 EXPECT_EQ(em1
, moves
[j
]);
43 EXPECT_EQ(em1
.value(), moves
[j
].value());
47 for (int i
= MAX_PLY
- 1; i
> 0; --i
) {
49 for (int j
= 0; j
< MAX_MOVES
; ++j
) {
50 ExtendedMove
em1(m
, i
+ j
);
51 EXPECT_EQ(em1
, moves
[j
]);
52 EXPECT_EQ(em1
.value(), moves
[j
].value());
56 for (int i
= 0; i
< MAX_PLY
; ++i
) {
57 for (int j
= 0; j
< MAX_MOVES
; ++j
) {
58 ExtendedMove
em1(m
, i
+ j
);
59 EXPECT_EQ(em1
, moves
[j
]);
60 EXPECT_EQ(em1
.value(), moves
[j
].value());
69 EXPECT_EQ(1, sizeof(MovesState
));
70 EXPECT_EQ(5, MOVES_STATE_SIZE
* sizeof(unsigned char));
72 sizeof(MoveList
*) + // 4-8 bytes
73 sizeof(Position
*) + // 4-8 bytes
74 sizeof(Board
*) + // 4-8 bytes
75 sizeof(Pieces
*) + // 4-8 bytes
76 sizeof(int) + // 4 bytes
77 sizeof(int) + // 4 bytes
78 MOVES_STATE_SIZE
* sizeof(unsigned char) + // 5 bytes
79 1 + // 1 byte (padding)
80 sizeof(MovesState
) + // 1 byte
81 sizeof(bool); // 1 byte
89 EXPECT_EQ(size
, sizeof(Moves
));
92 TEST(MovesTest
, Constructor
)
100 ExtendedMove
em(m
, 50);
102 EXPECT_EQ(em
.value(), list
[0].value());
104 EXPECT_EQ(0, list
.cur_ply());
106 Moves
moves(board
, pieces
, position
, list
);
108 // Test if MoveList::inc_ply() has been implicitly called by Moves()
109 EXPECT_EQ(1, list
.cur_ply());
111 EXPECT_EQ(BEST
, moves
.state());
113 EXPECT_EQ(0, moves
.count(BEST
));
114 EXPECT_EQ(0, moves
.count(GOOD_CAPTURES
));
115 EXPECT_EQ(0, moves
.count(KILLERS
));
116 EXPECT_EQ(0, moves
.count(BAD_CAPTURES
));
117 EXPECT_EQ(0, moves
.count(QUIET_MOVES
));
119 for (int i
= 0; i
< MAX_PLY
; ++i
) {
120 EXPECT_EQ(0, list
[i
].value());
123 EXPECT_EQ(em
.value(), list
[0].value());
126 TEST(MovesTest
, Score
)
132 Moves
moves(board
, pieces
, position
, list
);
134 Moves::init_mvv_lva_scores();
135 for (const PieceType
& v
: PIECE_TYPES
) {
136 for (const PieceType
& a
: PIECE_TYPES
) {
147 board
[from
] = Piece(WHITE
, a
);
148 board
[to
] = Piece(BLACK
, v
);
149 Move
capture(from
, to
, CAPTURE
);
150 Score score
= moves
.mvv_lva_score(capture
);
152 EXPECT_GT(BEST_SCORE
, score
);
153 EXPECT_LT(KILLERS_SCORE
, score
);
155 for (const PieceType
& v2
: PIECE_TYPES
) {
156 for (const PieceType
& a2
: PIECE_TYPES
) {
165 board
[from
] = Piece(WHITE
, a2
);
166 board
[to
] = Piece(BLACK
, v2
);
167 Move
capture2(from
, to
, CAPTURE
);
168 Score score2
= moves
.mvv_lva_score(capture2
);
171 EXPECT_GT(score
, score2
);
173 EXPECT_LT(score
, score2
);
176 EXPECT_LT(score
, score2
);
178 EXPECT_GT(score
, score2
);
180 EXPECT_EQ(score
, score2
);
189 // TODO Add test for Moves destructor (implicit call of MoveList::dec_ply())