-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect4_test.cpp
70 lines (66 loc) · 1.87 KB
/
Connect4_test.cpp
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
#include "pch.h"
#include "..\BoardGamesEngine\Games\Connect4.h"
#include "..\BoardGamesEngine\Algorithms.h"
TEST(Connect4_test, all_legal_moves)
{
Connect4 connect4;
int count = 0;
bool first = true;
Move<7, 6> last_move;
for (auto move : connect4.all_legal_moves())
{
if (first)
{
EXPECT_EQ(move.square.x(), 3);
first = false;
}
EXPECT_TRUE(move.is_valid());
EXPECT_EQ(move.square.y(), 0);
EXPECT_TRUE(connect4.is_legal(move));
count++;
last_move = move;
}
EXPECT_TRUE(last_move.square.x() == 0 || last_move.square.x() == 6);
EXPECT_EQ(count, 7);
}
TEST(Connect4_test, play_20_moves)
{
Connect4 connect4;
Move<7, 6> move;
for (int i = 0; i < 20; i++)
{
move = MinMax<Connect4>::FindBestMove(connect4, 6);
GTEST_LOG_(INFO) << move.chess_notation();
EXPECT_TRUE(connect4.is_legal(move)) << " not legal move";
bool game_over = connect4.easycheck_winning_move(move);
EXPECT_FALSE(game_over) << " game over!";
connect4 += move;
}
}
TEST(Connect4_test, FourByThree)
{
#define S(str) SquareBase<4, 3>(str)
std::vector<Move<4, 3>> moves = {
Move<4, 3>(S("C1"), Field::X),
Move<4, 3>(S("B1"), Field::O),
Move<4, 3>(S("B2"), Field::X),
Move<4, 3>(S("B3"), Field::O),
Move<4, 3>(S("C2"), Field::X),
Move<4, 3>(S("C3"), Field::O),
Move<4, 3>(S("A1"), Field::X),
Move<4, 3>(S("A2"), Field::O),
Move<4, 3>(S("A3"), Field::X),
};
MNKGravity<4, 3, 3> FourByThree;
for (int i = 0; i < moves.size(); i++)
{
auto move = MinMax<MNKGravity<4, 3, 3>, KillerOptions::Multiple, false>::FindBestMove(FourByThree, 12);
GTEST_LOG_(INFO) << move.chess_notation();
if (i < moves.size() - 1)
EXPECT_FALSE(FourByThree.easycheck_winning_move(move));
else
EXPECT_TRUE(FourByThree.easycheck_winning_move(move));
FourByThree += move;
EXPECT_EQ(moves[i], move) << "Expected move: " << moves[i].chess_notation() << " but got: " << move.chess_notation();
}
}