-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmark.cpp
executable file
·127 lines (98 loc) · 3.2 KB
/
benchmark.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "benchmark.h"
#include <fstream>
//#include <boost/algorithm/string.hpp>
#include <sstream>
#include <vector>
#include <string>
#include <iostream>
#include "fenstring.h"
#include "movegenerator.h"
#include "constants.h"
#include "console.h"
#include "search.h"
#include "board.h"
#include "stopwatch.h"
// ONLY USEFUL FOR DEBUG
namespace Napoleon
{
Benchmark::Benchmark(Board& board)
:board(board)
{
}
void Benchmark::Start(int depth)
{
std::ifstream fstream("ECM.epd");
std::string str = "";
std::vector<std::string> strings;
std::vector<std::string> fields;
std::string buff;
unsigned long nodesVisited = 0;
int correct = 0;
while (getline(fstream, buff))
{
strings.push_back(buff);
}
StopWatch watch = StopWatch::StartNew();
int i = 1;
for (std::string line : strings)
{
std::cout << i++ << " ";
Utils::String::Split(fields, line, ';');
FenString epd(fields[0]);
board.LoadGame(epd.FullString);
Search::searchInfo.SetDepthLimit(depth);
Move move = Search::StartThinking(SearchType::Infinite, board, false);
if(move.ToSan(board) == epd.BestMove)
correct++;
nodesVisited += Search::searchInfo.Nodes();
}
std::cout << str << std::endl;
std::cout << "correct: " << correct << "/" << strings.size() << std::endl;
std::cout << "rate: " << ((float)correct/(float)strings.size())*100 << std::endl;
std::cout << "nodes visited: " << nodesVisited << std::endl;
std::cout << "elapsed time(ms): " << std::fixed << watch.ElapsedMilliseconds() << std::endl;
fstream.close();
}
void Benchmark::CutoffTest()
{
std::ifstream ff("perft.epd");
std::vector<std::string> strings;
std::vector<std::string> fields;
std::string buff;
while (getline(ff, buff))
{
strings.push_back(buff);
}
for (unsigned i=0; i<50; i++)
{
Utils::String::Split(fields, strings[i], ';');
board.LoadGame(fields[0]);
Search::StartThinking(SearchType::Infinite, board);
std::cout << i << std::endl;
}
std::cout << "Cutoff on first move: " << board.FirstMoveCutoff << std::endl;
std::cout << "Total Cutoffs: " << board.TotalCutoffs << std::endl;
std::cout << Console::Green << "First Move Cutoff percentage: " << ((float)board.FirstMoveCutoff / (float)board.TotalCutoffs) * 100 << "%" << std::endl;
std::cout << Console::Reset << std::endl;
}
unsigned long long Benchmark::Perft(int depth)
{
int pos = 0;
Move moves[Constants::MaxMoves];
unsigned long long nodes = 0;
MoveGenerator::GetLegalMoves(moves, pos, board);
if (depth == 1)
{
return pos;
}
if (depth == 0)
return 1;
for (int i = 0; i < pos; i++)
{
board.MakeMove(moves[i]);
nodes += Perft(depth - 1);
board.UndoMove(moves[i]);
}
return nodes;
}
}