-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperft.c
103 lines (88 loc) · 1.94 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
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
94
95
96
97
98
99
100
101
102
103
//perft.c
#include "stdio.h"
#include <string.h>
#include "header.h"
long leafnodes;
void perft(int depth, S_BOARD *pos)
{
ASSERT(checkboard(pos));
//printf("depth %d ",depth);
if(depth==0)
{
leafnodes++;
//printf(" *check* ");
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;
//printf(" mv%4s",prmove(list->moves[movenum].move));
perft(depth - 1, pos);
takemove(pos);
}
return ;
}
void perfttest(int depth, S_BOARD *pos)
{
int d=6;
char * line = NULL;
size_t len = 0;
ssize_t read;
char buf[1000];
FILE *fptr,*fp;
fptr = fopen("out","w");
if(fptr==NULL)
{
printf("w ERROR");
exit(1);
}
fp = fopen("fens","r");
if (fp == NULL)
{
printf("r ERROR");
exit(1);
}
while ((read = getline(&line, &len, fp)) != -1)
{
line[strlen(line)-1]='\0';
fprintf(fptr,"%s;",line);
//printf("%s;",line);
parse_fen(line,pos);
//for(d=1;d<=depth;d++)
{
ASSERT(checkboard(pos));
//printboard(pos);
fprintf(fptr,"D%d ",d);
//printf(" D%d ",d);
leafnodes =0;
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(d-1, pos);
takemove(pos);
long oldnodes = leafnodes - cumnodes;
//printf("move %d : %s : %ld\n",movenum+1,prmove(move),oldnodes);
}
fprintf(fptr,"%ld ; ",leafnodes);
//printf("%ld; ",leafnodes);
}
fprintf(fptr,"\n");
//printf("\n");
}
fclose(fp);
fclose(fptr);
if (line)
free(line);
return;
}