-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.c
124 lines (102 loc) · 2.78 KB
/
validate.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// validate.c
#include "defs.h"
#include "stdio.h"
#include "string.h"
int MoveListOk(const S_MOVELIST *list, const S_BOARD *pos) {
if(list->count < 0 || list->count >= MAXPOSITIONMOVES) {
return FALSE;
}
int MoveNum;
int from = 0;
int to = 0;
for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
to = TOSQ(list->moves[MoveNum].move);
from = FROMSQ(list->moves[MoveNum].move);
if(!SqOnBoard(to) || !SqOnBoard(from)) {
return FALSE;
}
if(!PieceValid(pos->pieces[from])) {
PrintBoard(pos);
return FALSE;
}
}
return TRUE;
}
int SqIs120(const int sq) {
return (sq>=0 && sq<120);
}
int PceValidEmptyOffbrd(const int pce) {
return (PieceValidEmpty(pce) || pce == OFFBOARD);
}
int SqOnBoard(const int sq) {
return FilesBrd[sq]==OFFBOARD ? 0 : 1;
}
int SideValid(const int side) {
return (side==WHITE || side == BLACK) ? 1 : 0;
}
int FileRankValid(const int fr) {
return (fr >= 0 && fr <= 7) ? 1 : 0;
}
int PieceValidEmpty(const int pce) {
return (pce >= EMPTY && pce <= bK) ? 1 : 0;
}
int PieceValid(const int pce) {
return (pce >= wP && pce <= bK) ? 1 : 0;
}
void DebugAnalysisTest(S_BOARD *pos, S_SEARCHINFO *info) {
FILE *file;
file = fopen("lct2.epd","r");
char lineIn [1024];
info->depth = MAXDEPTH;
info->timeset = TRUE;
int time = 1140000;
if(file == NULL) {
printf("File Not Found\n");
return;
} else {
while(fgets (lineIn , 1024 , file) != NULL) {
info->starttime = GetTimeMs();
info->stoptime = info->starttime + time;
ClearHashTable(pos->HashTable);
ParseFen(lineIn, pos);
printf("\n%s\n",lineIn);
printf("time:%d start:%d stop:%d depth:%d timeset:%d\n",
time,info->starttime,info->stoptime,info->depth,info->timeset);
SearchPosition(pos, info);
memset(&lineIn[0], 0, sizeof(lineIn));
}
}
}
void MirrorEvalTest(S_BOARD *pos) {
FILE *file;
file = fopen("mirror.epd","r");
char lineIn [1024];
int ev1 = 0; int ev2 = 0;
int positions = 0;
if(file == NULL) {
printf("File Not Found\n");
return;
} else {
while(fgets (lineIn , 1024 , file) != NULL) {
ParseFen(lineIn, pos);
positions++;
ev1 = EvalPosition(pos);
MirrorBoard(pos);
ev2 = EvalPosition(pos);
if(ev1 != ev2) {
printf("\n\n\n");
ParseFen(lineIn, pos);
PrintBoard(pos);
MirrorBoard(pos);
PrintBoard(pos);
printf("\n\nMirror Fail:\n%s\n",lineIn);
getchar();
return;
}
if( (positions % 1000) == 0) {
printf("position %d\n",positions);
}
memset(&lineIn[0], 0, sizeof(lineIn));
}
}
}