21 #define XX 127 // Invalid EP square. Can be any value greater than 63, 23 #define C_PIECES 3 // Maximum number of pieces of one color and type. 29 #define PROBE_MAX_PER_SIDE 4 31 #define PROBE_MAX_PER_SIDE 3 35 typedef unsigned int INDEX;
36 typedef unsigned int square;
38 #define SqFindKing(psq) (psq[C_PIECES * (x_pieceKing - 1)]) 39 #define SqFindOne(psq,pce) (psq[C_PIECES * (pce - 1)]) 40 #define SqFindFirst(psq,pce) (psq[C_PIECES * (pce - 1)]) 41 #define SqFindSecond(psq,pce) (psq[C_PIECES * (pce - 1) + 1]) 42 #define SqFindThird(psq,pce) (psq[C_PIECES * (pce - 1) + 2]) 45 #include "egtb/tbindex.cpp" 49 static const uint EGTB_CACHE_SIZE_MIN = 512 * 1024;
50 static const uint EGTB_CACHE_SIZE_DEFAULT = 512 * 1024;
51 static const uint EGTB_CACHE_SIZE_MAX = 128 * 1024 * 1024;
53 static void * EGTB_cache = NULL;
54 static uint EGTB_maxpieces = 0;
55 static uint EGTB_cachesize = EGTB_CACHE_SIZE_DEFAULT;
69 return EGTB_maxpieces;
75 return EGTB_cachesize;
81 EGTB_cachesize = cachesize;
82 if (cachesize < EGTB_CACHE_SIZE_MIN) {
83 EGTB_cachesize = EGTB_CACHE_SIZE_MIN;
85 if (cachesize > EGTB_CACHE_SIZE_MAX) {
86 EGTB_cachesize = EGTB_CACHE_SIZE_MAX;
99 EGTB_maxpieces = (
uint) IInitializeTb ((
char *) egtb_path);
101 if (EGTB_cache != NULL) { my_Tcl_Free( (
char *) EGTB_cache); }
102 EGTB_cache = (
byte *)my_Tcl_Alloc(
sizeof(
byte [EGTB_cachesize]));
104 if (EGTB_cache != NULL) {
delete[] (
byte *) EGTB_cache; }
105 EGTB_cache =
new byte [EGTB_cachesize];
107 FTbSetCacheSize (EGTB_cache, EGTB_cachesize);
108 return EGTB_maxpieces;
122 if (EGTB_maxpieces == 0) {
return 0; }
138 uint wc = 1 + counts[0] + counts[1] + counts[2] + counts[3] + counts[4];
139 uint bc = 1 + counts[5] + counts[6] + counts[7] + counts[8] + counts[9];
140 uint bothc = wc + bc;
141 if (bothc > EGTB_maxpieces || wc > PROBE_MAX_PER_SIDE ||
142 bc > PROBE_MAX_PER_SIDE) {
return false; }
145 if (bothc == 2) {
return true; }
149 if (counts[1] == 1 || counts[2] == 1 ||
150 counts[6] == 1 || counts[7] == 1) {
155 int iTb = IDescFindFromCounters (counts);
156 if (iTb == 0) {
return false; }
157 if (iTb < 0) { iTb = -iTb; }
161 if (FRegistered (iTb, 0)) {
return true; }
162 if (FRegistered (iTb, 1)) {
return true; }
184 int pieceCounts [10];
185 uint wSquares [C_PIECES * 6], bSquares [C_PIECES * 6];
197 if (npieces <= 2) { *score = 0;
return OK; }
222 iTb = IDescFindFromCounters (pieceCounts);
245 firstSq[
EMPTY] = NULL;
246 firstSq[
WK] = &(wSquares [C_PIECES * (x_pieceKing - 1) ]);
247 firstSq[
BK] = &(bSquares [C_PIECES * (x_pieceKing - 1) ]);
248 firstSq[
WQ] = &(wSquares [C_PIECES * (x_pieceQueen - 1) ]);
249 firstSq[
BQ] = &(bSquares [C_PIECES * (x_pieceQueen - 1) ]);
250 firstSq[
WR] = &(wSquares [C_PIECES * (x_pieceRook - 1) ]);
251 firstSq[
BR] = &(bSquares [C_PIECES * (x_pieceRook - 1) ]);
252 firstSq[
WB] = &(wSquares [C_PIECES * (x_pieceBishop - 1) ]);
253 firstSq[
BB] = &(bSquares [C_PIECES * (x_pieceBishop - 1) ]);
254 firstSq[
WN] = &(wSquares [C_PIECES * (x_pieceKnight - 1) ]);
255 firstSq[
BN] = &(bSquares [C_PIECES * (x_pieceKnight - 1) ]);
256 firstSq[
WP] = &(wSquares [C_PIECES * (x_piecePawn - 1) ]);
257 firstSq[
BP] = &(bSquares [C_PIECES * (x_piecePawn - 1) ]);
264 *(firstSq[pce]) = (
int)
sq;
279 bool possibleEP =
false;
303 int epTarget = (int) enPassant;
308 INDEX index = PfnIndCalc(iTb,color) (wSqs, bSqs, epTarget,
flip);
309 int tbscore = L_TbtProbeTable (iTb, color, index);
315 int distance = tbscore;
317 distance = 32767 - tbscore;
318 }
else if (tbscore < 0) {
319 distance = -32767 - tbscore;
uint scid_TB_Init(const char *)
const squareT NULL_SQUARE
bool scid_TB_Available(matSigT)
constexpr squareT square_Move(squareT sq, directionT dir)
squareT GetEPTarget() const
void scid_TB_SetCacheSize(uint)
byte PieceCount(pieceT p)
const directionT UP_RIGHT
const pieceT * GetBoard() const
uint matsig_getCount(matSigT m, pieceT p)
uint scid_TB_MaxPieces(void)
bool scid_TB_compiled(void)
uint scid_TB_CacheSize(void)
errorT scid_TB_Probe(Position *, int *)
const directionT DOWN_RIGHT
const errorT ERROR_NotFound
uint GetCount(colorT c) const
const directionT DOWN_LEFT