-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCPerftSuite.cc
116 lines (97 loc) · 3.08 KB
/
CPerftSuite.cc
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
#include <sstream>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "CPerftSuite.h"
#include "CPerft.h"
/***************************************************************
* open
***************************************************************/
void CPerftSuite::open(const char *fileName)
{
m_testSuiteFile.open(fileName);
} // end of open
/***************************************************************
* close
***************************************************************/
void CPerftSuite::close()
{
m_testSuiteFile.close();
} // end of close
/***************************************************************
* operator <<
***************************************************************/
std::ostream& operator <<(std::ostream &os, const CPerftSuite &rhs)
{
return os << rhs.ToString();
}
/***************************************************************
* ToString
***************************************************************/
std::string CPerftSuite::ToString() const
{
std::stringstream ss;
ss << m_passCount << " test cases passed!" << std::endl;
ss << m_failCount << " test cases failed!" << std::endl;
return ss.str();
} // end of ToString
/***************************************************************
* DoTest
* Returns true on any errors.
***************************************************************/
bool CPerftSuite::DoTest()
{
if (!m_testSuiteFile.is_open())
{
std::cerr << "Could not open file. " << std::endl;
return true;
}
while (true)
{
std::string line;
getline(m_testSuiteFile, line);
if (m_testSuiteFile.eof())
{
return false;
}
const char *p;
if (m_board.read_from_fen(line.c_str(), &p))
{
std::cerr << "Error reading from FEN" << std::endl;
return true;
}
while (true)
{
p = strchr(p, ';');
if (!p)
{
m_passCount++;
break;
}
if (*(++p) == 'D')
{
CPerft perft(m_board);
char *np;
unsigned int depth = strtol(++p, &np, 10);
p=np;
unsigned long expLeafNodes = strtol(p, &np, 10);
std::cout << "depth " << depth << " leafnodes " << expLeafNodes << std::endl;
if (depth >= 1 && expLeafNodes < 10000000)
{
perft.clear();
perft.search(depth);
if (perft.getLeafNodes() != expLeafNodes)
{
std::cout << "FAILED!" << std::endl;
std::cout << m_board << std::endl;
std::cout << perft << std::endl;
std::cout << std::endl;
m_failCount++;
break;
}
}
p=np;
}
} // end of while true (reading a line)
} // end of while true (reading from file)
} // end of DoTest