📄 probe.cpp
字号:
// probe.cpp
// includes
#ifdef _WIN32
#include <windows.h>
#else
#include <string.h>
#include <dlfcn.h>
#endif
#include "board.h"
#include "config.h"
#include "probe.h"
// "constants"
enum
{
_EMPTY,
_WKING,
_WQUEEN,
_WROOK,
_WBISHOP,
_WKNIGHT,
_WPAWN,
_BKING,
_BQUEEN,
_BROOK,
_BBISHOP,
_BKNIGHT,
_BPAWN
};
enum
{
LOAD_NONE,
LOAD_4MEN,
SMART_LOAD,
LOAD_5MEN
};
static int egbb_load_type = LOAD_4MEN;
// macros
#ifdef _MSC_VER
#define EGBB_NAME "egbbdll.dll"
#else
#define EGBB_NAME "egbbso.so"
#define HMODULE void*
#define LoadLibrary(x) dlopen(x,RTLD_LAZY)
#define FreeLibrary(x) dlclose(x)
#define GetProcAddress dlsym
#endif
// variables
int egbb_is_loaded;
static int egbb_cache = 0;
static char *egbb_path = "";
static bool use_bitbases = true;
static PPROBE_EGBB probe_egbb;
// functions
void bitbase_init()
{
// UCI options
use_bitbases = option_get_bool("Bitbases");
if(use_bitbases)
{
egbb_cache = (option_get_int("Bitbase Cache") * 1024 * 1024);
egbb_path = (char *)option_get_string("Bitbase Path");
egbb_is_loaded = load_egbb_library(egbb_path, egbb_cache);
}
}
int load_egbb_library(char *main_path, uint32 egbb_cache_size)
{
static HMODULE hmod;
PLOAD_EGBB load_egbb;
char path[256];
strcpy(path, main_path);
strcat(path, EGBB_NAME);
if(hmod)
FreeLibrary(hmod);
if(hmod = LoadLibrary(path))
{
load_egbb = (PLOAD_EGBB)GetProcAddress(hmod, "load_egbb_5men");
probe_egbb = (PPROBE_EGBB)GetProcAddress(hmod, "probe_egbb_5men");
load_egbb(main_path, egbb_cache_size, egbb_load_type);
printf("\n");
return true;
}
else
{
return false;
}
}
int probe_bitbases(board_t *board, int &score)
{
int piece[5];
int square[5];
int from;
int count;
sq_t *ptr;
count = 0;
piece[0] = _EMPTY;
piece[1] = _EMPTY;
piece[2] = _EMPTY;
square[0] = _EMPTY;
square[1] = _EMPTY;
square[2] = _EMPTY;
for ( ptr = &board->piece[0][1]; (from = *ptr) != 0; ptr++ )
{
square[count] = square_to_64[from];
piece[count++] = -((PIECE_TO_12(board->square[from]) >> 1) - 6);
}
for ( ptr = &board->pawn[0][0]; (from = *ptr) != 0; ptr++ )
{
square[count] = square_to_64[from];
piece[count++] = _WPAWN;
}
for ( ptr = &board->piece[1][1]; (from = *ptr) != 0; ptr++ )
{
square[count] = square_to_64[from];
piece[count++] = -((PIECE_TO_12(board->square[from]) >> 1) - 12);
}
for ( ptr = &board->pawn[1][0]; (from = *ptr) != 0; ptr++ )
{
square[count] = square_to_64[from];
piece[count++] = _BPAWN;
}
score =
probe_egbb(board->turn, square_to_64[board->piece[0][0]], square_to_64[board->piece[1][0]], piece[0], square[0],
piece[1], square[1], piece[2], square[2]);
if(score != _NOTFOUND)
{
return true;
}
return false;
}
// end of probe.cpp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -