-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperft.c
56 lines (44 loc) · 1.36 KB
/
perft.c
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
#include "include/definitions.h"
long leafNodes;
void perft(int depth, board *position) {
ASSERT(checkBoard(position));
if(depth == 0) {
leafNodes++;
return;
}
movelist newList[1];
generateAllMoves(position, newList);
int moveNum = 0;
for(moveNum = 0; moveNum < newList -> numberOfMoves; moveNum++) {
if(!makeMove(position, newList -> moves[moveNum].move)) {
continue;
}
perft(depth - 1, position);
takeMove(position);
}
return;
}
void perftTest(int depth, board *position) {
ASSERT(checkBoard(position));
printBoard(position);
printf("\nStarting Test to Depth: %d\n", depth);
leafNodes = 0;
int start = getTimeInMiliseconds();
movelist newList[1];
generateAllMoves(position, newList);
int move;
int moveNum = 0;
for(moveNum = 0; moveNum < newList -> numberOfMoves; moveNum++) {
move = newList -> moves[moveNum].move;
if(!makeMove(position, move)) {
continue;
}
long cumNodes = leafNodes;
perft(depth - 1, position);
takeMove(position);
long oldNodes = leafNodes - cumNodes;
printf("Move %d: %s : %ld\n", moveNum + 1, printMove(move), oldNodes);
}
printf("\nTest Complete: %ld Nodes Visited in %dms\n", leafNodes, getTimeInMiliseconds() - start);
return;
}