]> git.sesse.net Git - stockfish/commitdiff
Remove update_checkers()
authorMarco Costalba <mcostalba@gmail.com>
Wed, 11 Nov 2009 09:41:46 +0000 (10:41 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 11 Nov 2009 21:26:29 +0000 (22:26 +0100)
Now that we have CheckInfo we don't need it anymore.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp
src/position.h
src/search.cpp

index ca1c21c38dc8a5f2f7e9e8f16f971ed59c75313c..8954834ad546bb8c4902b9c3a45be485dafa707f 100644 (file)
@@ -343,16 +343,15 @@ void Position::copy(const Position& pos) {
 template<bool FindPinned>
 Bitboard Position::hidden_checkers(Color c) const {
 
-  Bitboard pinners, result = EmptyBoardBB;
+  Bitboard result = EmptyBoardBB;
+  Bitboard pinners = pieces_of_color(FindPinned ? opposite_color(c) : c);
 
   // Pinned pieces protect our king, dicovery checks attack
   // the enemy king.
   Square ksq = king_square(FindPinned ? c : opposite_color(c));
 
-  // Pinners are sliders, not checkers, that give check when
-  // candidate pinned is removed.
-  pinners =  (pieces(ROOK, QUEEN, FindPinned ? opposite_color(c) : c) & RookPseudoAttacks[ksq])
-           | (pieces(BISHOP, QUEEN, FindPinned ? opposite_color(c) : c) & BishopPseudoAttacks[ksq]);
+  // Pinners are sliders, not checkers, that give check when candidate pinned is removed
+  pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq]) | (pieces(BISHOP, QUEEN) & BishopPseudoAttacks[ksq]);
 
   if (FindPinned && pinners)
       pinners &= ~st->checkersBB;
@@ -647,49 +646,17 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
 }
 
 
-/// Position::update_checkers() udpates chekers info given the move. It is called
-/// in do_move() and is faster then find_checkers().
-
-template<PieceType Piece>
-inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from,
-                                      Square to, Bitboard dcCandidates) {
-
-  const bool Bishop = (Piece == QUEEN || Piece == BISHOP);
-  const bool Rook   = (Piece == QUEEN || Piece == ROOK);
-  const bool Slider = Bishop || Rook;
-
-  assert(*pCheckersBB == EmptyBoardBB);
-
-  // Direct checks
-  if (  (   !Slider // try to early skip slide piece attacks
-         || (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to))
-         || (Rook   && bit_is_set(RookPseudoAttacks[ksq], to)))
-      && bit_is_set(Piece == PAWN ? attacks_from<PAWN>(ksq, opposite_color(sideToMove)) : attacks_from<Piece>(ksq) , to))
-  {
-      *pCheckersBB = SetMaskBB[to];
-  }
-  // Discovery checks
-  if (Piece != QUEEN && dcCandidates && bit_is_set(dcCandidates, from))
-  {
-      if (Piece != ROOK)
-          (*pCheckersBB) |= (attacks_from<ROOK>(ksq) & pieces(ROOK, QUEEN, side_to_move()));
-
-      if (Piece != BISHOP)
-          (*pCheckersBB) |= (attacks_from<BISHOP>(ksq) & pieces(BISHOP, QUEEN, side_to_move()));
-  }
-}
-
-
 /// Position::do_move() makes a move, and saves all information necessary
 /// to a StateInfo object. The move is assumed to be legal.
 /// Pseudo-legal moves should be filtered out before this function is called.
 
 void Position::do_move(Move m, StateInfo& newSt) {
 
-  do_move(m, newSt, discovered_check_candidates(side_to_move()));
+  CheckInfo ci(*this);
+  do_move(m, newSt, ci, move_is_check(m, ci));
 }
 
-void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool moveCanBeCheck) {
+void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveIsCheck) {
 
   assert(is_ok());
   assert(move_is_ok(m));
@@ -860,22 +827,24 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool mov
   // Update checkers bitboard, piece must be already moved
   st->checkersBB = EmptyBoardBB;
 
-  if (moveCanBeCheck)
+  if (moveIsCheck)
   {
       if (ep | pm)
           st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
       else
       {
-          Square ksq = king_square(them);
-          switch (pt)
+          // Direct checks
+          if (bit_is_set(ci.checkSq[pt], to))
+              st->checkersBB = SetMaskBB[to];
+
+          // Discovery checks
+          if (ci.dcCandidates && bit_is_set(ci.dcCandidates, from))
           {
-          case PAWN:   update_checkers<PAWN>(&(st->checkersBB), ksq, from, to, dcCandidates);   break;
-          case KNIGHT: update_checkers<KNIGHT>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
-          case BISHOP: update_checkers<BISHOP>(&(st->checkersBB), ksq, from, to, dcCandidates); break;
-          case ROOK:   update_checkers<ROOK>(&(st->checkersBB), ksq, from, to, dcCandidates);   break;
-          case QUEEN:  update_checkers<QUEEN>(&(st->checkersBB), ksq, from, to, dcCandidates);  break;
-          case KING:   update_checkers<KING>(&(st->checkersBB), ksq, from, to, dcCandidates);   break;
-          default: assert(false); break;
+              if (pt != ROOK)
+                  st->checkersBB |= (attacks_from<ROOK>(ci.ksq) & pieces(ROOK, QUEEN, us));
+
+              if (pt != BISHOP)
+                  st->checkersBB |= (attacks_from<BISHOP>(ci.ksq) & pieces(BISHOP, QUEEN, us));
           }
       }
   }
index eecf53527a7e169a33119ba5461a1bd2bebd8228..f6e49687de45c7b7bf2e5cb04ef61c5ff5ee9b5f 100644 (file)
@@ -236,7 +236,7 @@ public:
   // Doing and undoing moves
   void saveState();
   void do_move(Move m, StateInfo& st);
-  void do_move(Move m, StateInfo& st, Bitboard dcCandidates, bool moveCanBeCheck = true);
+  void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
@@ -296,9 +296,6 @@ private:
   void undo_castle_move(Move m);
   void find_checkers();
 
-  template<PieceType Piece>
-  void update_checkers(Bitboard* pCheckersBB, Square ksq, Square from, Square to, Bitboard dcCandidates);
-
   template<bool FindPinned>
   Bitboard hidden_checkers(Color c) const;
 
index c4e061bd6cd1afb5d8bcc0035bda587668adb86d..c217e953715b48d1211efd43eb02f21521065fcc 100644 (file)
@@ -349,7 +349,7 @@ int perft(Position& pos, Depth depth)
     while ((move = mp.get_next_move()) != MOVE_NONE)
     {
       StateInfo st;
-      pos.do_move(move, st, ci.dcCandidates, pos.move_is_check(move, ci));
+      pos.do_move(move, st, ci, pos.move_is_check(move, ci));
       sum += perft(pos, depth - OnePly);
       pos.undo_move(move);
     }
@@ -898,13 +898,14 @@ namespace {
                       << " currmovenumber " << i + 1 << std::endl;
 
         // Decide search depth for this move
+        bool moveIsCheck = pos.move_is_check(move);
         bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
         bool dangerous;
-        ext = extension(pos, move, true, captureOrPromotion, pos.move_is_check(move), false, false, &dangerous);
+        ext = extension(pos, move, true, captureOrPromotion, moveIsCheck, false, false, &dangerous);
         newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
 
         // Make the move, and search it
-        pos.do_move(move, st, ci.dcCandidates);
+        pos.do_move(move, st, ci, moveIsCheck);
 
         if (i < MultiPV)
         {
@@ -1135,7 +1136,7 @@ namespace {
       newDepth = depth - OnePly + ext;
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
+      pos.do_move(move, st, ci, moveIsCheck);
 
       if (moveCount == 1) // The first move in list is the PV
           value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
@@ -1424,7 +1425,7 @@ namespace {
       }
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
+      pos.do_move(move, st, ci, moveIsCheck);
 
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
       // if the move fails high will be re-searched at full depth.
@@ -1637,7 +1638,7 @@ namespace {
           continue;
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
+      pos.do_move(move, st, ci, moveIsCheck);
       value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
       pos.undo_move(move);
 
@@ -1764,7 +1765,7 @@ namespace {
 
       // Make and search the move.
       StateInfo st;
-      pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
+      pos.do_move(move, st, ci, moveIsCheck);
 
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
       // if the move fails high will be re-searched at full depth.
@@ -1870,7 +1871,7 @@ namespace {
 
       // Make and search the move.
       StateInfo st;
-      pos.do_move(move, st, sp->dcCandidates, moveIsCheck);
+      pos.do_move(move, st, ci, moveIsCheck);
 
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
       // if the move fails high will be re-searched at full depth.