-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperft.c
More file actions
83 lines (52 loc) · 1.44 KB
/
perft.c
File metadata and controls
83 lines (52 loc) · 1.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// perft.c
#include "perft.h"
#include "util.h"
#include "io.h"
#include "makemove.h"
#include "movegen.h"
#include "board.h"
#include <stdio.h>
#define PERFTFEN "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1"
long leafNodes;
void perft(S_BOARD *pos, int depth) {
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(pos, depth-1);
takeMove(pos);
}
return;
}
void perftTest(S_BOARD *pos, int depth) {
ASSERT(checkBoard(pos));
printBoard(pos);
printf("\nStarting Test To Depth:%d\n",depth);
leafNodes = 0;
long 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(pos, depth-1);
takeMove(pos);
long oldnodes = leafNodes - cumnodes;
printf("move %d : %s : %ld\n", moveNum + 1, prmove(move), oldnodes);
}
printf("\nTest Complete : %ld nodes visited in %ldms\n",leafNodes, getTimeMs() - start);
return;
}