Skip to content

Commit d799529

Browse files
protonspringsnicolet
authored andcommitted
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
1 parent 3984b8f commit d799529

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/pawns.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace {
3333

3434
// Pawn penalties
3535
constexpr Score Backward = S( 9, 24);
36+
constexpr Score BlockedStorm = S(82, 82);
3637
constexpr Score Doubled = S(11, 56);
3738
constexpr Score Isolated = S( 5, 15);
3839
constexpr Score WeakLever = S( 0, 56);
@@ -182,7 +183,7 @@ Entry* probe(const Position& pos) {
182183
/// penalty for a king, looking at the king file and the two closest files.
183184

184185
template<Color Us>
185-
void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
186+
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
186187

187188
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
188189

@@ -205,13 +206,12 @@ void Entry::evaluate_shelter(const Position& pos, Square ksq, Score& shelter) {
205206
bonus += make_score(ShelterStrength[d][ourRank], 0);
206207

207208
if (ourRank && (ourRank == theirRank - 1))
208-
bonus -= make_score(82 * (theirRank == RANK_3), 82 * (theirRank == RANK_3));
209+
bonus -= BlockedStorm * int(theirRank == RANK_3);
209210
else
210211
bonus -= make_score(UnblockedStorm[d][theirRank], 0);
211212
}
212213

213-
if (mg_value(bonus) > mg_value(shelter))
214-
shelter = bonus;
214+
return bonus;
215215
}
216216

217217

@@ -225,26 +225,31 @@ Score Entry::do_king_safety(const Position& pos) {
225225
kingSquares[Us] = ksq;
226226
castlingRights[Us] = pos.castling_rights(Us);
227227

228+
Score shelters[3] = { evaluate_shelter<Us>(pos, ksq),
229+
make_score(-VALUE_INFINITE, 0),
230+
make_score(-VALUE_INFINITE, 0) };
231+
232+
// If we can castle use the bonus after castling if it is bigger
233+
if (pos.can_castle(Us & KING_SIDE))
234+
shelters[1] = evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1));
235+
236+
if (pos.can_castle(Us & QUEEN_SIDE))
237+
shelters[2] = evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1));
238+
239+
for (int i : {1, 2})
240+
if (mg_value(shelters[i]) > mg_value(shelters[0]))
241+
shelters[0] = shelters[i];
242+
243+
// In endgame we like to bring our king near our closest pawn
228244
Bitboard pawns = pos.pieces(Us, PAWN);
229245
int minPawnDist = pawns ? 8 : 0;
230246

231247
if (pawns & PseudoAttacks[KING][ksq])
232248
minPawnDist = 1;
233-
234249
else while (pawns)
235250
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
236251

237-
Score shelter = make_score(-VALUE_INFINITE, 0);
238-
evaluate_shelter<Us>(pos, ksq, shelter);
239-
240-
// If we can castle use the bonus after the castling if it is bigger
241-
if (pos.can_castle(Us & KING_SIDE))
242-
evaluate_shelter<Us>(pos, relative_square(Us, SQ_G1), shelter);
243-
244-
if (pos.can_castle(Us & QUEEN_SIDE))
245-
evaluate_shelter<Us>(pos, relative_square(Us, SQ_C1), shelter);
246-
247-
return shelter - make_score(0, 16 * minPawnDist);
252+
return shelters[0] - make_score(0, 16 * minPawnDist);
248253
}
249254

250255
// Explicit template instantiation

src/pawns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Entry {
4949
Score do_king_safety(const Position& pos);
5050

5151
template<Color Us>
52-
void evaluate_shelter(const Position& pos, Square ksq, Score& shelter);
52+
Score evaluate_shelter(const Position& pos, Square ksq);
5353

5454
Key key;
5555
Score scores[COLOR_NB];

0 commit comments

Comments
 (0)