-
Notifications
You must be signed in to change notification settings - Fork 1
/
testminimax.cpp
66 lines (56 loc) · 1.71 KB
/
testminimax.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
#include <iostream>
#include "common.hpp"
#include "player.hpp"
#include "board.hpp"
// Use this file to test your minimax implementation (2-ply depth, with a
// heuristic of the difference in number of pieces).
int main(int argc, char *argv[])
{
// Create board with example state. You do not necessarily need to use
// this, but it's provided for convenience.
char boardData[64] =
{
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', 'b', ' ', ' ', ' ', ' ', ' ', ' ',
'b', 'w', 'b', 'b', 'b', 'b', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
};
Board *board = new Board();
board->setBoard(boardData);
// Initialize player as the white player, and set testing_minimax flag and
// the board.
Player *player = new Player(WHITE);
player->testingMinimax = true;
player->setBoard(boardData);
// Get player's move and check if it's right.
Move *move = player->doMove(nullptr, 0);
if (move != nullptr && move->x == 1 && move->y == 1)
{
std::cout << "Correct move: (1, 1)" << std::endl;
}
else
{
std::cout << "Wrong move: got ";
if (move == nullptr)
{
std::cout << "PASS";
}
else
{
std::cout << "(" << move->x << ", " << move->y << ")";
}
std::cout << ", expected (1, 1)" << std::endl;
}
// Clean up memory.
delete board;
delete player;
if (move != nullptr)
{
delete move;
}
return 0;
}