-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.cpp
93 lines (86 loc) · 3.61 KB
/
tests.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
/*
Clarity
Copyright (C) 2024 Joseph Pasfield
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "testessentials.h"
#include "testsuites.h"
// runs a single perft test
int perft(Board &board, int depth) {
if(depth == 0) return 1;
std::array<Move, 256> moves;
int numMoves = board.getMoves(moves);
int result = 0;
for(int i = 0; i < numMoves; i++) {
if(board.makeMove<false>(moves[i])) {
result += perft(board, depth-1);
board.undoMove<false>();
}
}
return result;
}
// runs an entire suite of perft tests
void runPerftSuite(int number) {
if(number == 0) {
int i = 0;
int passed = 0;
int failed = 0;
double total = 0;
clock_t start = clock();
for(PerftTest test : etherealSuite) {
i++;
Board board(test.fen);
int result = perft(board, test.depth);
total += result;
if(result == test.expectedOutput) {
std::cout << "Test " << std::to_string(i) << " Passed\n";
passed++;
} else {
std::cout << "Test " << std::to_string(i) << " Failed, outputted " << std::to_string(result) << " With fen string " << test.fen << " and depth " << std::to_string(test.depth) << '\n';
failed++;
}
}
clock_t end = clock();
std::cout << "Passed " << std::to_string(passed) << ", Failed " << std::to_string(failed) << '\n';
std::cout << "Tests took: " << std::to_string((end-start)/static_cast<double>(1000)) << '\n';
std::cout << "Total nodes: " << std::to_string(static_cast<int>(total)) << '\n';
std::cout << "NPS: " << std::to_string(total / ((end-start)/static_cast<double>(1000))) << '\n';
}
}
// runs perft split by what the first move that is done is
void splitPerft(Board board, int depth) {
std::array<Move, 256> moves;
int numMoves = board.getMoves(moves);
int total = 0;
clock_t start = clock();
for(int i = 0; i < numMoves; i++) {
if(board.makeMove<false>(moves[i])) {
int result = perft(board, depth - 1);
board.undoMove<false>();
total += result;
std::cout << toLongAlgebraic(moves[i]) << ": " << std::to_string(result) << '\n';
}
}
clock_t end = clock();
std::cout << "Total: " << std::to_string(total) << '\n';
std::cout << "Time: " << std::to_string((end-start)/static_cast<double>(1000)) << '\n';
std::cout << "NPS: " << std::to_string(total / ((end-start)/static_cast<double>(1000))) << '\n';
}
// runs an individual perft test, and outputs the results
void individualPerft(Board board, int depth) {
clock_t start = clock();
int result = perft(board, depth);
clock_t end = clock();
std::cout << "Result: " << std::to_string(result) << '\n';
std::cout << "Time: " << std::to_string((end-start)/static_cast<double>(1000)) << '\n';
std::cout << "NPS: " << std::to_string(result / ((end-start)/static_cast<double>(1000))) << '\n';
}