]> git.sesse.net Git - stockfish/commitdiff
Don't prune discovered checks
authorMarco Costalba <mcostalba@gmail.com>
Wed, 7 Nov 2012 17:20:39 +0000 (18:20 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 7 Nov 2012 17:29:56 +0000 (18:29 +0100)
Don't prune and eventually extend check moves of type
DISCO_CHECK (pun intended, Lucas will understand :-) ).

Patch from Lucas Braesch that has also tested it:

Result: 879-661-2137, score=52.96%, LOS=100.00% (time 10"+0.1")

I have started a verification test right now.

bench: 6004966

src/position.cpp
src/position.h
src/search.cpp
src/types.h

index 004d6994731ca106e0dd3d7afd6fb5f5b31fd719..9f2ee1970c36e28db3c055361c2bd7bcf584f6a9 100644 (file)
@@ -657,7 +657,7 @@ bool Position::is_pseudo_legal(const Move m) const {
 
 /// Position::move_gives_check() tests whether a pseudo-legal move gives a check
 
-bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
+CheckType Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
   assert(is_ok(m));
   assert(ci.dcCandidates == discovered_check_candidates());
@@ -669,7 +669,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
 
   // Direct check ?
   if (ci.checkSq[pt] & to)
-      return true;
+      return DIRECT_CHECK;
 
   // Discovery check ?
   if (ci.dcCandidates && (ci.dcCandidates & from))
@@ -677,19 +677,19 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
       // For pawn and king moves we need to verify also direction
       if (   (pt != PAWN && pt != KING)
           || !squares_aligned(from, to, king_square(~sideToMove)))
-          return true;
+          return DISCO_CHECK;
   }
 
   // Can we skip the ugly special cases ?
   if (type_of(m) == NORMAL)
-      return false;
+      return NO_CHECK;
 
   Color us = sideToMove;
   Square ksq = king_square(~us);
 
   // Promotion with check ?
   if (type_of(m) == PROMOTION)
-      return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
+      return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq ? DIRECT_CHECK : NO_CHECK;
 
   // En passant capture with check ? We have already handled the case
   // of direct checks and ordinary discovered check, the only case we
@@ -701,7 +701,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
       Bitboard b = (pieces() ^ from ^ capsq) | to;
 
       return  (attacks_bb<  ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
-            | (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP));
+            | (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP)) ? DISCO_CHECK : NO_CHECK;
   }
 
   // Castling with check ?
@@ -713,10 +713,10 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
       Square rto = relative_square(us, rfrom > kfrom ? SQ_F1 : SQ_D1);
       Bitboard b = (pieces() ^ kfrom ^ rfrom) | rto | kto;
 
-      return attacks_bb<ROOK>(rto, b) & ksq;
+      return attacks_bb<ROOK>(rto, b) & ksq ? DIRECT_CHECK : NO_CHECK;
   }
 
-  return false;
+  return NO_CHECK;
 }
 
 
index d09dce08c22a6f9fe93772cbee22b733bb13daf7..813cd0109210f2efdafd069ba8727029068de4e9 100644 (file)
@@ -136,7 +136,7 @@ public:
   template<PieceType> Bitboard attacks_from(Square s, Color c) const;
 
   // Properties of moves
-  bool move_gives_check(Move m, const CheckInfo& ci) const;
+  CheckType move_gives_check(Move m, const CheckInfo& ci) const;
   bool move_is_legal(const Move m) const;
   bool pl_move_is_legal(Move m, Bitboard pinned) const;
   bool is_pseudo_legal(const Move m) const;
index 3ffd8ae4c780262937f98e7f83227017b7d29c08..35a396814d676f4878738150ddd129d20e551bb1 100644 (file)
@@ -483,7 +483,8 @@ namespace {
     Depth ext, newDepth;
     Value bestValue, value, ttValue;
     Value eval, nullValue, futilityValue;
-    bool inCheck, givesCheck, pvMove, singularExtensionNode;
+    CheckType givesCheck;
+    bool inCheck, pvMove, singularExtensionNode;
     bool captureOrPromotion, dangerous, doFullDepthSearch;
     int moveCount, playedMoveCount;
 
@@ -815,7 +816,7 @@ split_point_start: // At split points actual search starts from here
       if (PvNode && dangerous)
           ext = ONE_PLY;
 
-      else if (givesCheck && pos.see_sign(move) >= 0)
+      else if (givesCheck && (givesCheck == DISCO_CHECK || pos.see_sign(move) >= 0))
           ext = ONE_PLY / 2;
 
       // Singular extension search. If all moves but one fail low on a search of
@@ -882,6 +883,7 @@ split_point_start: // At split points actual search starts from here
 
           // Prune moves with negative SEE at low depths
           if (   predictedDepth < 2 * ONE_PLY
+              && givesCheck != DISCO_CHECK
               && pos.see_sign(move) < 0)
           {
               if (SpNode)
@@ -1102,7 +1104,8 @@ split_point_start: // At split points actual search starts from here
     Key posKey;
     Move ttMove, move, bestMove;
     Value bestValue, value, ttValue, futilityValue, futilityBase;
-    bool givesCheck, enoughMaterial, evasionPrunable, fromNull;
+    CheckType givesCheck;
+    bool enoughMaterial, evasionPrunable, fromNull;
     Depth ttDepth;
 
     ss->currentMove = bestMove = MOVE_NONE;
@@ -1234,6 +1237,7 @@ split_point_start: // At split points actual search starts from here
       if (   !PvNode
           && (!InCheck || evasionPrunable)
           &&  move != ttMove
+          &&  givesCheck != DISCO_CHECK
           &&  type_of(move) != PROMOTION
           &&  pos.see_sign(move) < 0)
           continue;
index 9b36fd89fde9f9505dc54a2093bab49711cbf651..eea31e3b6f229cf8cc72b1abcdb8c363fce88216 100644 (file)
@@ -130,6 +130,12 @@ enum MoveType {
   CASTLE    = 3 << 14
 };
 
+enum CheckType {
+  NO_CHECK,
+  DIRECT_CHECK,
+  DISCO_CHECK
+};
+
 enum CastleRight {  // Defined as in PolyGlot book hash key
   CASTLES_NONE = 0,
   WHITE_OO     = 1,