Skip to content

Commit d6ecfaa

Browse files
committed
Separate and simplify antichess tablebase probing code official-stockfish#511
No functional change
1 parent ec3d49a commit d6ecfaa

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/syzygy/tbprobe.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,17 @@ struct TBEntry {
358358
void* baseAddress;
359359
uint8_t* map;
360360
uint64_t mapping;
361+
Variant variant;
361362
Key key;
362363
Key key2;
363364
int pieceCount;
364365
bool hasPawns;
365-
int numUniquePieces;
366-
int minLikeMan;
366+
uint8_t numUniquePieces; // count of piece types
367+
#ifdef ANTI
368+
uint8_t minModePieces; // minimum mode of pieces per piece type
369+
#endif
367370
uint8_t pawnCount[2]; // [Lead color / other color]
368371
PairsData items[Sides][4]; // [wtm / btm][FILE_A..FILE_D or 0]
369-
Variant variant;
370372

371373
PairsData* get(int stm, int f) {
372374
return &items[stm % Sides][hasPawns ? f : 0];
@@ -390,15 +392,14 @@ TBEntry<WDL>::TBEntry(const std::string& code, Variant v) : TBEntry() {
390392
hasPawns = pos.pieces(PAWN);
391393

392394
for (Color c = WHITE; c <= BLACK; ++c)
393-
for (PieceType pt = PAWN; pt < KING; ++pt)
394-
if (popcount(pos.pieces(c, pt)) == 1)
395-
numUniquePieces++;
396-
397-
for (Color c = WHITE; c <= BLACK; ++c)
398-
for (PieceType pt = PAWN; pt <= KING; ++pt) {
395+
for (PieceType pt = PAWN; pt < KING; ++pt) {
399396
int count = popcount(pos.pieces(c, pt));
400-
if (2 <= count && (count < minLikeMan || !minLikeMan))
401-
minLikeMan = count;
397+
if (count == 1)
398+
numUniquePieces++;
399+
#ifdef ANTI
400+
else if (variant == ANTI_VARIANT && (count < minModePieces || !minModePieces))
401+
minModePieces = count;
402+
#endif
402403
}
403404

404405
if (hasPawns) {
@@ -424,7 +425,9 @@ TBEntry<DTZ>::TBEntry(const TBEntry<WDL>& wdl) : TBEntry() {
424425
pieceCount = wdl.pieceCount;
425426
hasPawns = wdl.hasPawns;
426427
numUniquePieces = wdl.numUniquePieces;
427-
minLikeMan = wdl.minLikeMan;
428+
#ifdef ANTI
429+
minModePieces = wdl.minModePieces;
430+
#endif
428431

429432
if (hasPawns) {
430433
pawnCount[0] = wdl.pawnCount[0];
@@ -1182,7 +1185,8 @@ T do_probe_table(const Position& pos, TBEntry<Type>* entry, WDLScore wdl, ProbeS
11821185
// the kings.
11831186
idx = MapKK[MapA1D1D4[squares[0]]][squares[1]];
11841187

1185-
} else if (entry->minLikeMan == 2) {
1188+
#ifdef ANTI
1189+
} else if (entry->variant == ANTI_VARIANT && entry->minModePieces == 2) {
11861190
if (Triangle[squares[0]] > Triangle[squares[1]])
11871191
std::swap(squares[0], squares[1]);
11881192

@@ -1205,6 +1209,7 @@ T do_probe_table(const Position& pos, TBEntry<Type>* entry, WDLScore wdl, ProbeS
12051209
}
12061210

12071211
idx = MapPP[Triangle[squares[0]]][squares[1]];
1212+
#endif
12081213
} else {
12091214
for (int i = 1; i < d->groupLen[0]; ++i)
12101215
if (Triangle[squares[0]] > Triangle[squares[i]])
@@ -1317,10 +1322,10 @@ void set_groups(TBEntry<Type>& e, PairsData* d, int order[], File f) {
13171322
else if (e.numUniquePieces == 2)
13181323
// Standard or Atomic/Giveaway
13191324
idx *= (e.variant == CHESS_VARIANT) ? 462 : 518;
1320-
else if (e.minLikeMan == 2)
1321-
idx *= 278;
1322-
else
1323-
idx *= MultFactor[e.minLikeMan - 1];
1325+
#ifdef ANTI
1326+
else if (e.variant == ANTI_VARIANT)
1327+
idx *= (e.minModePieces == 2) ? 278 : MultFactor[e.minModePieces - 1];
1328+
#endif
13241329
}
13251330
else if (k == order[1]) // Remaining pawns
13261331
{

0 commit comments

Comments
 (0)