]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Don't prune discovered checks
[stockfish] / src / position.cpp
index be9e7ac847f68eac2e2bb339eaa84adb715f949a..9f2ee1970c36e28db3c055361c2bd7bcf584f6a9 100644 (file)
@@ -473,37 +473,6 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
 }
 
 
-/// Position::move_attacks_square() tests whether a move from the current
-/// position attacks a given square.
-
-bool Position::move_attacks_square(Move m, Square s) const {
-
-  assert(is_ok(m));
-  assert(is_ok(s));
-
-  Bitboard occ, xray;
-  Square from = from_sq(m);
-  Square to = to_sq(m);
-  Piece piece = piece_moved(m);
-
-  assert(!is_empty(from));
-
-  // Update occupancy as if the piece is moving
-  occ = pieces() ^ from ^ to;
-
-  // The piece moved in 'to' attacks the square 's' ?
-  if (attacks_from(piece, to, occ) & s)
-      return true;
-
-  // Scan for possible X-ray attackers behind the moved piece
-  xray =  (attacks_bb<  ROOK>(s, occ) & pieces(color_of(piece), QUEEN, ROOK))
-        | (attacks_bb<BISHOP>(s, occ) & pieces(color_of(piece), QUEEN, BISHOP));
-
-  // Verify attackers are triggered by our move and not already existing
-  return xray && (xray ^ (xray & attacks_from<QUEEN>(s)));
-}
-
-
 /// Position::pl_move_is_legal() tests whether a pseudo-legal move is legal
 
 bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
@@ -688,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());
@@ -700,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))
@@ -708,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
@@ -732,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 ?
@@ -744,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;
 }
 
 
@@ -1479,13 +1448,13 @@ bool Position::is_draw() const {
 
   if (CheckRepetition)
   {
-      int i = 4, e = std::min(st->rule50, st->pliesFromNull);
+      int i = 4, e = std::min(st->rule50, st->pliesFromNull), cnt;
 
       if (i <= e)
       {
           StateInfo* stp = st->previous->previous;
 
-          for (int cnt = 0; i <= e; i += 2)
+          for (cnt = 0; i <= e; i += 2)
           {
               stp = stp->previous->previous;