-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperft.cpp
More file actions
54 lines (40 loc) · 1.36 KB
/
Copy pathperft.cpp
File metadata and controls
54 lines (40 loc) · 1.36 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
#include "defs.h"
#include <iostream>
#include <chrono>
long nodes = 0;
void perft_driver(int depth) {
if (depth == 0) {
nodes++;
return;
}
MoveList move_list;
generate_moves(&move_list);
for (int i = 0; i < move_list.count; i++) {
if (!make_move(move_list.moves[i], move_list.moves[i].capture)) {
continue;
}
perft_driver(depth - 1);
take_back();
}
}
void perft_test(int depth) {
std::cout << "\n Performance Test (Perft) Depth: " << depth << "\n";
nodes = 0;
auto start = std::chrono::high_resolution_clock::now();
MoveList move_list;
generate_moves(&move_list);
for (int i = 0; i < move_list.count; i++) {
make_move(move_list.moves[i], move_list.moves[i].capture);
long old_nodes = nodes;
perft_driver(depth - 1);
take_back();
long current_nodes = nodes - old_nodes;
}
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "\n Nodes: " << nodes;
std::cout << "\n Time: " << duration.count() << " ms";
if(duration.count() > 0)
std::cout << "\n NPS: " << (nodes * 1000) / duration.count() << " (Nodes/Sec)";
std::cout << "\n\n";
}