1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

Cleanup KBPsK endgame

* Clarify distinction between strong side pawns and all pawns.
* Simplify and speed-up determination of pawns on the same file.
* Clarify comments.
* more_than_one() is probably faster than pos.count.

Passed STC:
LLR: 2.95 (-2.94,2.94) {-1.50,0.50}
Total: 40696 W: 7856 L: 7740 D: 25100
Ptnml(0-2): 584, 4519, 10054, 4579, 612
http://tests.stockfishchess.org/tests/view/5e6153b1e42a5c3b3ca2e1a9

closes https://github.com/official-stockfish/Stockfish/pull/2574

No functional change.
This commit is contained in:
protonspring 2020-03-05 12:07:48 -07:00 committed by Joost VandeVondele
parent 0424273d0b
commit e7c1c8c1ab

View file

@ -343,29 +343,27 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
// No assertions about the material of weakSide, because we want draws to // No assertions about the material of weakSide, because we want draws to
// be detected even when the weaker side has some pawns. // be detected even when the weaker side has some pawns.
Bitboard pawns = pos.pieces(strongSide, PAWN); Bitboard strongpawns = pos.pieces(strongSide, PAWN);
File pawnsFile = file_of(lsb(pawns)); Bitboard allpawns = pos.pieces(PAWN);
// All pawns are on a single rook file? // All strongSide pawns are on a single rook file?
if ( (pawnsFile == FILE_A || pawnsFile == FILE_H) if (!(strongpawns & ~FileABB) || !(strongpawns & ~FileHBB))
&& !(pawns & ~file_bb(pawnsFile)))
{ {
Square bishopSq = pos.square<BISHOP>(strongSide); Square bishopSq = pos.square<BISHOP>(strongSide);
Square queeningSq = relative_square(strongSide, make_square(pawnsFile, RANK_8)); Square queeningSq = relative_square(strongSide, make_square(file_of(lsb(strongpawns)), RANK_8));
Square kingSq = pos.square<KING>(weakSide); Square weakkingSq = pos.square<KING>(weakSide);
if ( opposite_colors(queeningSq, bishopSq) if ( opposite_colors(queeningSq, bishopSq)
&& distance(queeningSq, kingSq) <= 1) && distance(queeningSq, weakkingSq) <= 1)
return SCALE_FACTOR_DRAW; return SCALE_FACTOR_DRAW;
} }
// If all the pawns are on the same B or G file, then it's potentially a draw // If all the pawns are on the same B or G file, then it's potentially a draw
if ( (pawnsFile == FILE_B || pawnsFile == FILE_G) if ((!(allpawns & ~FileBBB) || !(allpawns & ~FileGBB))
&& !(pos.pieces(PAWN) & ~file_bb(pawnsFile))
&& pos.non_pawn_material(weakSide) == 0 && pos.non_pawn_material(weakSide) == 0
&& pos.count<PAWN>(weakSide) >= 1) && pos.count<PAWN>(weakSide) >= 1)
{ {
// Get weakSide pawn that is closest to the home rank // Get the least advanced weakSide pawn
Square weakPawnSq = frontmost_sq(strongSide, pos.pieces(weakSide, PAWN)); Square weakPawnSq = frontmost_sq(strongSide, pos.pieces(weakSide, PAWN));
Square strongKingSq = pos.square<KING>(strongSide); Square strongKingSq = pos.square<KING>(strongSide);
@ -375,8 +373,8 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
// There's potential for a draw if our pawn is blocked on the 7th rank, // There's potential for a draw if our pawn is blocked on the 7th rank,
// the bishop cannot attack it or they only have one pawn left // the bishop cannot attack it or they only have one pawn left
if ( relative_rank(strongSide, weakPawnSq) == RANK_7 if ( relative_rank(strongSide, weakPawnSq) == RANK_7
&& (pos.pieces(strongSide, PAWN) & (weakPawnSq + pawn_push(weakSide))) && (strongpawns & (weakPawnSq + pawn_push(weakSide)))
&& (opposite_colors(bishopSq, weakPawnSq) || pos.count<PAWN>(strongSide) == 1)) && (opposite_colors(bishopSq, weakPawnSq) || !more_than_one(strongpawns)))
{ {
int strongKingDist = distance(weakPawnSq, strongKingSq); int strongKingDist = distance(weakPawnSq, strongKingSq);
int weakKingDist = distance(weakPawnSq, weakKingSq); int weakKingDist = distance(weakPawnSq, weakKingSq);