]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Use CheckInfo to store pinned bitboard
[stockfish] / src / search.cpp
index 1ffab9d3f16055b5227317e2340c56861c6d7383..2e12f82e2a44ff16b3c31a6fc75afb97e715db5d 100644 (file)
@@ -717,7 +717,6 @@ namespace {
     StateInfo st;
     const TTEntry *tte;
     Key posKey;
-    Bitboard pinned;
     Move ttMove, move, excludedMove, threatMove;
     Depth ext, newDepth;
     ValueType vt;
@@ -764,10 +763,13 @@ namespace {
         return VALUE_DRAW;
 
     // Step 3. Mate distance pruning
-    alpha = Max(value_mated_in(ss->ply), alpha);
-    beta = Min(value_mate_in(ss->ply+1), beta);
-    if (alpha >= beta)
-        return alpha;
+    if (!RootNode)
+    {
+        alpha = Max(value_mated_in(ss->ply), alpha);
+        beta = Min(value_mate_in(ss->ply+1), beta);
+        if (alpha >= beta)
+            return alpha;
+    }
 
     // Step 4. Transposition table lookup
     // We don't want the score of a partial search to overwrite a previous full search
@@ -915,12 +917,12 @@ namespace {
         assert(rdepth >= ONE_PLY);
 
         MovePicker mp(pos, ttMove, H, Position::see_value(pos.captured_piece_type()));
-        pinned = pos.pinned_pieces(pos.side_to_move());
+        CheckInfo ci(pos);
 
         while ((move = mp.get_next_move()) != MOVE_NONE)
-            if (pos.pl_move_is_legal(move, pinned))
+            if (pos.pl_move_is_legal(move, ci.pinned))
             {
-                pos.do_move(move, st);
+                pos.do_move(move, st, ci, pos.move_gives_check(move, ci));
                 value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth);
                 pos.undo_move(move);
                 if (value >= rbeta)
@@ -948,7 +950,6 @@ split_point_start: // At split points actual search starts from here
     // Initialize a MovePicker object for the current position
     MovePickerExt<NT> mp(pos, ttMove, depth, H, ss, PvNode ? -VALUE_INFINITE : beta);
     CheckInfo ci(pos);
-    pinned = pos.pinned_pieces(pos.side_to_move());
     ss->bestMove = MOVE_NONE;
     futilityBase = ss->eval + ss->evalMargin;
     singularExtensionNode =   !RootNode
@@ -976,7 +977,7 @@ split_point_start: // At split points actual search starts from here
           continue;
 
       // At PV and SpNode nodes we want the moves to be legal
-      if ((PvNode || SpNode) && !pos.pl_move_is_legal(move, pinned))
+      if ((PvNode || SpNode) && !pos.pl_move_is_legal(move, ci.pinned))
           continue;
 
       if (SpNode)
@@ -1009,7 +1010,7 @@ split_point_start: // At split points actual search starts from here
       }
 
       // At Root and at first iteration do a PV search on all the moves to score root moves
-      isPvMove = (PvNode && moveCount <= (RootNode ? depth <= ONE_PLY ? 1000 : MultiPV : 1));
+      isPvMove = (PvNode && moveCount <= (RootNode ? depth <= ONE_PLY ? MAX_MOVES : MultiPV : 1));
       givesCheck = pos.move_gives_check(move, ci);
       captureOrPromotion = pos.move_is_capture(move) || move_is_promotion(move);
 
@@ -1023,7 +1024,7 @@ split_point_start: // At split points actual search starts from here
       // a margin then we extend ttMove.
       if (   singularExtensionNode
           && move == ttMove
-          && pos.pl_move_is_legal(move, pinned)
+          && pos.pl_move_is_legal(move, ci.pinned)
           && ext < ONE_PLY)
       {
           Value ttValue = value_from_tt(tte->value(), ss->ply);
@@ -1098,7 +1099,7 @@ split_point_start: // At split points actual search starts from here
       }
 
       // Check for legality only before to do the move
-      if (!pos.pl_move_is_legal(move, pinned))
+      if (!pos.pl_move_is_legal(move, ci.pinned))
       {
           moveCount--;
           continue;
@@ -1115,14 +1116,8 @@ split_point_start: // At split points actual search starts from here
       // Step extra. pv search (only in PV nodes)
       // The first move in list is the expected PV
       if (isPvMove)
-      {
-          // Aspiration window is disabled in multi-pv case
-          if (RootNode && MultiPV > 1)
-              alpha = -VALUE_INFINITE;
-
           value = newDepth < ONE_PLY ? -qsearch<PV>(pos, ss+1, -beta, -alpha, DEPTH_ZERO)
                                      : - search<PV>(pos, ss+1, -beta, -alpha, newDepth);
-      }
       else
       {
           // Step 15. Reduced depth search
@@ -1398,7 +1393,6 @@ split_point_start: // At split points actual search starts from here
     // be generated.
     MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove));
     CheckInfo ci(pos);
-    Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
 
     // Loop through the moves until no moves remain or a beta cutoff occurs
     while (   alpha < beta
@@ -1467,7 +1461,7 @@ split_point_start: // At split points actual search starts from here
       }
 
       // Check for legality only before to do the move
-      if (!pos.pl_move_is_legal(move, pinned))
+      if (!pos.pl_move_is_legal(move, ci.pinned))
           continue;
 
       // Update current move