Most engines have a unique position structure, and a "position_t" is often all that is necessary to evaluate a position. It takes several hours to create the binary file, but it only needs to be done once. Instead of:
if (fgets(line, 256, fin) == NULL)
that programs like Ethereal use with an epd file, to tune now use with the binary file:
while (fread(pos, sizeof(position_t), 1 , f)) {
The binary file could be re-opened into another array for tuning, but disk read is so fast that it is not necessary. Besides, if threading is used then the disk binary file can be used to save memory. The "quiet-labeled.epd" was an old common file used for tuning. It creates a binary of 113,282 KB for the Schooner position_t structure. A link from someone would be appreciated if there are newer and better tuning epd's.
The game result is not normally saved in a position structure, so an unused variable is used to store the game result. Here is a sample 'C' code of the technique to convert an epd file and build the binary file:
Code: Select all
void CreateBinaryFile() {
FILE * f;
FILE * f2;
int n = 0;
double result;
position_t *pos = rsd->pos;
strcpy(Tfilename,"quiet-labeled.epd");
strcpy(Wfilename,"tune_array.bin");
f = fopen(Tfilename,"r+");
if (f == NULL) {
printf("file not opened\n");
return;
}
f2 = fopen(Wfilename,"wb+");
if (f2 == NULL) {
printf("file f2 not opened\n");
return;
}
n = 0;
while (fgets(fen,128,f)) {
n+=1;
// the parsing method here was taken from Crafty
nargs = ReadParse(fen," ;=");
//this loads the fen and builds the position structure in my program
Command(rsd);
if (!strcmp(args[5], "\"0-1\"")) {
result = 0.0;
} else if (!strcmp(args[5], "\"1-0\"")) {
result = 1.0;
} else if (!strcmp(args[5], "\"1/2-1/2\"")) {
result = 0.5;
} else {
printf("%d bad result\n",n);
printf("args[5] %s\n",args[5]);
printf("%s\n", fen);
break;
}
// save the game result in an unused variable
pos->static_score = (uint16_t) (result * 2);
// and save the converted fen to disk with a sequential write
fwrite(pos, sizeof(position_t), 1 , f2);
}
fclose (f); fclose(f2);
printf("%d writes\n",n);
}