mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Mark all compile-time constants as constexpr.
To more clearly distinguish them from "const" local variables, this patch defines compile-time local constants as constexpr. This is consistent with the definition of PvNode as constexpr in search() and qsearch(). It also makes the code more robust, since the compiler will now check that those constants are indeed compile-time constants. We can go even one step further and define all the evaluation and search compile-time constants as constexpr. In generate_castling() I replaced "K" with "step", since K was incorrectly capitalised (in the Chess960 case). In timeman.cpp I had to make the non-local constants MaxRatio and StealRatio constepxr, since otherwise gcc would complain when calculating TMaxRatio and TStealRatio. (Strangely, I did not have to make Is64Bit constexpr even though it is used in ucioption.cpp in the calculation of constexpr MaxHashMB.) I have renamed PieceCount to pieceCount in material.h, since the values of the array are not compile-time constants. Some compile-time constants in tbprobe.cpp were overlooked. Sides and MaxFile are not compile-time constants, so were renamed to sides and maxFile. Non-functional change.
This commit is contained in:
parent
350dff4464
commit
759b3c79cf
17 changed files with 164 additions and 164 deletions
|
@ -29,7 +29,7 @@
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
// There are 24 possible pawn squares: the first 4 files and ranks from 2 to 7
|
||||||
const unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
|
||||||
|
|
||||||
// Each uint32_t stores results of 32 positions, one per bit
|
// Each uint32_t stores results of 32 positions, one per bit
|
||||||
uint32_t KPKBitbase[MAX_INDEX / 32];
|
uint32_t KPKBitbase[MAX_INDEX / 32];
|
||||||
|
@ -152,9 +152,9 @@ namespace {
|
||||||
// as WIN, the position is classified as WIN, otherwise the current position is
|
// as WIN, the position is classified as WIN, otherwise the current position is
|
||||||
// classified as UNKNOWN.
|
// classified as UNKNOWN.
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Result Good = (Us == WHITE ? WIN : DRAW);
|
constexpr Result Good = (Us == WHITE ? WIN : DRAW);
|
||||||
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
constexpr Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||||
|
|
||||||
Result r = INVALID;
|
Result r = INVALID;
|
||||||
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||||
|
|
|
@ -39,26 +39,26 @@ const std::string pretty(Bitboard b);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bitboard AllSquares = ~Bitboard(0);
|
constexpr Bitboard AllSquares = ~Bitboard(0);
|
||||||
const Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
constexpr Bitboard DarkSquares = 0xAA55AA55AA55AA55ULL;
|
||||||
|
|
||||||
const Bitboard FileABB = 0x0101010101010101ULL;
|
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
const Bitboard FileBBB = FileABB << 1;
|
constexpr Bitboard FileBBB = FileABB << 1;
|
||||||
const Bitboard FileCBB = FileABB << 2;
|
constexpr Bitboard FileCBB = FileABB << 2;
|
||||||
const Bitboard FileDBB = FileABB << 3;
|
constexpr Bitboard FileDBB = FileABB << 3;
|
||||||
const Bitboard FileEBB = FileABB << 4;
|
constexpr Bitboard FileEBB = FileABB << 4;
|
||||||
const Bitboard FileFBB = FileABB << 5;
|
constexpr Bitboard FileFBB = FileABB << 5;
|
||||||
const Bitboard FileGBB = FileABB << 6;
|
constexpr Bitboard FileGBB = FileABB << 6;
|
||||||
const Bitboard FileHBB = FileABB << 7;
|
constexpr Bitboard FileHBB = FileABB << 7;
|
||||||
|
|
||||||
const Bitboard Rank1BB = 0xFF;
|
constexpr Bitboard Rank1BB = 0xFF;
|
||||||
const Bitboard Rank2BB = Rank1BB << (8 * 1);
|
constexpr Bitboard Rank2BB = Rank1BB << (8 * 1);
|
||||||
const Bitboard Rank3BB = Rank1BB << (8 * 2);
|
constexpr Bitboard Rank3BB = Rank1BB << (8 * 2);
|
||||||
const Bitboard Rank4BB = Rank1BB << (8 * 3);
|
constexpr Bitboard Rank4BB = Rank1BB << (8 * 3);
|
||||||
const Bitboard Rank5BB = Rank1BB << (8 * 4);
|
constexpr Bitboard Rank5BB = Rank1BB << (8 * 4);
|
||||||
const Bitboard Rank6BB = Rank1BB << (8 * 5);
|
constexpr Bitboard Rank6BB = Rank1BB << (8 * 5);
|
||||||
const Bitboard Rank7BB = Rank1BB << (8 * 6);
|
constexpr Bitboard Rank7BB = Rank1BB << (8 * 6);
|
||||||
const Bitboard Rank8BB = Rank1BB << (8 * 7);
|
constexpr Bitboard Rank8BB = Rank1BB << (8 * 7);
|
||||||
|
|
||||||
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
extern int SquareDistance[SQUARE_NB][SQUARE_NB];
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace {
|
||||||
|
|
||||||
// Table used to drive the king towards the edge of the board
|
// Table used to drive the king towards the edge of the board
|
||||||
// in KX vs K and KQ vs KR endgames.
|
// in KX vs K and KQ vs KR endgames.
|
||||||
const int PushToEdges[SQUARE_NB] = {
|
constexpr int PushToEdges[SQUARE_NB] = {
|
||||||
100, 90, 80, 70, 70, 80, 90, 100,
|
100, 90, 80, 70, 70, 80, 90, 100,
|
||||||
90, 70, 60, 50, 50, 60, 70, 90,
|
90, 70, 60, 50, 50, 60, 70, 90,
|
||||||
80, 60, 40, 30, 30, 40, 60, 80,
|
80, 60, 40, 30, 30, 40, 60, 80,
|
||||||
|
@ -44,7 +44,7 @@ namespace {
|
||||||
|
|
||||||
// Table used to drive the king towards a corner square of the
|
// Table used to drive the king towards a corner square of the
|
||||||
// right color in KBN vs K endgames.
|
// right color in KBN vs K endgames.
|
||||||
const int PushToCorners[SQUARE_NB] = {
|
constexpr int PushToCorners[SQUARE_NB] = {
|
||||||
200, 190, 180, 170, 160, 150, 140, 130,
|
200, 190, 180, 170, 160, 150, 140, 130,
|
||||||
190, 180, 170, 160, 150, 140, 130, 140,
|
190, 180, 170, 160, 150, 140, 130, 140,
|
||||||
180, 170, 155, 140, 140, 125, 140, 150,
|
180, 170, 155, 140, 140, 125, 140, 150,
|
||||||
|
@ -56,11 +56,11 @@ namespace {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tables used to drive a piece towards or away from another piece
|
// Tables used to drive a piece towards or away from another piece
|
||||||
const int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
constexpr int PushClose[8] = { 0, 0, 100, 80, 60, 40, 20, 10 };
|
||||||
const int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
constexpr int PushAway [8] = { 0, 5, 20, 40, 60, 80, 90, 100 };
|
||||||
|
|
||||||
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
// Pawn Rank based scaling factors used in KRPPKRP endgame
|
||||||
const int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
constexpr int KRPPKRPScaleFactors[RANK_NB] = { 0, 9, 10, 14, 21, 44, 0, 0 };
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
bool verify_material(const Position& pos, Color c, Value npm, int pawnsCnt) {
|
||||||
|
|
110
src/evaluate.cpp
110
src/evaluate.cpp
|
@ -74,35 +74,35 @@ using namespace Trace;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
|
constexpr Bitboard QueenSide = FileABB | FileBBB | FileCBB | FileDBB;
|
||||||
const Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
|
constexpr Bitboard CenterFiles = FileCBB | FileDBB | FileEBB | FileFBB;
|
||||||
const Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
|
constexpr Bitboard KingSide = FileEBB | FileFBB | FileGBB | FileHBB;
|
||||||
const Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
|
constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
|
||||||
|
|
||||||
const Bitboard KingFlank[FILE_NB] = {
|
constexpr Bitboard KingFlank[FILE_NB] = {
|
||||||
QueenSide, QueenSide, QueenSide,
|
QueenSide, QueenSide, QueenSide,
|
||||||
CenterFiles, CenterFiles,
|
CenterFiles, CenterFiles,
|
||||||
KingSide, KingSide, KingSide
|
KingSide, KingSide, KingSide
|
||||||
};
|
};
|
||||||
|
|
||||||
// Threshold for lazy and space evaluation
|
// Threshold for lazy and space evaluation
|
||||||
const Value LazyThreshold = Value(1500);
|
constexpr Value LazyThreshold = Value(1500);
|
||||||
const Value SpaceThreshold = Value(12222);
|
constexpr Value SpaceThreshold = Value(12222);
|
||||||
|
|
||||||
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
||||||
const int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 78, 56, 45, 11 };
|
constexpr int KingAttackWeights[PIECE_TYPE_NB] = { 0, 0, 78, 56, 45, 11 };
|
||||||
|
|
||||||
// Penalties for enemy's safe checks
|
// Penalties for enemy's safe checks
|
||||||
const int QueenSafeCheck = 780;
|
constexpr int QueenSafeCheck = 780;
|
||||||
const int RookSafeCheck = 880;
|
constexpr int RookSafeCheck = 880;
|
||||||
const int BishopSafeCheck = 435;
|
constexpr int BishopSafeCheck = 435;
|
||||||
const int KnightSafeCheck = 790;
|
constexpr int KnightSafeCheck = 790;
|
||||||
|
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game,
|
// MobilityBonus[PieceType-2][attacked] contains bonuses for middle and end game,
|
||||||
// indexed by piece type and number of attacked squares in the mobility area.
|
// indexed by piece type and number of attacked squares in the mobility area.
|
||||||
const Score MobilityBonus[][32] = {
|
constexpr Score MobilityBonus[][32] = {
|
||||||
{ S(-75,-76), S(-57,-54), S( -9,-28), S( -2,-10), S( 6, 5), S( 14, 12), // Knights
|
{ S(-75,-76), S(-57,-54), S( -9,-28), S( -2,-10), S( 6, 5), S( 14, 12), // Knights
|
||||||
S( 22, 26), S( 29, 29), S( 36, 29) },
|
S( 22, 26), S( 29, 29), S( 36, 29) },
|
||||||
{ S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishops
|
{ S(-48,-59), S(-20,-23), S( 16, -3), S( 26, 13), S( 38, 24), S( 51, 42), // Bishops
|
||||||
|
@ -121,66 +121,66 @@ namespace {
|
||||||
// Outpost[knight/bishop][supported by pawn] contains bonuses for minor
|
// Outpost[knight/bishop][supported by pawn] contains bonuses for minor
|
||||||
// pieces if they occupy or can reach an outpost square, bigger if that
|
// pieces if they occupy or can reach an outpost square, bigger if that
|
||||||
// square is supported by a pawn.
|
// square is supported by a pawn.
|
||||||
const Score Outpost[][2] = {
|
constexpr Score Outpost[][2] = {
|
||||||
{ S(22, 6), S(36,12) }, // Knight
|
{ S(22, 6), S(36,12) }, // Knight
|
||||||
{ S( 9, 2), S(15, 5) } // Bishop
|
{ S( 9, 2), S(15, 5) } // Bishop
|
||||||
};
|
};
|
||||||
|
|
||||||
// RookOnFile[semiopen/open] contains bonuses for each rook when there is
|
// RookOnFile[semiopen/open] contains bonuses for each rook when there is
|
||||||
// no (friendly) pawn on the rook file.
|
// no (friendly) pawn on the rook file.
|
||||||
const Score RookOnFile[] = { S(20, 7), S(45, 20) };
|
constexpr Score RookOnFile[] = { S(20, 7), S(45, 20) };
|
||||||
|
|
||||||
// ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
|
// ThreatByMinor/ByRook[attacked PieceType] contains bonuses according to
|
||||||
// which piece type attacks which one. Attacks on lesser pieces which are
|
// which piece type attacks which one. Attacks on lesser pieces which are
|
||||||
// pawn-defended are not considered.
|
// pawn-defended are not considered.
|
||||||
const Score ThreatByMinor[PIECE_TYPE_NB] = {
|
constexpr Score ThreatByMinor[PIECE_TYPE_NB] = {
|
||||||
S(0, 0), S(0, 31), S(39, 42), S(57, 44), S(68, 112), S(47, 120)
|
S(0, 0), S(0, 31), S(39, 42), S(57, 44), S(68, 112), S(47, 120)
|
||||||
};
|
};
|
||||||
|
|
||||||
const Score ThreatByRook[PIECE_TYPE_NB] = {
|
constexpr Score ThreatByRook[PIECE_TYPE_NB] = {
|
||||||
S(0, 0), S(0, 24), S(38, 71), S(38, 61), S(0, 38), S(36, 38)
|
S(0, 0), S(0, 24), S(38, 71), S(38, 61), S(0, 38), S(36, 38)
|
||||||
};
|
};
|
||||||
|
|
||||||
// ThreatByKing[on one/on many] contains bonuses for king attacks on
|
// ThreatByKing[on one/on many] contains bonuses for king attacks on
|
||||||
// pawns or pieces which are not pawn-defended.
|
// pawns or pieces which are not pawn-defended.
|
||||||
const Score ThreatByKing[] = { S(3, 65), S(9, 145) };
|
constexpr Score ThreatByKing[] = { S(3, 65), S(9, 145) };
|
||||||
|
|
||||||
// PassedRank[Rank] contains a bonus according to the rank of a passed pawn
|
// PassedRank[Rank] contains a bonus according to the rank of a passed pawn
|
||||||
const Score PassedRank[RANK_NB] = {
|
constexpr Score PassedRank[RANK_NB] = {
|
||||||
S(0, 0), S(5, 7), S(5, 13), S(32, 42), S(70, 70), S(172, 170), S(217, 269)
|
S(0, 0), S(5, 7), S(5, 13), S(32, 42), S(70, 70), S(172, 170), S(217, 269)
|
||||||
};
|
};
|
||||||
|
|
||||||
// PassedFile[File] contains a bonus according to the file of a passed pawn
|
// PassedFile[File] contains a bonus according to the file of a passed pawn
|
||||||
const Score PassedFile[FILE_NB] = {
|
constexpr Score PassedFile[FILE_NB] = {
|
||||||
S( 9, 10), S(2, 10), S(1, -8), S(-20,-12),
|
S( 9, 10), S(2, 10), S(1, -8), S(-20,-12),
|
||||||
S(-20,-12), S(1, -8), S(2, 10), S( 9, 10)
|
S(-20,-12), S(1, -8), S(2, 10), S( 9, 10)
|
||||||
};
|
};
|
||||||
|
|
||||||
// PassedDanger[Rank] contains a term to weight the passed score
|
// PassedDanger[Rank] contains a term to weight the passed score
|
||||||
const int PassedDanger[RANK_NB] = { 0, 0, 0, 2, 7, 12, 19 };
|
constexpr int PassedDanger[RANK_NB] = { 0, 0, 0, 2, 7, 12, 19 };
|
||||||
|
|
||||||
// KingProtector[PieceType-2] contains a penalty according to distance from king
|
// KingProtector[PieceType-2] contains a penalty according to distance from king
|
||||||
const Score KingProtector[] = { S(3, 5), S(4, 3), S(3, 0), S(1, -1) };
|
constexpr Score KingProtector[] = { S(3, 5), S(4, 3), S(3, 0), S(1, -1) };
|
||||||
|
|
||||||
// Assorted bonuses and penalties
|
// Assorted bonuses and penalties
|
||||||
const Score BishopPawns = S( 8, 12);
|
constexpr Score BishopPawns = S( 8, 12);
|
||||||
const Score CloseEnemies = S( 7, 0);
|
constexpr Score CloseEnemies = S( 7, 0);
|
||||||
const Score Connectivity = S( 3, 1);
|
constexpr Score Connectivity = S( 3, 1);
|
||||||
const Score CorneredBishop = S( 50, 50);
|
constexpr Score CorneredBishop = S( 50, 50);
|
||||||
const Score Hanging = S( 52, 30);
|
constexpr Score Hanging = S( 52, 30);
|
||||||
const Score HinderPassedPawn = S( 8, 1);
|
constexpr Score HinderPassedPawn = S( 8, 1);
|
||||||
const Score KnightOnQueen = S( 21, 11);
|
constexpr Score KnightOnQueen = S( 21, 11);
|
||||||
const Score LongDiagonalBishop = S( 22, 0);
|
constexpr Score LongDiagonalBishop = S( 22, 0);
|
||||||
const Score MinorBehindPawn = S( 16, 0);
|
constexpr Score MinorBehindPawn = S( 16, 0);
|
||||||
const Score PawnlessFlank = S( 20, 80);
|
constexpr Score PawnlessFlank = S( 20, 80);
|
||||||
const Score RookOnPawn = S( 8, 24);
|
constexpr Score RookOnPawn = S( 8, 24);
|
||||||
const Score SliderOnQueen = S( 42, 21);
|
constexpr Score SliderOnQueen = S( 42, 21);
|
||||||
const Score ThreatByPawnPush = S( 47, 26);
|
constexpr Score ThreatByPawnPush = S( 47, 26);
|
||||||
const Score ThreatByRank = S( 16, 3);
|
constexpr Score ThreatByRank = S( 16, 3);
|
||||||
const Score ThreatBySafePawn = S(175,168);
|
constexpr Score ThreatBySafePawn = S(175,168);
|
||||||
const Score TrappedRook = S( 92, 0);
|
constexpr Score TrappedRook = S( 92, 0);
|
||||||
const Score WeakQueen = S( 50, 10);
|
constexpr Score WeakQueen = S( 50, 10);
|
||||||
const Score WeakUnopposedPawn = S( 5, 25);
|
constexpr Score WeakUnopposedPawn = S( 5, 25);
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
|
|
||||||
|
@ -250,10 +250,10 @@ namespace {
|
||||||
template<Tracing T> template<Color Us>
|
template<Tracing T> template<Color Us>
|
||||||
void Evaluation<T>::initialize() {
|
void Evaluation<T>::initialize() {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
|
||||||
const Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
|
constexpr Bitboard LowRanks = (Us == WHITE ? Rank2BB | Rank3BB: Rank7BB | Rank6BB);
|
||||||
|
|
||||||
// Find our pawns that are blocked or on the first two ranks
|
// Find our pawns that are blocked or on the first two ranks
|
||||||
Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
|
Bitboard b = pos.pieces(Us, PAWN) & (shift<Down>(pos.pieces()) | LowRanks);
|
||||||
|
@ -287,8 +287,8 @@ namespace {
|
||||||
template<Tracing T> template<Color Us, PieceType Pt>
|
template<Tracing T> template<Color Us, PieceType Pt>
|
||||||
Score Evaluation<T>::pieces() {
|
Score Evaluation<T>::pieces() {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
|
constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
|
||||||
: Rank5BB | Rank4BB | Rank3BB);
|
: Rank5BB | Rank4BB | Rank3BB);
|
||||||
const Square* pl = pos.squares<Pt>(Us);
|
const Square* pl = pos.squares<Pt>(Us);
|
||||||
|
|
||||||
|
@ -404,8 +404,8 @@ namespace {
|
||||||
template<Tracing T> template<Color Us>
|
template<Tracing T> template<Color Us>
|
||||||
Score Evaluation<T>::king() const {
|
Score Evaluation<T>::king() const {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
constexpr Bitboard Camp = (Us == WHITE ? AllSquares ^ Rank6BB ^ Rank7BB ^ Rank8BB
|
||||||
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
: AllSquares ^ Rank1BB ^ Rank2BB ^ Rank3BB);
|
||||||
|
|
||||||
const Square ksq = pos.square<KING>(Us);
|
const Square ksq = pos.square<KING>(Us);
|
||||||
|
@ -506,9 +506,9 @@ namespace {
|
||||||
template<Tracing T> template<Color Us>
|
template<Tracing T> template<Color Us>
|
||||||
Score Evaluation<T>::threats() const {
|
Score Evaluation<T>::threats() const {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
|
|
||||||
Bitboard b, weak, defended, nonPawnEnemies, stronglyProtected, safeThreats;
|
Bitboard b, weak, defended, nonPawnEnemies, stronglyProtected, safeThreats;
|
||||||
Score score = SCORE_ZERO;
|
Score score = SCORE_ZERO;
|
||||||
|
@ -617,8 +617,8 @@ namespace {
|
||||||
template<Tracing T> template<Color Us>
|
template<Tracing T> template<Color Us>
|
||||||
Score Evaluation<T>::passed() const {
|
Score Evaluation<T>::passed() const {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
|
|
||||||
auto king_proximity = [&](Color c, Square s) {
|
auto king_proximity = [&](Color c, Square s) {
|
||||||
return std::min(distance(pos.square<KING>(c), s), 5);
|
return std::min(distance(pos.square<KING>(c), s), 5);
|
||||||
|
@ -715,8 +715,8 @@ namespace {
|
||||||
template<Tracing T> template<Color Us>
|
template<Tracing T> template<Color Us>
|
||||||
Score Evaluation<T>::space() const {
|
Score Evaluation<T>::space() const {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard SpaceMask =
|
constexpr Bitboard SpaceMask =
|
||||||
Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB)
|
Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB)
|
||||||
: CenterFiles & (Rank7BB | Rank6BB | Rank5BB);
|
: CenterFiles & (Rank7BB | Rank6BB | Rank5BB);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Position;
|
||||||
|
|
||||||
namespace Eval {
|
namespace Eval {
|
||||||
|
|
||||||
const Value Tempo = Value(20); // Must be visible to search
|
constexpr Value Tempo = Value(20); // Must be visible to search
|
||||||
|
|
||||||
extern std::atomic<Score> Contempt;
|
extern std::atomic<Score> Contempt;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace {
|
||||||
|
|
||||||
// Polynomial material imbalance parameters
|
// Polynomial material imbalance parameters
|
||||||
|
|
||||||
const int QuadraticOurs[][PIECE_TYPE_NB] = {
|
constexpr int QuadraticOurs[][PIECE_TYPE_NB] = {
|
||||||
// OUR PIECES
|
// OUR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{1667 }, // Bishop pair
|
{1667 }, // Bishop pair
|
||||||
|
@ -42,7 +42,7 @@ namespace {
|
||||||
{-189, 24, 117, 133, -134, -10 } // Queen
|
{-189, 24, 117, 133, -134, -10 } // Queen
|
||||||
};
|
};
|
||||||
|
|
||||||
const int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
constexpr int QuadraticTheirs[][PIECE_TYPE_NB] = {
|
||||||
// THEIR PIECES
|
// THEIR PIECES
|
||||||
// pair pawn knight bishop rook queen
|
// pair pawn knight bishop rook queen
|
||||||
{ 0 }, // Bishop pair
|
{ 0 }, // Bishop pair
|
||||||
|
@ -87,7 +87,7 @@ namespace {
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
int bonus = 0;
|
int bonus = 0;
|
||||||
|
|
||||||
|
@ -215,13 +215,13 @@ Entry* probe(const Position& pos) {
|
||||||
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
|
||||||
// for the bishop pair "extended piece", which allows us to be more flexible
|
// for the bishop pair "extended piece", which allows us to be more flexible
|
||||||
// in defining bishop pair bonuses.
|
// in defining bishop pair bonuses.
|
||||||
const int PieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
|
||||||
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
{ pos.count<BISHOP>(WHITE) > 1, pos.count<PAWN>(WHITE), pos.count<KNIGHT>(WHITE),
|
||||||
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
pos.count<BISHOP>(WHITE) , pos.count<ROOK>(WHITE), pos.count<QUEEN >(WHITE) },
|
||||||
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
{ pos.count<BISHOP>(BLACK) > 1, pos.count<PAWN>(BLACK), pos.count<KNIGHT>(BLACK),
|
||||||
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
pos.count<BISHOP>(BLACK) , pos.count<ROOK>(BLACK), pos.count<QUEEN >(BLACK) } };
|
||||||
|
|
||||||
e->value = int16_t((imbalance<WHITE>(PieceCount) - imbalance<BLACK>(PieceCount)) / 16);
|
e->value = int16_t((imbalance<WHITE>(pieceCount) - imbalance<BLACK>(pieceCount)) / 16);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace {
|
||||||
template<CastlingRight Cr, bool Checks, bool Chess960>
|
template<CastlingRight Cr, bool Checks, bool Chess960>
|
||||||
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) {
|
ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) {
|
||||||
|
|
||||||
static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
static constexpr bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO);
|
||||||
|
|
||||||
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
|
if (pos.castling_impeded(Cr) || !pos.can_castle(Cr))
|
||||||
return moveList;
|
return moveList;
|
||||||
|
@ -42,10 +42,10 @@ namespace {
|
||||||
|
|
||||||
assert(!pos.checkers());
|
assert(!pos.checkers());
|
||||||
|
|
||||||
const Direction K = Chess960 ? kto > kfrom ? WEST : EAST
|
const Direction step = Chess960 ? kto > kfrom ? WEST : EAST
|
||||||
: KingSide ? WEST : EAST;
|
: KingSide ? WEST : EAST;
|
||||||
|
|
||||||
for (Square s = kto; s != kfrom; s += K)
|
for (Square s = kto; s != kfrom; s += step)
|
||||||
if (pos.attackers_to(s) & enemies)
|
if (pos.attackers_to(s) & enemies)
|
||||||
return moveList;
|
return moveList;
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ namespace {
|
||||||
|
|
||||||
// Compute our parametrized parameters at compile time, named according to
|
// Compute our parametrized parameters at compile time, named according to
|
||||||
// the point of view of white side.
|
// the point of view of white side.
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
constexpr Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
|
||||||
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
const Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
||||||
const Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
||||||
|
|
||||||
Bitboard emptySquares;
|
Bitboard emptySquares;
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ namespace {
|
||||||
template<Color Us, GenType Type>
|
template<Color Us, GenType Type>
|
||||||
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) {
|
||||||
|
|
||||||
const bool Checks = Type == QUIET_CHECKS;
|
constexpr bool Checks = Type == QUIET_CHECKS;
|
||||||
|
|
||||||
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
|
||||||
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
moveList = generate_moves<KNIGHT, Checks>(pos, moveList, Us, target);
|
||||||
|
|
|
@ -32,20 +32,20 @@ namespace {
|
||||||
#define S(mg, eg) make_score(mg, eg)
|
#define S(mg, eg) make_score(mg, eg)
|
||||||
|
|
||||||
// Isolated pawn penalty
|
// Isolated pawn penalty
|
||||||
const Score Isolated = S(13, 18);
|
constexpr Score Isolated = S(13, 18);
|
||||||
|
|
||||||
// Backward pawn penalty
|
// Backward pawn penalty
|
||||||
const Score Backward = S(24, 12);
|
constexpr Score Backward = S(24, 12);
|
||||||
|
|
||||||
// Connected pawn bonus by opposed, phalanx, #support and rank
|
// Connected pawn bonus by opposed, phalanx, #support and rank
|
||||||
Score Connected[2][2][3][RANK_NB];
|
Score Connected[2][2][3][RANK_NB];
|
||||||
|
|
||||||
// Doubled pawn penalty
|
// Doubled pawn penalty
|
||||||
const Score Doubled = S(18, 38);
|
constexpr Score Doubled = S(18, 38);
|
||||||
|
|
||||||
// Weakness of our pawn shelter in front of the king by [isKingFile][distance from edge][rank].
|
// Weakness of our pawn shelter in front of the king by [isKingFile][distance from edge][rank].
|
||||||
// RANK_1 = 0 is used for files where we have no pawns or our pawn is behind our king.
|
// RANK_1 = 0 is used for files where we have no pawns or our pawn is behind our king.
|
||||||
const Value ShelterWeakness[][int(FILE_NB) / 2][RANK_NB] = {
|
constexpr Value ShelterWeakness[][int(FILE_NB) / 2][RANK_NB] = {
|
||||||
{ { V( 98), V(20), V(11), V(42), V( 83), V( 84), V(101) }, // Not On King file
|
{ { V( 98), V(20), V(11), V(42), V( 83), V( 84), V(101) }, // Not On King file
|
||||||
{ V(103), V( 8), V(33), V(86), V( 87), V(105), V(113) },
|
{ V(103), V( 8), V(33), V(86), V( 87), V(105), V(113) },
|
||||||
{ V(100), V( 2), V(65), V(95), V( 59), V( 89), V(115) },
|
{ V(100), V( 2), V(65), V(95), V( 59), V( 89), V(115) },
|
||||||
|
@ -59,7 +59,7 @@ namespace {
|
||||||
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank].
|
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank].
|
||||||
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
// For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has
|
||||||
// no pawn on the given file, or their pawn is behind our king.
|
// no pawn on the given file, or their pawn is behind our king.
|
||||||
const Value StormDanger[][4][RANK_NB] = {
|
constexpr Value StormDanger[][4][RANK_NB] = {
|
||||||
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
{ { V( 0), V(-290), V(-274), V(57), V(41) }, // BlockedByKing
|
||||||
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
{ V( 0), V( 60), V( 144), V(39), V(13) },
|
||||||
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
{ V( 0), V( 65), V( 141), V(41), V(34) },
|
||||||
|
@ -80,7 +80,7 @@ namespace {
|
||||||
|
|
||||||
// Max bonus for king safety. Corresponds to start position with all the pawns
|
// Max bonus for king safety. Corresponds to start position with all the pawns
|
||||||
// in front of the king and no enemy pawn on the horizon.
|
// in front of the king and no enemy pawn on the horizon.
|
||||||
const Value MaxSafetyBonus = V(258);
|
constexpr Value MaxSafetyBonus = V(258);
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
#undef V
|
#undef V
|
||||||
|
@ -88,8 +88,8 @@ namespace {
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
Score evaluate(const Position& pos, Pawns::Entry* e) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
const Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
|
||||||
|
|
||||||
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
|
||||||
Bitboard lever, leverPush;
|
Bitboard lever, leverPush;
|
||||||
|
@ -191,7 +191,7 @@ namespace Pawns {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
static const int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
|
static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
|
||||||
|
|
||||||
for (int opposed = 0; opposed <= 1; ++opposed)
|
for (int opposed = 0; opposed <= 1; ++opposed)
|
||||||
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
for (int phalanx = 0; phalanx <= 1; ++phalanx)
|
||||||
|
|
|
@ -52,8 +52,8 @@ namespace {
|
||||||
|
|
||||||
const string PieceToChar(" PNBRQK pnbrqk");
|
const string PieceToChar(" PNBRQK pnbrqk");
|
||||||
|
|
||||||
const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||||
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
|
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
|
||||||
|
|
||||||
// min_attacker() is a helper function used by see_ge() to locate the least
|
// min_attacker() is a helper function used by see_ge() to locate the least
|
||||||
// valuable attacker for the side to move, remove the attacker we just found
|
// valuable attacker for the side to move, remove the attacker we just found
|
||||||
|
@ -1146,7 +1146,7 @@ void Position::flip() {
|
||||||
|
|
||||||
bool Position::pos_is_ok() const {
|
bool Position::pos_is_ok() const {
|
||||||
|
|
||||||
const bool Fast = true; // Quick (default) or full check?
|
constexpr bool Fast = true; // Quick (default) or full check?
|
||||||
|
|
||||||
if ( (sideToMove != WHITE && sideToMove != BLACK)
|
if ( (sideToMove != WHITE && sideToMove != BLACK)
|
||||||
|| piece_on(square<KING>(WHITE)) != W_KING
|
|| piece_on(square<KING>(WHITE)) != W_KING
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace PSQT {
|
||||||
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
// type on a given square a (middlegame, endgame) score pair is assigned. Table
|
||||||
// is defined for files A..D and white side: it is symmetric for black side and
|
// is defined for files A..D and white side: it is symmetric for black side and
|
||||||
// second half of the files.
|
// second half of the files.
|
||||||
const Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
constexpr Score Bonus[][RANK_NB][int(FILE_NB) / 2] = {
|
||||||
{ },
|
{ },
|
||||||
{ // Pawn
|
{ // Pawn
|
||||||
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
{ S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) },
|
||||||
|
|
|
@ -63,12 +63,12 @@ namespace {
|
||||||
enum NodeType { NonPV, PV };
|
enum NodeType { NonPV, PV };
|
||||||
|
|
||||||
// Sizes and phases of the skip-blocks, used for distributing search depths across the threads
|
// Sizes and phases of the skip-blocks, used for distributing search depths across the threads
|
||||||
const int SkipSize[] = { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
|
constexpr int SkipSize[] = { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
|
||||||
const int SkipPhase[] = { 0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7 };
|
constexpr int SkipPhase[] = { 0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||||
|
|
||||||
// Razor and futility margins
|
// Razor and futility margins
|
||||||
const int RazorMargin1 = 590;
|
constexpr int RazorMargin1 = 590;
|
||||||
const int RazorMargin2 = 604;
|
constexpr int RazorMargin2 = 604;
|
||||||
Value futility_margin(Depth d, bool improving) {
|
Value futility_margin(Depth d, bool improving) {
|
||||||
return Value((175 - 50 * improving) * d / ONE_PLY);
|
return Value((175 - 50 * improving) * d / ONE_PLY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Position;
|
||||||
namespace Search {
|
namespace Search {
|
||||||
|
|
||||||
/// Threshold used for countermoves based pruning
|
/// Threshold used for countermoves based pruning
|
||||||
const int CounterMovePruneThreshold = 0;
|
constexpr int CounterMovePruneThreshold = 0;
|
||||||
|
|
||||||
|
|
||||||
/// Stack struct keeps track of the information we need to remember from nodes
|
/// Stack struct keeps track of the information we need to remember from nodes
|
||||||
|
|
|
@ -102,7 +102,7 @@ struct LR {
|
||||||
|
|
||||||
static_assert(sizeof(LR) == 3, "LR tree entry must be 3 bytes");
|
static_assert(sizeof(LR) == 3, "LR tree entry must be 3 bytes");
|
||||||
|
|
||||||
const int TBPIECES = 6;
|
constexpr int TBPIECES = 6;
|
||||||
|
|
||||||
struct PairsData {
|
struct PairsData {
|
||||||
int flags;
|
int flags;
|
||||||
|
@ -208,7 +208,7 @@ int MapKK[10][SQUARE_NB]; // [MapA1D1D4][SQUARE_NB]
|
||||||
bool pawns_comp(Square i, Square j) { return MapPawns[i] < MapPawns[j]; }
|
bool pawns_comp(Square i, Square j) { return MapPawns[i] < MapPawns[j]; }
|
||||||
int off_A1H8(Square sq) { return int(rank_of(sq)) - file_of(sq); }
|
int off_A1H8(Square sq) { return int(rank_of(sq)) - file_of(sq); }
|
||||||
|
|
||||||
const Value WDL_to_value[] = {
|
constexpr Value WDL_to_value[] = {
|
||||||
-VALUE_MATE + MAX_PLY + 1,
|
-VALUE_MATE + MAX_PLY + 1,
|
||||||
VALUE_DRAW - 2,
|
VALUE_DRAW - 2,
|
||||||
VALUE_DRAW,
|
VALUE_DRAW,
|
||||||
|
@ -255,8 +255,8 @@ class HashTable {
|
||||||
typedef std::pair<WDLEntry*, DTZEntry*> EntryPair;
|
typedef std::pair<WDLEntry*, DTZEntry*> EntryPair;
|
||||||
typedef std::pair<Key, EntryPair> Entry;
|
typedef std::pair<Key, EntryPair> Entry;
|
||||||
|
|
||||||
static const int TBHASHBITS = 10;
|
static constexpr int TBHASHBITS = 10;
|
||||||
static const int HSHMAX = 5;
|
static constexpr int HSHMAX = 5;
|
||||||
|
|
||||||
Entry hashTable[1 << TBHASHBITS][HSHMAX];
|
Entry hashTable[1 << TBHASHBITS][HSHMAX];
|
||||||
|
|
||||||
|
@ -315,9 +315,9 @@ public:
|
||||||
TBFile(const std::string& f) {
|
TBFile(const std::string& f) {
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
const char SepChar = ':';
|
constexpr char SepChar = ':';
|
||||||
#else
|
#else
|
||||||
const char SepChar = ';';
|
constexpr char SepChar = ';';
|
||||||
#endif
|
#endif
|
||||||
std::stringstream ss(Paths);
|
std::stringstream ss(Paths);
|
||||||
std::string path;
|
std::string path;
|
||||||
|
@ -649,7 +649,7 @@ WDLScore map_score(WDLEntry*, File, int value, WDLScore) { return WDLScore(value
|
||||||
|
|
||||||
int map_score(DTZEntry* entry, File f, int value, WDLScore wdl) {
|
int map_score(DTZEntry* entry, File f, int value, WDLScore wdl) {
|
||||||
|
|
||||||
const int WDLMap[] = { 1, 3, 0, 2, 0 };
|
constexpr int WDLMap[] = { 1, 3, 0, 2, 0 };
|
||||||
|
|
||||||
int flags = entry->hasPawns ? entry->pawnTable.file[f].precomp->flags
|
int flags = entry->hasPawns ? entry->pawnTable.file[f].precomp->flags
|
||||||
: entry->pieceTable.precomp->flags;
|
: entry->pieceTable.precomp->flags;
|
||||||
|
@ -682,7 +682,7 @@ int map_score(DTZEntry* entry, File f, int value, WDLScore wdl) {
|
||||||
template<typename Entry, typename T = typename Ret<Entry>::type>
|
template<typename Entry, typename T = typename Ret<Entry>::type>
|
||||||
T do_probe_table(const Position& pos, Entry* entry, WDLScore wdl, ProbeState* result) {
|
T do_probe_table(const Position& pos, Entry* entry, WDLScore wdl, ProbeState* result) {
|
||||||
|
|
||||||
const bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
constexpr bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
||||||
|
|
||||||
Square squares[TBPIECES];
|
Square squares[TBPIECES];
|
||||||
Piece pieces[TBPIECES];
|
Piece pieces[TBPIECES];
|
||||||
|
@ -1081,16 +1081,16 @@ void do_init(Entry& e, T& p, uint8_t* data) {
|
||||||
|
|
||||||
data++; // First byte stores flags
|
data++; // First byte stores flags
|
||||||
|
|
||||||
const int Sides = IsWDL && (e.key != e.key2) ? 2 : 1;
|
const int sides = IsWDL && (e.key != e.key2) ? 2 : 1;
|
||||||
const File MaxFile = e.hasPawns ? FILE_D : FILE_A;
|
const File maxFile = e.hasPawns ? FILE_D : FILE_A;
|
||||||
|
|
||||||
bool pp = e.hasPawns && e.pawnTable.pawnCount[1]; // Pawns on both sides
|
bool pp = e.hasPawns && e.pawnTable.pawnCount[1]; // Pawns on both sides
|
||||||
|
|
||||||
assert(!pp || e.pawnTable.pawnCount[0]);
|
assert(!pp || e.pawnTable.pawnCount[0]);
|
||||||
|
|
||||||
for (File f = FILE_A; f <= MaxFile; ++f) {
|
for (File f = FILE_A; f <= maxFile; ++f) {
|
||||||
|
|
||||||
for (int i = 0; i < Sides; i++)
|
for (int i = 0; i < sides; i++)
|
||||||
item(p, i, f).precomp = new PairsData();
|
item(p, i, f).precomp = new PairsData();
|
||||||
|
|
||||||
int order[][2] = { { *data & 0xF, pp ? *(data + 1) & 0xF : 0xF },
|
int order[][2] = { { *data & 0xF, pp ? *(data + 1) & 0xF : 0xF },
|
||||||
|
@ -1098,36 +1098,36 @@ void do_init(Entry& e, T& p, uint8_t* data) {
|
||||||
data += 1 + pp;
|
data += 1 + pp;
|
||||||
|
|
||||||
for (int k = 0; k < e.pieceCount; ++k, ++data)
|
for (int k = 0; k < e.pieceCount; ++k, ++data)
|
||||||
for (int i = 0; i < Sides; i++)
|
for (int i = 0; i < sides; i++)
|
||||||
item(p, i, f).precomp->pieces[k] = Piece(i ? *data >> 4 : *data & 0xF);
|
item(p, i, f).precomp->pieces[k] = Piece(i ? *data >> 4 : *data & 0xF);
|
||||||
|
|
||||||
for (int i = 0; i < Sides; ++i)
|
for (int i = 0; i < sides; ++i)
|
||||||
set_groups(e, item(p, i, f).precomp, order[i], f);
|
set_groups(e, item(p, i, f).precomp, order[i], f);
|
||||||
}
|
}
|
||||||
|
|
||||||
data += (uintptr_t)data & 1; // Word alignment
|
data += (uintptr_t)data & 1; // Word alignment
|
||||||
|
|
||||||
for (File f = FILE_A; f <= MaxFile; ++f)
|
for (File f = FILE_A; f <= maxFile; ++f)
|
||||||
for (int i = 0; i < Sides; i++)
|
for (int i = 0; i < sides; i++)
|
||||||
data = set_sizes(item(p, i, f).precomp, data);
|
data = set_sizes(item(p, i, f).precomp, data);
|
||||||
|
|
||||||
if (!IsWDL)
|
if (!IsWDL)
|
||||||
data = set_dtz_map(e, p, data, MaxFile);
|
data = set_dtz_map(e, p, data, maxFile);
|
||||||
|
|
||||||
for (File f = FILE_A; f <= MaxFile; ++f)
|
for (File f = FILE_A; f <= maxFile; ++f)
|
||||||
for (int i = 0; i < Sides; i++) {
|
for (int i = 0; i < sides; i++) {
|
||||||
(d = item(p, i, f).precomp)->sparseIndex = (SparseEntry*)data;
|
(d = item(p, i, f).precomp)->sparseIndex = (SparseEntry*)data;
|
||||||
data += d->sparseIndexSize * sizeof(SparseEntry);
|
data += d->sparseIndexSize * sizeof(SparseEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File f = FILE_A; f <= MaxFile; ++f)
|
for (File f = FILE_A; f <= maxFile; ++f)
|
||||||
for (int i = 0; i < Sides; i++) {
|
for (int i = 0; i < sides; i++) {
|
||||||
(d = item(p, i, f).precomp)->blockLength = (uint16_t*)data;
|
(d = item(p, i, f).precomp)->blockLength = (uint16_t*)data;
|
||||||
data += d->blockLengthSize * sizeof(uint16_t);
|
data += d->blockLengthSize * sizeof(uint16_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File f = FILE_A; f <= MaxFile; ++f)
|
for (File f = FILE_A; f <= maxFile; ++f)
|
||||||
for (int i = 0; i < Sides; i++) {
|
for (int i = 0; i < sides; i++) {
|
||||||
data = (uint8_t*)(((uintptr_t)data + 0x3F) & ~0x3F); // 64 byte alignment
|
data = (uint8_t*)(((uintptr_t)data + 0x3F) & ~0x3F); // 64 byte alignment
|
||||||
(d = item(p, i, f).precomp)->data = data;
|
(d = item(p, i, f).precomp)->data = data;
|
||||||
data += d->blocksNum * d->sizeofBlock;
|
data += d->blocksNum * d->sizeofBlock;
|
||||||
|
@ -1137,7 +1137,7 @@ void do_init(Entry& e, T& p, uint8_t* data) {
|
||||||
template<typename Entry>
|
template<typename Entry>
|
||||||
void* init(Entry& e, const Position& pos) {
|
void* init(Entry& e, const Position& pos) {
|
||||||
|
|
||||||
const bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
constexpr bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
||||||
|
|
||||||
static Mutex mutex;
|
static Mutex mutex;
|
||||||
|
|
||||||
|
@ -1158,7 +1158,7 @@ void* init(Entry& e, const Position& pos) {
|
||||||
b += std::string(popcount(pos.pieces(BLACK, pt)), PieceToChar[pt]);
|
b += std::string(popcount(pos.pieces(BLACK, pt)), PieceToChar[pt]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t TB_MAGIC[][4] = { { 0xD7, 0x66, 0x0C, 0xA5 },
|
constexpr uint8_t TB_MAGIC[][4] = { { 0xD7, 0x66, 0x0C, 0xA5 },
|
||||||
{ 0x71, 0xE8, 0x23, 0x5D } };
|
{ 0x71, 0xE8, 0x23, 0x5D } };
|
||||||
|
|
||||||
fname = (e.key == pos.material_key() ? w + 'v' + b : b + 'v' + w)
|
fname = (e.key == pos.material_key() ? w + 'v' + b : b + 'v' + w)
|
||||||
|
|
|
@ -32,9 +32,9 @@ namespace {
|
||||||
|
|
||||||
enum TimeType { OptimumTime, MaxTime };
|
enum TimeType { OptimumTime, MaxTime };
|
||||||
|
|
||||||
const int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
constexpr int MoveHorizon = 50; // Plan time management at most this many moves ahead
|
||||||
const double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
constexpr double MaxRatio = 7.3; // When in trouble, we can step over reserved time with this ratio
|
||||||
const double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
constexpr double StealRatio = 0.34; // However we must not steal time from remaining moves over this ratio
|
||||||
|
|
||||||
|
|
||||||
// move_importance() is a skew-logistic function based on naive statistical
|
// move_importance() is a skew-logistic function based on naive statistical
|
||||||
|
@ -44,9 +44,9 @@ namespace {
|
||||||
|
|
||||||
double move_importance(int ply) {
|
double move_importance(int ply) {
|
||||||
|
|
||||||
const double XScale = 6.85;
|
constexpr double XScale = 6.85;
|
||||||
const double XShift = 64.5;
|
constexpr double XShift = 64.5;
|
||||||
const double Skew = 0.171;
|
constexpr double Skew = 0.171;
|
||||||
|
|
||||||
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
return pow((1 + exp((ply - XShift) / XScale)), -Skew) + DBL_MIN; // Ensure non-zero
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ namespace {
|
||||||
template<TimeType T>
|
template<TimeType T>
|
||||||
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
int remaining(int myTime, int movesToGo, int ply, int slowMover) {
|
||||||
|
|
||||||
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
constexpr double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
|
||||||
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
constexpr double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
|
||||||
|
|
||||||
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
double moveImportance = (move_importance(ply) * slowMover) / 100;
|
||||||
double otherMovesImportance = 0;
|
double otherMovesImportance = 0;
|
||||||
|
@ -106,12 +106,12 @@ void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
|
||||||
startTime = limits.startTime;
|
startTime = limits.startTime;
|
||||||
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
optimumTime = maximumTime = std::max(limits.time[us], minThinkingTime);
|
||||||
|
|
||||||
const int MaxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
const int maxMTG = limits.movestogo ? std::min(limits.movestogo, MoveHorizon) : MoveHorizon;
|
||||||
|
|
||||||
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
// We calculate optimum time usage for different hypothetical "moves to go"-values
|
||||||
// and choose the minimum of calculated search time values. Usually the greatest
|
// and choose the minimum of calculated search time values. Usually the greatest
|
||||||
// hypMTG gives the minimum values.
|
// hypMTG gives the minimum values.
|
||||||
for (int hypMTG = 1; hypMTG <= MaxMTG; ++hypMTG)
|
for (int hypMTG = 1; hypMTG <= maxMTG; ++hypMTG)
|
||||||
{
|
{
|
||||||
// Calculate thinking time for hypothetical "moves to go"-value
|
// Calculate thinking time for hypothetical "moves to go"-value
|
||||||
int hypMyTime = limits.time[us]
|
int hypMyTime = limits.time[us]
|
||||||
|
|
4
src/tt.h
4
src/tt.h
|
@ -85,8 +85,8 @@ private:
|
||||||
|
|
||||||
class TranspositionTable {
|
class TranspositionTable {
|
||||||
|
|
||||||
static const int CacheLineSize = 64;
|
static constexpr int CacheLineSize = 64;
|
||||||
static const int ClusterSize = 3;
|
static constexpr int ClusterSize = 3;
|
||||||
|
|
||||||
struct Cluster {
|
struct Cluster {
|
||||||
TTEntry entry[ClusterSize];
|
TTEntry entry[ClusterSize];
|
||||||
|
|
16
src/types.h
16
src/types.h
|
@ -80,28 +80,28 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POPCNT
|
#ifdef USE_POPCNT
|
||||||
const bool HasPopCnt = true;
|
constexpr bool HasPopCnt = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPopCnt = false;
|
constexpr bool HasPopCnt = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PEXT
|
#ifdef USE_PEXT
|
||||||
const bool HasPext = true;
|
constexpr bool HasPext = true;
|
||||||
#else
|
#else
|
||||||
const bool HasPext = false;
|
constexpr bool HasPext = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef IS_64BIT
|
#ifdef IS_64BIT
|
||||||
const bool Is64Bit = true;
|
constexpr bool Is64Bit = true;
|
||||||
#else
|
#else
|
||||||
const bool Is64Bit = false;
|
constexpr bool Is64Bit = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint64_t Key;
|
typedef uint64_t Key;
|
||||||
typedef uint64_t Bitboard;
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
const int MAX_MOVES = 256;
|
constexpr int MAX_MOVES = 256;
|
||||||
const int MAX_PLY = 128;
|
constexpr int MAX_PLY = 128;
|
||||||
|
|
||||||
/// A move needs 16 bits to be stored
|
/// A move needs 16 bits to be stored
|
||||||
///
|
///
|
||||||
|
|
|
@ -56,7 +56,7 @@ bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const
|
||||||
void init(OptionsMap& o) {
|
void init(OptionsMap& o) {
|
||||||
|
|
||||||
// at most 2^32 clusters.
|
// at most 2^32 clusters.
|
||||||
const int MaxHashMB = Is64Bit ? 131072 : 2048;
|
constexpr int MaxHashMB = Is64Bit ? 131072 : 2048;
|
||||||
|
|
||||||
o["Debug Log File"] << Option("", on_logger);
|
o["Debug Log File"] << Option("", on_logger);
|
||||||
o["Contempt"] << Option(12, -100, 100);
|
o["Contempt"] << Option(12, -100, 100);
|
||||||
|
|
Loading…
Add table
Reference in a new issue