]> git.sesse.net Git - stockfish/commitdiff
Revert to Galurung's KBPsK endgame
authorMarco Costalba <mcostalba@gmail.com>
Fri, 2 May 2014 08:27:13 +0000 (10:27 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 2 May 2014 09:04:18 +0000 (11:04 +0200)
After reverting to the original Tord's
endgame, a search on position

7k/6p1/6B1/5K1P/8/8/8/8 w - - 0 1

Reports, correctly, a draw score instead of
an advantage for white.

Issue reported by Uri Blass.

bench: 8678654

src/endgame.cpp

index 9e60503e98f5e07602ec1335956de559b01df181..23c546d796dccc914724aa80b938781db2c30fba 100644 (file)
@@ -363,52 +363,27 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
   // be detected even when the weaker side has some pawns.
 
   Bitboard pawns = pos.pieces(strongSide, PAWN);
-  File pawnFile = file_of(pos.list<PAWN>(strongSide)[0]);
+  File pawnsFile = file_of(lsb(pawns));
 
   // All pawns are on a single rook file ?
-  if (    (pawnFile == FILE_A || pawnFile == FILE_H)
-      && !(pawns & ~file_bb(pawnFile)))
+  if (    (pawnsFile == FILE_A || pawnsFile == FILE_H)
+      && !(pawns & ~file_bb(pawnsFile)))
   {
       Square bishopSq = pos.list<BISHOP>(strongSide)[0];
-      Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8));
+      Square queeningSq = relative_square(strongSide, make_square(pawnsFile, RANK_8));
       Square kingSq = pos.king_square(weakSide);
 
+      // If the bishop has the wrong color, and the defending king is on the file
+      // of the pawn(s) or the neighboring file, then it's potentially a draw.
       if (   opposite_colors(queeningSq, bishopSq)
-          && square_distance(queeningSq, kingSq) <= 1)
-          return SCALE_FACTOR_DRAW;
-  }
-
-  // If all the pawns are on the same B or G file, then it's potentially a draw
-  if (    (pawnFile == FILE_B || pawnFile == FILE_G)
-      && !(pos.pieces(PAWN) & ~file_bb(pawnFile))
-      && pos.non_pawn_material(weakSide) == 0
-      && pos.count<PAWN>(weakSide) >= 1)
-  {
-      // Get weakSide pawn that is closest to the home rank
-      Square weakPawnSq = backmost_sq(weakSide, pos.pieces(weakSide, PAWN));
-
-      Square strongKingSq = pos.king_square(strongSide);
-      Square weakKingSq = pos.king_square(weakSide);
-      Square bishopSq = pos.list<BISHOP>(strongSide)[0];
-
-      // 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
-      if (   relative_rank(strongSide, weakPawnSq) == RANK_7
-          && (pos.pieces(strongSide, PAWN) & (weakPawnSq + pawn_push(weakSide)))
-          && (opposite_colors(bishopSq, weakPawnSq) || pos.count<PAWN>(strongSide) == 1))
+          && file_distance(kingSq, lsb(pawns)) <= 1)
       {
-          int strongKingDist = square_distance(weakPawnSq, strongKingSq);
-          int weakKingDist = square_distance(weakPawnSq, weakKingSq);
-
-          // It's a draw if the weak king is on its back two ranks, within 2
-          // squares of the blocking pawn and the strong king is not
-          // closer. (I think this rule only fails in practically
-          // unreachable positions such as 5k1K/6p1/6P1/8/8/3B4/8/8 w
-          // and positions where qsearch will immediately correct the
-          // problem such as 8/4k1p1/6P1/1K6/3B4/8/8/8 w)
-          if (   relative_rank(strongSide, weakKingSq) >= RANK_7
-              && weakKingDist <= 2
-              && weakKingDist <= strongKingDist)
+          // If the defending king has distance <= 1 to the promotion square or
+          // is placed somewhere in front of the frontmost pawn, it's a draw.
+          Rank rank = relative_rank(strongSide, (frontmost_sq(strongSide, pawns)));
+
+          if (   square_distance(kingSq, queeningSq) <= 1
+              || relative_rank(strongSide, kingSq) >= rank)
               return SCALE_FACTOR_DRAW;
       }
   }