-
Notifications
You must be signed in to change notification settings - Fork 0
/
perft.c
72 lines (45 loc) · 1.26 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
57
58
59
60
#include "defs.h"
#include "stdio.h"
long leafNodes;
void Perft(int depth, S_BOARD *pos) {
ASSERT(CheckBoard(pos));
if(depth == 0) {
leafNodes++;
return;
}
S_MOVELIST list[1];
GenerateAllMoves(pos,list);
int MoveNum = 0;
for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
if ( !MakeMove(pos,list->moves[MoveNum].move)) {
continue;
}
Perft(depth - 1, pos);
TakeMove(pos);
}
return;
}
void PerftTest(int depth, S_BOARD *pos) {
ASSERT(CheckBoard(pos));
PrintBoard(pos);
printf("\nStarting Test To Depth:%d\n",depth);
leafNodes = 0;
int start = GetTimeMs();
S_MOVELIST list[1];
GenerateAllMoves(pos,list);
int move;
int MoveNum = 0;
for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
move = list->moves[MoveNum].move;
if ( !MakeMove(pos,move)) {
continue;
}
long cumnodes = leafNodes;
Perft(depth - 1, pos);
TakeMove(pos);
long oldnodes = leafNodes - cumnodes;
printf("move %d : %s : %ld\n",MoveNum+1,PrMove(move),oldnodes);
}
printf("\nTest Complete : %ld nodes visited in %dms\n",leafNodes, GetTimeMs() - start);
return;
}