mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Improve signature of evaluate_shelter()
Remove one parameter in function evaluate_shelter(), making all comparisons for castled/uncastled shelter locally in do_king_safety(). Also introduce BlockedStorm penalty. Passed non-regression test at STC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 65864 W: 14630 L: 14596 D: 36638 http://tests.stockfishchess.org/tests/view/5d5fc80c0ebc5939d09f0acc No functional change
This commit is contained in:
parent
3984b8f8f0
commit
d799529b48
2 changed files with 22 additions and 17 deletions
|
@ -33,6 +33,7 @@ namespace {
|
||||||
|
|
||||||
// Pawn penalties
|
// Pawn penalties
|
||||||
constexpr Score Backward = S( 9, 24);
|
constexpr Score Backward = S( 9, 24);
|
||||||
|
constexpr Score BlockedStorm = S(82, 82);
|
||||||
constexpr Score Doubled = S(11, 56);
|
constexpr Score Doubled = S(11, 56);
|
||||||
constexpr Score Isolated = S( 5, 15);
|
constexpr Score Isolated = S( 5, 15);
|
||||||
constexpr Score WeakLever = S( 0, 56);
|
constexpr Score WeakLever = S( 0, 56);
|
||||||
|
@ -182,7 +183,7 @@ Entry* probe(const Position& pos) {
|
||||||
/// penalty for a king, looking at the king file and the two closest files.
|
/// penalty for a king, looking at the king file and the two closest files.
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
|
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
|
||||||
|
|
||||||
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
|
||||||
|
|
||||||
|
@ -205,13 +206,12 @@ void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
|
||||||
bonus += make_score(ShelterStrength[d][ourRank], 0);
|
bonus += make_score(ShelterStrength[d][ourRank], 0);
|
||||||
|
|
||||||
if (ourRank && (ourRank == theirRank - 1))
|
if (ourRank && (ourRank == theirRank - 1))
|
||||||
bonus -= make_score(82 * (theirRank == RANK_3), 82 * (theirRank == RANK_3));
|
bonus -= BlockedStorm * int(theirRank == RANK_3);
|
||||||
else
|
else
|
||||||
bonus -= make_score(UnblockedStorm[d][theirRank], 0);
|
bonus -= make_score(UnblockedStorm[d][theirRank], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mg_value(bonus) > mg_value(shelter))
|
return bonus;
|
||||||
shelter = bonus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,26 +225,31 @@ Score Entry::do_king_safety(const Position& pos) {
|
||||||
kingSquares[Us] = ksq;
|
kingSquares[Us] = ksq;
|
||||||
castlingRights[Us] = pos.castling_rights(Us);
|
castlingRights[Us] = pos.castling_rights(Us);
|
||||||
|
|
||||||
|
Score shelters[3] = { evaluate_shelter<Us>(pos, ksq),
|
||||||
|
make_score(-VALUE_INFINITE, 0),
|
||||||
|
make_score(-VALUE_INFINITE, 0) };
|
||||||
|
|
||||||
|
// If we can castle use the bonus after castling if it is bigger
|
||||||
|
if (pos.can_castle(Us & KING_SIDE))
|
||||||
|
shelters[1] = evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1));
|
||||||
|
|
||||||
|
if (pos.can_castle(Us & QUEEN_SIDE))
|
||||||
|
shelters[2] = evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1));
|
||||||
|
|
||||||
|
for (int i : {1, 2})
|
||||||
|
if (mg_value(shelters[i]) > mg_value(shelters[0]))
|
||||||
|
shelters[0] = shelters[i];
|
||||||
|
|
||||||
|
// In endgame we like to bring our king near our closest pawn
|
||||||
Bitboard pawns = pos.pieces(Us, PAWN);
|
Bitboard pawns = pos.pieces(Us, PAWN);
|
||||||
int minPawnDist = pawns ? 8 : 0;
|
int minPawnDist = pawns ? 8 : 0;
|
||||||
|
|
||||||
if (pawns & PseudoAttacks[KING][ksq])
|
if (pawns & PseudoAttacks[KING][ksq])
|
||||||
minPawnDist = 1;
|
minPawnDist = 1;
|
||||||
|
|
||||||
else while (pawns)
|
else while (pawns)
|
||||||
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
|
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
|
||||||
|
|
||||||
Score shelter = make_score(-VALUE_INFINITE, 0);
|
return shelters[0] - make_score(0, 16 * minPawnDist);
|
||||||
evaluate_shelter<Us>(pos, ksq, shelter);
|
|
||||||
|
|
||||||
// If we can castle use the bonus after the castling if it is bigger
|
|
||||||
if (pos.can_castle(Us & KING_SIDE))
|
|
||||||
evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1), shelter);
|
|
||||||
|
|
||||||
if (pos.can_castle(Us & QUEEN_SIDE))
|
|
||||||
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);
|
|
||||||
|
|
||||||
return shelter - make_score(0, 16 * minPawnDist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit template instantiation
|
// Explicit template instantiation
|
||||||
|
|
|
@ -49,7 +49,7 @@ struct Entry {
|
||||||
Score do_king_safety(const Position& pos);
|
Score do_king_safety(const Position& pos);
|
||||||
|
|
||||||
template<Color Us>
|
template<Color Us>
|
||||||
void evaluate_shelter(const Position& pos, Square ksq, Score& shelter);
|
Score evaluate_shelter(const Position& pos, Square ksq);
|
||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
Score scores[COLOR_NB];
|
Score scores[COLOR_NB];
|
||||||
|
|
Loading…
Add table
Reference in a new issue