]> git.sesse.net Git - stockfish/commitdiff
Simplification of KPsK function
authorChris Caino <chricainogithub@gmail.com>
Mon, 14 Oct 2013 23:20:34 +0000 (00:20 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 15 Oct 2013 05:36:01 +0000 (07:36 +0200)
Also the drawing criteria has been slightly loosened.
It now detects a draw if the king is ahead of all the
pawns and on the same file or the adjacent file.

bench: 7700683

src/endgame.cpp

index 5906b4d59187aecd8604e191bba119591d37a995..635ff4085382ad07f4d2ecc67a7fbcfacb615695 100644 (file)
@@ -684,25 +684,15 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
 
   Square ksq = pos.king_square(weakSide);
   Bitboard pawns = pos.pieces(strongSide, PAWN);
+  Square psq = pos.list<PAWN>(strongSide)[0];
+
+  // If all pawns are ahead of the king, all pawns are on a single
+  // rook file and the king is within one file of the pawns then draw.
+  if (   !(pawns & ~in_front_bb(weakSide, rank_of(ksq)))
+      && !((pawns & ~FileABB) && (pawns & ~FileHBB))
+      && file_distance(ksq, psq) <= 1)
+      return SCALE_FACTOR_DRAW;
 
-  // Are all pawns on the 'a' file?
-  if (!(pawns & ~FileABB))
-  {
-      // Does the defending king block the pawns?
-      if (   square_distance(ksq, relative_square(strongSide, SQ_A8)) <= 1
-          || (    file_of(ksq) == FILE_A
-              && !(in_front_bb(strongSide, rank_of(ksq)) & pawns)))
-          return SCALE_FACTOR_DRAW;
-  }
-  // Are all pawns on the 'h' file?
-  else if (!(pawns & ~FileHBB))
-  {
-    // Does the defending king block the pawns?
-    if (   square_distance(ksq, relative_square(strongSide, SQ_H8)) <= 1
-        || (    file_of(ksq) == FILE_H
-            && !(in_front_bb(strongSide, rank_of(ksq)) & pawns)))
-        return SCALE_FACTOR_DRAW;
-  }
   return SCALE_FACTOR_NONE;
 }