mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Improve some comments
This commit is contained in:
parent
23a548feaa
commit
c920c6c807
1 changed files with 18 additions and 20 deletions
|
@ -63,23 +63,23 @@ inline WDLScore operator+(WDLScore d1, WDLScore d2) { return WDLScore(int(d1) +
|
||||||
inline Square operator^=(Square& s, int i) { return s = Square(int(s) ^ i); }
|
inline Square operator^=(Square& s, int i) { return s = Square(int(s) ^ i); }
|
||||||
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
|
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
|
||||||
|
|
||||||
// DTZ tables don't store valid scoers for moves that reset the rule50 counter
|
// DTZ tables don't store valid scores for moves that reset the rule50 counter
|
||||||
// like captures and pawn moves. Luckily we can easily recover the correct dtz
|
// like captures and pawn moves but we can easily recover the correct dtz if we
|
||||||
// if we know the position's WDL score.
|
// know the position's WDL score.
|
||||||
int zeroing_move_dtz(WDLScore wdl)
|
int zeroing_move_dtz(WDLScore wdl) {
|
||||||
{
|
|
||||||
return wdl == WDLWin ? 1 :
|
return wdl == WDLWin ? 1 :
|
||||||
wdl == WDLCursedWin ? 101 :
|
wdl == WDLCursedWin ? 101 :
|
||||||
wdl == WDLCursedLoss ? -101 :
|
wdl == WDLCursedLoss ? -101 :
|
||||||
wdl == WDLLoss ? -1 : 0;
|
wdl == WDLLoss ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the sign of a number (-1, 0, 1)
|
// Return the sign of a number (-1, 0, 1)
|
||||||
template <typename T> int sign_of(T val) {
|
template <typename T> int sign_of(T val) {
|
||||||
return (T(0) < val) - (val < T(0));
|
return (T(0) < val) - (val < T(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Numbers in Little Endian format used by sparseIndex[] to point into blockLength[]
|
// Numbers in little endian used by sparseIndex[] to point into blockLength[]
|
||||||
struct SparseEntry {
|
struct SparseEntry {
|
||||||
char block[4]; // Number of block
|
char block[4]; // Number of block
|
||||||
char offset[2]; // Offset within the block
|
char offset[2]; // Offset within the block
|
||||||
|
@ -114,14 +114,14 @@ struct PairsData {
|
||||||
int blocksNum; // Number of blocks in the TB file
|
int blocksNum; // Number of blocks in the TB file
|
||||||
int maxSymLen; // Maximum length in bits of the Huffman symbols
|
int maxSymLen; // Maximum length in bits of the Huffman symbols
|
||||||
int minSymLen; // Minimum length in bits of the Huffman symbols
|
int minSymLen; // Minimum length in bits of the Huffman symbols
|
||||||
Sym* lowestSym; // lowestSym[l] is the value of the lowest symbol of length l
|
Sym* lowestSym; // lowestSym[l] is the symbol of length l with the lowest value
|
||||||
LR* btree; // btree[sym] stores the left and right symbols that expand sym
|
LR* btree; // btree[sym] stores the left and right symbols that expand sym
|
||||||
uint16_t* blockLength; // Number of stored positions (minus one) for each block: 1..65536
|
uint16_t* blockLength; // Number of stored positions (minus one) for each block: 1..65536
|
||||||
int blockLengthSize; // Size of blockLength[] table: padded so it's bigger than blocksNum
|
int blockLengthSize; // Size of blockLength[] table: padded so it's bigger than blocksNum
|
||||||
SparseEntry* sparseIndex; // Partial indices into blockLength[]
|
SparseEntry* sparseIndex; // Partial indices into blockLength[]
|
||||||
size_t sparseIndexSize; // Size of SparseIndex[] table
|
size_t sparseIndexSize; // Size of SparseIndex[] table
|
||||||
uint8_t* data; // Start of Huffman compressed data
|
uint8_t* data; // Start of Huffman compressed data
|
||||||
std::vector<uint64_t> base64; // Smallest symbol of length l padded to 64 bits is at base64[l - min_sym_len]
|
std::vector<uint64_t> base64; // base64[l - min_sym_len] is the 64bit-padded lowest symbol of length l
|
||||||
std::vector<uint8_t> symlen; // Number of values (-1) represented by a given Huffman symbol: 1..256
|
std::vector<uint8_t> symlen; // Number of values (-1) represented by a given Huffman symbol: 1..256
|
||||||
Piece pieces[TBPIECES]; // Sequence of the pieces: order is critical to ensure the best compression
|
Piece pieces[TBPIECES]; // Sequence of the pieces: order is critical to ensure the best compression
|
||||||
uint64_t groupSize[TBPIECES]; // Size needed by a given subset of pieces: KRKN -> (KRK) + (N)
|
uint64_t groupSize[TBPIECES]; // Size needed by a given subset of pieces: KRKN -> (KRK) + (N)
|
||||||
|
@ -150,13 +150,13 @@ struct WDLEntry : public Atomic {
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
PairsData* precomp;
|
PairsData* precomp;
|
||||||
} piece[2]; // One for each side to move
|
} piece[2]; // [Side to move]
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t pawnCount[2];
|
uint8_t pawnCount[2]; // [Lead color / weak color]
|
||||||
struct {
|
struct {
|
||||||
PairsData* precomp;
|
PairsData* precomp;
|
||||||
} file[2][4];
|
} file[2][4]; // [Side to move][FILE_A..FILE_D]
|
||||||
} pawn;
|
} pawn;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -212,8 +212,6 @@ int off_A1H8(Square sq) { return int(rank_of(sq)) - file_of(sq); }
|
||||||
const uint8_t WDL_MAGIC[] = { 0x71, 0xE8, 0x23, 0x5D };
|
const uint8_t WDL_MAGIC[] = { 0x71, 0xE8, 0x23, 0x5D };
|
||||||
const uint8_t DTZ_MAGIC[] = { 0xD7, 0x66, 0x0C, 0xA5 };
|
const uint8_t DTZ_MAGIC[] = { 0xD7, 0x66, 0x0C, 0xA5 };
|
||||||
|
|
||||||
const int wdl_to_dtz[] = { -1, -101, 0, 101, 1 };
|
|
||||||
|
|
||||||
const Value WDL_to_value[] = {
|
const Value WDL_to_value[] = {
|
||||||
-VALUE_MATE + MAX_PLY + 1,
|
-VALUE_MATE + MAX_PLY + 1,
|
||||||
VALUE_DRAW - 2,
|
VALUE_DRAW - 2,
|
||||||
|
@ -300,9 +298,9 @@ class TBFile : public std::ifstream {
|
||||||
std::string fname;
|
std::string fname;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Open the file with the given name found among the TBPaths directories
|
// Look for and open the file among the TBPaths directories where the .rtbw
|
||||||
// where the .rtbw and .rtbz files can be found. Multiple directories are
|
// and .rtbz files can be found. Multiple directories are separated by ";"
|
||||||
// separated by ";" on Windows and by ":" on Unix-based operating systems.
|
// on Windows and by ":" on Unix-based operating systems.
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// C:\tb\wdl345;C:\tb\wdl6;D:\tb\dtz345;D:\tb\dtz6
|
// C:\tb\wdl345;C:\tb\wdl6;D:\tb\dtz345;D:\tb\dtz6
|
||||||
|
@ -324,8 +322,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memory map the file and check it. File should be already open and
|
// Memory map the file and check it. File should be already open and will be
|
||||||
// will be closed after mapping.
|
// closed after mapping.
|
||||||
uint8_t* map(void** baseAddress, uint64_t* mapping, const uint8_t TB_MAGIC[]) {
|
uint8_t* map(void** baseAddress, uint64_t* mapping, const uint8_t TB_MAGIC[]) {
|
||||||
|
|
||||||
if (!is_open()) {
|
if (!is_open()) {
|
||||||
|
@ -1588,7 +1586,7 @@ bool Tablebases::root_probe(Position& pos, Search::RootMoves& rootMoves, Value&
|
||||||
--v;
|
--v;
|
||||||
} else {
|
} else {
|
||||||
v = -probe_wdl(pos, &result);
|
v = -probe_wdl(pos, &result);
|
||||||
v = wdl_to_dtz[v + 2];
|
v = zeroing_move_dtz(WDLScore(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue