Sample code that shows a FEN string lookup for Miguel's egtb
Posted: 25 Jun 2010, 04:11
It's just a simple worked out example that I cobbled together from Miguel's public gtb code and Aaron's public gtb probe code:
http://cap.connx.com/chess-engines/new-approach/gtb.7z
http://cap.connx.com/chess-engines/new-approach/gtb.7z
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int load_gtb(char *gtb_pathlist, int cache_size_bytes, int compression_scheme);
extern void unload_gtb(void);
extern int probe_gtb_soft_dtm(char *fen, int *score);
extern int probe_gtb_soft(char *fen, int *score);
extern int probe_gtb_hard_dtm(char *fen, int *score);
extern int probe_gtb_hard(char *fen, int *score);
extern int probe_gtb_firm_dtm(char *fen, int *score);
extern int probe_gtb_firm(char *fen, int *score);
char gtb_path[FILENAME_MAX*100];
char *getsafe(char *buffer, int count)
{
char *result = buffer, *np;
if ((buffer == NULL) || (count < 1))
result = NULL;
else if (count == 1)
*result = '\0';
else if ((result = fgets(buffer, count, stdin)) != NULL)
if (np = strchr(buffer, '\n'))
*np = '\0';
return result;
}
char string[256];
int main(void)
{
char *gtb_pathlist = getenv("GTB_LOCATION");
int result;
int method;
if (gtb_pathlist == NULL)
{
puts("Enter the path to the gaviota tablebase files:");
gtb_pathlist = getsafe(gtb_path, sizeof gtb_path);
}
puts("What is the method of compression? (0,1,2,3,4,5,6,7,8 or 9):");
puts("If unsure, look at the extension on your gtb files...");
getsafe(string, sizeof string);
method = atoi(string);
result = load_gtb(gtb_pathlist, 1 << 22, method);
if (result)
{
int score;
int result;
puts("Enter a FEN or EPD chess position:");
getsafe(string, sizeof string);
puts("First probe results...");
result = probe_gtb_soft_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_soft(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_hard_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_hard(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_firm_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_firm(string, &score);
printf("result = %d, score = %d\n", result, score);
puts("Second probe results...");
result = probe_gtb_soft_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_soft(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_hard_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_hard(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_firm_dtm(string, &score);
printf("result = %d, score = %d\n", result, score);
result = probe_gtb_firm(string, &score);
printf("result = %d, score = %d\n", result, score);
}
else
{
puts("gtb base load failed.");
exit(EXIT_FAILURE);
}
return 0;
}
/*
Possible output:
Enter the path to the gaviota tablebase files:
c:\chess\winboard\gtb
What is the method of compression? (0,1,2,3,4,5,6,7,8 or 9):
If unsure, look at the extension on your gtb files...
4
Enter a FEN or EPD chess position:
8/8/8/8/4P1k1/8/5K2/8 w - - bm Ke3; id "J&S42.05";
First probe results...
result = 0, score = -858993460
result = 0, score = -858993460
result = 1, score = 32732
result = 1, score = 32000
result = 1, score = 32732
result = 1, score = 32000
Second probe results...
result = 1, score = 32732
result = 1, score = 31743
result = 1, score = 32732
result = 1, score = 32000
result = 1, score = 32732
result = 1, score = 32000
*/