-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
95 lines (84 loc) · 2.65 KB
/
Copy pathtest.cpp
File metadata and controls
95 lines (84 loc) · 2.65 KB
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
#include <iostream>
#include "engine_API.h"
void first_move_test(EngineAPI& engine)
// Test how often each first move occurs.
{
int number[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int trials = 10000;
engine.new_game();
for (int n=1; n<=trials; n++)
{
number[engine.engine_move()]++;
}
std::cout << "0: " << number[0] << " times" << std::endl;
std::cout << "1: " << number[1] << " times" << std::endl;
std::cout << "2: " << number[2] << " times" << std::endl;
std::cout << "3: " << number[3] << " times" << std::endl;
std::cout << "4: " << number[4] << " times" << std::endl;
std::cout << "5: " << number[5] << " times" << std::endl;
std::cout << "6: " << number[6] << " times" << std::endl;
std::cout << "7: " << number[7] << " times" << std::endl;
std::cout << "8: " << number[8] << " times" << std::endl;
}
int single_game(EngineAPI& engine1, EngineAPI& engine2, bool engine1_begin)
// Let engine1 and engine2 play a game against each other.
// Return 1 if engine1 wins, 0 if draw and 2 if engine2 wins.
{
bool engine1_to_play = engine1_begin;
int move;
engine1.new_game();
engine2.new_game();
while (true)
{
if (engine1_to_play)
{
move = engine1.engine_move();
engine1.make_move(move);
engine2.make_move(move);
if (engine1.three_in_a_row(move))
return 1;
if (engine1.board_full())
return 0;
}
else
{
move = engine2.engine_move();
engine1.make_move(move);
engine2.make_move(move);
if (engine1.three_in_a_row(move))
return 2;
if (engine1.board_full())
return 0;
}
engine1_to_play = not engine1_to_play;
}
}
int main()
{
EngineAPI engine1;
engine1.set_difficulty_level(2);
EngineAPI engine2;
engine2.set_difficulty_level(3);
int number_of_games = 100;
int engine1_wins = 0;
int engine2_wins = 0;
int draws = 0;
bool engine1_begin = true;
int result;
for (int n=1; n<=number_of_games; n++)
{
result = single_game(engine1, engine2, engine1_begin);
if (result == 1)
engine1_wins++;
if (result == 2)
engine2_wins++;
if (result == 0)
draws++;
engine1_begin = not engine1_begin;
}
std::cout << "Number of games: " << number_of_games << std::endl;
std::cout << "Engine 1 wins: " << engine1_wins << std::endl;
std::cout << "Engine 2 wins: " << engine2_wins << std::endl;
std::cout << "Draws: " << draws << std::endl;
return 0;
}