]> git.sesse.net Git - stockfish/commitdiff
Propagate "move is check" info to do_move()
authorMarco Costalba <mcostalba@gmail.com>
Tue, 10 Nov 2009 10:05:20 +0000 (11:05 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 10 Nov 2009 17:12:19 +0000 (18:12 +0100)
When false (common case) we avoid to update checkers
bitboard that although not so costly slows down a bit
this very hot and critical path.

No functional change.

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

index 366d61f309ed9706b0bec3d3af5797b9b8fdf48f..ca1c21c38dc8a5f2f7e9e8f16f971ed59c75313c 100644 (file)
@@ -689,7 +689,7 @@ void Position::do_move(Move m, StateInfo& newSt) {
   do_move(m, newSt, discovered_check_candidates(side_to_move()));
 }
 
-void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
+void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates, bool moveCanBeCheck) {
 
   assert(is_ok());
   assert(move_is_ok(m));
@@ -858,21 +858,25 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   st->key = key;
 
   // Update checkers bitboard, piece must be already moved
-  if (ep | pm)
-      st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
-  else
+  st->checkersBB = EmptyBoardBB;
+
+  if (moveCanBeCheck)
   {
-      st->checkersBB = EmptyBoardBB;
-      Square ksq = king_square(them);
-      switch (pt)
+      if (ep | pm)
+          st->checkersBB = attackers_to(king_square(them)) & pieces_of_color(us);
+      else
       {
-      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;
+          Square ksq = king_square(them);
+          switch (pt)
+          {
+          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;
+          }
       }
   }
 
index c04f1412e5db666ef0ac06f86395171f663abc66..eecf53527a7e169a33119ba5461a1bd2bebd8228 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);
+  void do_move(Move m, StateInfo& st, Bitboard dcCandidates, bool moveCanBeCheck = true);
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
index 1d4de838f6bf199cc2b1c698ded66fa2cd1d86ab..44c29ec878209a882c27f5880878443ac32a0081 100644 (file)
@@ -334,7 +334,6 @@ int perft(Position& pos, Depth depth)
 {
     Move move;
     MovePicker mp = MovePicker(pos, MOVE_NONE, depth, H);
-    Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move());
     int sum = 0;
 
     // If we are at the last ply we don't need to do and undo
@@ -346,10 +345,11 @@ int perft(Position& pos, Depth depth)
     }
 
     // Loop through all legal moves
+    CheckInfo ci(pos);
     while ((move = mp.get_next_move()) != MOVE_NONE)
     {
       StateInfo st;
-      pos.do_move(move, st, dcCandidates);
+      pos.do_move(move, st, ci.dcCandidates, pos.move_is_check(move, ci));
       sum += perft(pos, depth - OnePly);
       pos.undo_move(move);
     }
@@ -862,7 +862,7 @@ namespace {
 
     Value oldAlpha = alpha;
     Value value;
-    Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move());
+    CheckInfo ci(pos);
 
     // Loop through all the moves in the root move list
     for (int i = 0; i <  rml.move_count() && !AbortSearch; i++)
@@ -904,7 +904,7 @@ namespace {
         newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
 
         // Make the move, and search it
-        pos.do_move(move, st, dcCandidates);
+        pos.do_move(move, st, ci.dcCandidates);
 
         if (i < MultiPV)
         {
@@ -1135,7 +1135,7 @@ namespace {
       newDepth = depth - OnePly + ext;
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates);
+      pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
 
       if (moveCount == 1) // The first move in list is the PV
           value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
@@ -1423,7 +1423,7 @@ namespace {
       }
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates);
+      pos.do_move(move, st, ci.dcCandidates, 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.
@@ -1520,7 +1520,7 @@ namespace {
     StateInfo st;
     Move ttMove, move;
     Value staticValue, bestValue, value, futilityValue;
-    bool isCheck, enoughMaterial;
+    bool isCheck, enoughMaterial, moveIsCheck;
     const TTEntry* tte = NULL;
     int moveCount = 0;
     bool pvNode = (beta - alpha != 1);
@@ -1602,12 +1602,14 @@ namespace {
       moveCount++;
       ss[ply].currentMove = move;
 
+      moveIsCheck = pos.move_is_check(move, ci);
+
       // Futility pruning
       if (   enoughMaterial
           && !isCheck
           && !pvNode
+          && !moveIsCheck
           && !move_is_promotion(move)
-          && !pos.move_is_check(move, ci)
           && !pos.move_is_passed_pawn_push(move))
       {
           futilityValue =  staticValue
@@ -1633,7 +1635,7 @@ namespace {
           continue;
 
       // Make and search the move
-      pos.do_move(move, st, ci.dcCandidates);
+      pos.do_move(move, st, ci.dcCandidates, moveIsCheck);
       value = -qsearch(pos, ss, -beta, -alpha, depth-OnePly, ply+1, threadID);
       pos.undo_move(move);
 
@@ -1760,7 +1762,7 @@ namespace {
 
       // Make and search the move.
       StateInfo st;
-      pos.do_move(move, st, sp->dcCandidates);
+      pos.do_move(move, st, sp->dcCandidates, 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.
@@ -1866,7 +1868,7 @@ namespace {
 
       // Make and search the move.
       StateInfo st;
-      pos.do_move(move, st, sp->dcCandidates);
+      pos.do_move(move, st, sp->dcCandidates, 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.