Skip to content

Commit 28f7515

Browse files
Jerry Donald Watsongoodkov
authored andcommitted
Make kingRing always 8 squares
Make kingRing always eight squares, extending the bitboard to the F file if the king is on the H file, and to the C file if the king is on the A file. This may deal with cases where Stockfish (like many other engines) would shift the king around on the back rank like g1h1, not because there is some imminent threat, but because it makes king safety look a little better just because the king ring had a smaller area. STC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 34000 W: 7167 L: 6877 D: 19956 http://tests.stockfishchess.org/tests/view/5ab8216d0ebc5902932cbe64 LTC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 22574 W: 3576 L: 3370 D: 15628 http://tests.stockfishchess.org/tests/view/5ab84e6a0ebc5902932cbe72 How to continue from there? This patch probably makes it easier to tune the king safety evaluation, because the new regularity of the king ring size will make the king safety function more continuous. Closes official-stockfish#1512 Bench: 5934103
1 parent e1b119d commit 28f7515

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/bitboard.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ constexpr Bitboard make_bitboard(Square s, Squares... squares) {
165165
template<Direction D>
166166
constexpr Bitboard shift(Bitboard b) {
167167
return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
168-
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
169-
: D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
168+
: D == EAST ? (b & ~FileHBB) << 1 : D == WEST ? (b & ~FileABB) >> 1
169+
: D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == NORTH_WEST ? (b & ~FileABB) << 7
170+
: D == SOUTH_EAST ? (b & ~FileHBB) >> 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
170171
: 0;
171172
}
172173

src/evaluate.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ namespace {
275275
if (relative_rank(Us, pos.square<KING>(Us)) == RANK_1)
276276
kingRing[Us] |= shift<Up>(kingRing[Us]);
277277

278+
if (file_of(pos.square<KING>(Us)) == FILE_H)
279+
kingRing[Us] |= shift<WEST>(kingRing[Us]);
280+
281+
else if (file_of(pos.square<KING>(Us)) == FILE_A)
282+
kingRing[Us] |= shift<EAST>(kingRing[Us]);
283+
278284
kingAttackersCount[Them] = popcount(attackedBy[Us][KING] & pe->pawn_attacks(Them));
279285
kingAttacksCount[Them] = kingAttackersWeight[Them] = 0;
280286
}

0 commit comments

Comments
 (0)