mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Sync with master
bench: 7696257
This commit is contained in:
commit
1277a42823
4 changed files with 84 additions and 77 deletions
|
@ -448,16 +448,13 @@ gcc-profile-prepare:
|
||||||
|
|
||||||
gcc-profile-make:
|
gcc-profile-make:
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-fprofile-arcs' \
|
EXTRACXXFLAGS='-fprofile-generate' \
|
||||||
EXTRALDFLAGS='-lgcov' \
|
EXTRALDFLAGS='-lgcov' \
|
||||||
all
|
all
|
||||||
|
|
||||||
gcc-profile-use:
|
gcc-profile-use:
|
||||||
# Deleting corrupt ucioption.gc* profile files is necessary to avoid an
|
|
||||||
# "internal compiler error" for gcc versions 4.7.x
|
|
||||||
@rm -f ucioption.gc*
|
|
||||||
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
|
||||||
EXTRACXXFLAGS='-fbranch-probabilities' \
|
EXTRACXXFLAGS='-fprofile-use -fno-peel-loops -fno-tracer' \
|
||||||
EXTRALDFLAGS='-lgcov' \
|
EXTRALDFLAGS='-lgcov' \
|
||||||
all
|
all
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace {
|
||||||
// Evaluation weights, indexed by evaluation term
|
// Evaluation weights, indexed by evaluation term
|
||||||
enum { Mobility, PawnStructure, PassedPawns, Space, KingSafety };
|
enum { Mobility, PawnStructure, PassedPawns, Space, KingSafety };
|
||||||
const struct Weight { int mg, eg; } Weights[] = {
|
const struct Weight { int mg, eg; } Weights[] = {
|
||||||
{289, 344}, {233, 201}, {221, 273}, {46, 0}, {324, 0}
|
{289, 344}, {233, 201}, {221, 273}, {46, 0}, {322, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define V(v) Value(v)
|
#define V(v) Value(v)
|
||||||
|
@ -162,6 +162,7 @@ namespace {
|
||||||
const Score TrappedRook = S(92, 0);
|
const Score TrappedRook = S(92, 0);
|
||||||
const Score Unstoppable = S( 0, 20);
|
const Score Unstoppable = S( 0, 20);
|
||||||
const Score Hanging = S(31, 26);
|
const Score Hanging = S(31, 26);
|
||||||
|
const Score PawnAttackThreat = S(20, 20);
|
||||||
|
|
||||||
// Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
|
// Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by
|
||||||
// a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
|
// a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only
|
||||||
|
@ -186,15 +187,15 @@ namespace {
|
||||||
// index to KingDanger[].
|
// index to KingDanger[].
|
||||||
//
|
//
|
||||||
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
// KingAttackWeights[PieceType] contains king attack weights by piece type
|
||||||
const int KingAttackWeights[] = { 0, 0, 8, 4, 4, 1 };
|
const int KingAttackWeights[] = { 0, 0, 7, 5, 4, 1 };
|
||||||
|
|
||||||
// Bonuses for enemy's safe checks
|
// Bonuses for enemy's safe checks
|
||||||
const int QueenContactCheck = 89;
|
const int QueenContactCheck = 89;
|
||||||
const int RookContactCheck = 72;
|
const int RookContactCheck = 71;
|
||||||
const int QueenCheck = 51;
|
const int QueenCheck = 50;
|
||||||
const int RookCheck = 38;
|
const int RookCheck = 37;
|
||||||
const int BishopCheck = 5;
|
const int BishopCheck = 6;
|
||||||
const int KnightCheck = 16;
|
const int KnightCheck = 14;
|
||||||
|
|
||||||
// KingDanger[attackUnits] contains the actual king danger weighted
|
// KingDanger[attackUnits] contains the actual king danger weighted
|
||||||
// scores, indexed by a calculated integer number.
|
// scores, indexed by a calculated integer number.
|
||||||
|
@ -412,10 +413,10 @@ namespace {
|
||||||
// attacked and undefended squares around our king and the quality of
|
// attacked and undefended squares around our king and the quality of
|
||||||
// the pawn shelter (current 'score' value).
|
// the pawn shelter (current 'score' value).
|
||||||
attackUnits = std::min(74, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
|
attackUnits = std::min(74, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them])
|
||||||
+ 9 * ei.kingAdjacentZoneAttacksCount[Them]
|
+ 8 * ei.kingAdjacentZoneAttacksCount[Them]
|
||||||
+ 25 * popcount<Max15>(undefended)
|
+ 25 * popcount<Max15>(undefended)
|
||||||
+ 10 * (ei.pinnedPieces[Us] != 0)
|
+ 11 * (ei.pinnedPieces[Us] != 0)
|
||||||
- mg_value(score) / 8
|
- mg_value(score) * 31 / 256
|
||||||
- !pos.count<QUEEN>(Them) * 60;
|
- !pos.count<QUEEN>(Them) * 60;
|
||||||
|
|
||||||
// Analyse the enemy's safe queen contact checks. Firstly, find the
|
// Analyse the enemy's safe queen contact checks. Firstly, find the
|
||||||
|
@ -492,7 +493,12 @@ namespace {
|
||||||
template<Color Us, bool Trace>
|
template<Color Us, bool Trace>
|
||||||
Score evaluate_threats(const Position& pos, const EvalInfo& ei) {
|
Score evaluate_threats(const Position& pos, const EvalInfo& ei) {
|
||||||
|
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S);
|
||||||
|
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE);
|
||||||
|
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW);
|
||||||
|
const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB);
|
||||||
|
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
||||||
|
|
||||||
enum { Defended, Weak };
|
enum { Defended, Weak };
|
||||||
enum { Minor, Major };
|
enum { Minor, Major };
|
||||||
|
@ -541,6 +547,21 @@ namespace {
|
||||||
score += more_than_one(b) ? KingOnMany : KingOnOne;
|
score += more_than_one(b) ? KingOnMany : KingOnOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add bonus for safe pawn pushes which attacks an enemy piece
|
||||||
|
b = pos.pieces(Us, PAWN) & ~TRank7BB;
|
||||||
|
b = shift_bb<Up>(b | (shift_bb<Up>(b & TRank2BB) & ~pos.pieces()));
|
||||||
|
|
||||||
|
b &= ~pos.pieces()
|
||||||
|
& ~ei.attackedBy[Them][PAWN]
|
||||||
|
& (ei.attackedBy[Us][PAWN] | ~ei.attackedBy[Them][ALL_PIECES]);
|
||||||
|
|
||||||
|
b = (shift_bb<Left>(b) | shift_bb<Right>(b))
|
||||||
|
& pos.pieces(Them)
|
||||||
|
& ~ei.attackedBy[Us][PAWN];
|
||||||
|
|
||||||
|
if(b)
|
||||||
|
score += popcount<Max15>(b) * PawnAttackThreat;
|
||||||
|
|
||||||
if (Trace)
|
if (Trace)
|
||||||
Tracing::write(Tracing::THREAT, Us, score);
|
Tracing::write(Tracing::THREAT, Us, score);
|
||||||
|
|
||||||
|
@ -891,7 +912,7 @@ namespace Eval {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
const double MaxSlope = 8.5;
|
const double MaxSlope = 8.7;
|
||||||
const double Peak = 1280;
|
const double Peak = 1280;
|
||||||
double t = 0.0;
|
double t = 0.0;
|
||||||
|
|
||||||
|
|
|
@ -64,31 +64,28 @@ namespace {
|
||||||
Endgame<KPsK> ScaleKPsK[] = { Endgame<KPsK>(WHITE), Endgame<KPsK>(BLACK) };
|
Endgame<KPsK> ScaleKPsK[] = { Endgame<KPsK>(WHITE), Endgame<KPsK>(BLACK) };
|
||||||
Endgame<KPKP> ScaleKPKP[] = { Endgame<KPKP>(WHITE), Endgame<KPKP>(BLACK) };
|
Endgame<KPKP> ScaleKPKP[] = { Endgame<KPKP>(WHITE), Endgame<KPKP>(BLACK) };
|
||||||
|
|
||||||
// Helper templates used to detect a given material distribution
|
// Helper used to detect a given material distribution
|
||||||
template<Color Us> bool is_KXK(const Position& pos) {
|
bool is_KXK(const Position& pos, Color us) {
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
return !more_than_one(pos.pieces(~us))
|
||||||
return !more_than_one(pos.pieces(Them))
|
&& pos.non_pawn_material(us) >= RookValueMg;
|
||||||
&& pos.non_pawn_material(Us) >= RookValueMg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us> bool is_KBPsKs(const Position& pos) {
|
bool is_KBPsKs(const Position& pos, Color us) {
|
||||||
return pos.non_pawn_material(Us) == BishopValueMg
|
return pos.non_pawn_material(us) == BishopValueMg
|
||||||
&& pos.count<BISHOP>(Us) == 1
|
&& pos.count<BISHOP>(us) == 1
|
||||||
&& pos.count<PAWN >(Us) >= 1;
|
&& pos.count<PAWN >(us) >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Color Us> bool is_KQKRPs(const Position& pos) {
|
bool is_KQKRPs(const Position& pos, Color us) {
|
||||||
const Color Them = (Us == WHITE ? BLACK : WHITE);
|
return !pos.count<PAWN>(us)
|
||||||
return !pos.count<PAWN>(Us)
|
&& pos.non_pawn_material(us) == QueenValueMg
|
||||||
&& pos.non_pawn_material(Us) == QueenValueMg
|
&& pos.count<QUEEN>(us) == 1
|
||||||
&& pos.count<QUEEN>(Us) == 1
|
&& pos.count<ROOK>(~us) == 1
|
||||||
&& pos.count<ROOK>(Them) == 1
|
&& pos.count<PAWN>(~us) >= 1;
|
||||||
&& pos.count<PAWN>(Them) >= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// imbalance() calculates the imbalance by comparing the piece count of each
|
/// imbalance() calculates the imbalance by comparing the piece count of each
|
||||||
/// piece type for both colors.
|
/// piece type for both colors.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
int imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
|
||||||
|
|
||||||
|
@ -142,17 +139,12 @@ Entry* probe(const Position& pos) {
|
||||||
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
if (is_KXK<WHITE>(pos))
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
{
|
if (is_KXK(pos, c))
|
||||||
e->evaluationFunction = &EvaluateKXK[WHITE];
|
{
|
||||||
return e;
|
e->evaluationFunction = &EvaluateKXK[c];
|
||||||
}
|
return e;
|
||||||
|
}
|
||||||
if (is_KXK<BLACK>(pos))
|
|
||||||
{
|
|
||||||
e->evaluationFunction = &EvaluateKXK[BLACK];
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// OK, we didn't find any special evaluation function for the current material
|
// OK, we didn't find any special evaluation function for the current material
|
||||||
// configuration. Is there a suitable specialized scaling function?
|
// configuration. Is there a suitable specialized scaling function?
|
||||||
|
@ -167,17 +159,14 @@ Entry* probe(const Position& pos) {
|
||||||
// We didn't find any specialized scaling function, so fall back on generic
|
// We didn't find any specialized scaling function, so fall back on generic
|
||||||
// ones that refer to more than one material distribution. Note that in this
|
// ones that refer to more than one material distribution. Note that in this
|
||||||
// case we don't return after setting the function.
|
// case we don't return after setting the function.
|
||||||
if (is_KBPsKs<WHITE>(pos))
|
for (Color c = WHITE; c <= BLACK; ++c)
|
||||||
e->scalingFunction[WHITE] = &ScaleKBPsK[WHITE];
|
{
|
||||||
|
if (is_KBPsKs(pos, c))
|
||||||
|
e->scalingFunction[c] = &ScaleKBPsK[c];
|
||||||
|
|
||||||
if (is_KBPsKs<BLACK>(pos))
|
else if (is_KQKRPs(pos, c))
|
||||||
e->scalingFunction[BLACK] = &ScaleKBPsK[BLACK];
|
e->scalingFunction[c] = &ScaleKQKRPs[c];
|
||||||
|
}
|
||||||
if (is_KQKRPs<WHITE>(pos))
|
|
||||||
e->scalingFunction[WHITE] = &ScaleKQKRPs[WHITE];
|
|
||||||
|
|
||||||
else if (is_KQKRPs<BLACK>(pos))
|
|
||||||
e->scalingFunction[BLACK] = &ScaleKQKRPs[BLACK];
|
|
||||||
|
|
||||||
Value npm_w = pos.non_pawn_material(WHITE);
|
Value npm_w = pos.non_pawn_material(WHITE);
|
||||||
Value npm_b = pos.non_pawn_material(BLACK);
|
Value npm_b = pos.non_pawn_material(BLACK);
|
||||||
|
|
|
@ -63,33 +63,33 @@ namespace {
|
||||||
|
|
||||||
// Weakness of our pawn shelter in front of the king by [distance from edge][rank]
|
// Weakness of our pawn shelter in front of the king by [distance from edge][rank]
|
||||||
const Value ShelterWeakness[][RANK_NB] = {
|
const Value ShelterWeakness[][RANK_NB] = {
|
||||||
{ V( 99), V(23), V(24), V(54), V(85), V( 93), V(107) },
|
{ V( 99), V(20), V(26), V(54), V(85), V( 92), V(108) },
|
||||||
{ V(119), V( 2), V(28), V(72), V(96), V(104), V(114) },
|
{ V(117), V( 1), V(27), V(71), V(94), V(104), V(118) },
|
||||||
{ V(103), V( 6), V(47), V(74), V(84), V(103), V( 94) },
|
{ V(104), V( 4), V(51), V(76), V(82), V(102), V( 97) },
|
||||||
{ V( 78), V(10), V(41), V(64), V(88), V( 92), V(115) } };
|
{ V( 80), V(12), V(43), V(65), V(88), V( 91), V(115) } };
|
||||||
|
|
||||||
// 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]
|
||||||
const Value StormDanger[][4][RANK_NB] = {
|
const Value StormDanger[][4][RANK_NB] = {
|
||||||
{ { V( 0), V( 65), V( 125), V(37), V(30) },
|
{ { V( 0), V( 65), V( 126), V(36), V(30) },
|
||||||
{ V( 0), V( 57), V( 136), V(39), V(24) },
|
{ V( 0), V( 55), V( 135), V(36), V(23) },
|
||||||
{ V( 0), V( 50), V( 114), V(45), V(29) },
|
{ V( 0), V( 47), V( 116), V(45), V(26) },
|
||||||
{ V( 0), V( 58), V( 129), V(56), V(34) } },
|
{ V( 0), V( 62), V( 127), V(57), V(34) } },
|
||||||
{ { V(20), V( 45), V( 91), V(47), V(20) },
|
{ { V(21), V( 45), V( 93), V(50), V(19) },
|
||||||
{ V(25), V( 23), V( 105), V(38), V(14) },
|
{ V(23), V( 24), V( 105), V(41), V(13) },
|
||||||
{ V(21), V( 37), V( 99), V(35), V(21) },
|
{ V(23), V( 36), V( 101), V(38), V(20) },
|
||||||
{ V(30), V( 18), V( 105), V(38), V(28) } },
|
{ V(30), V( 19), V( 110), V(41), V(27) } },
|
||||||
{ { V( 0), V( 0), V( 81), V(13), V( 4) },
|
{ { V( 0), V( 0), V( 81), V(14), V( 4) },
|
||||||
{ V( 0), V( 0), V( 169), V(30), V( 4) },
|
{ V( 0), V( 0), V( 169), V(30), V( 3) },
|
||||||
{ V( 0), V( 0), V( 166), V(24), V( 6) },
|
{ V( 0), V( 0), V( 168), V(24), V( 5) },
|
||||||
{ V( 0), V( 0), V( 164), V(24), V(11) } },
|
{ V( 0), V( 0), V( 162), V(26), V(10) } },
|
||||||
{ { V( 0), V(-289), V(-297), V(57), V(29) },
|
{ { V( 0), V(-283), V(-298), V(57), V(29) },
|
||||||
{ V( 0), V( 66), V( 136), V(43), V(16) },
|
{ V( 0), V( 63), V( 137), V(42), V(18) },
|
||||||
{ V( 0), V( 66), V( 141), V(50), V(31) },
|
{ V( 0), V( 67), V( 145), V(49), V(33) },
|
||||||
{ V( 0), V( 63), V( 126), V(52), V(23) } } };
|
{ V( 0), V( 62), V( 126), V(53), V(21) } } };
|
||||||
|
|
||||||
// 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(252);
|
const Value MaxSafetyBonus = V(258);
|
||||||
|
|
||||||
#undef S
|
#undef S
|
||||||
#undef V
|
#undef V
|
||||||
|
@ -147,7 +147,7 @@ namespace {
|
||||||
// If the pawn is passed, isolated, connected or a lever it cannot be
|
// If the pawn is passed, isolated, connected or a lever it cannot be
|
||||||
// backward. If there are friendly pawns behind on adjacent files
|
// backward. If there are friendly pawns behind on adjacent files
|
||||||
// it cannot be backward either.
|
// it cannot be backward either.
|
||||||
if ( (passed | isolated | connected | lever)
|
if ( (passed | isolated | lever | connected)
|
||||||
|| (ourPawns & pawn_attack_span(Them, s)))
|
|| (ourPawns & pawn_attack_span(Them, s)))
|
||||||
backward = false;
|
backward = false;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue