]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Move legal check out of MovePicker
[stockfish] / src / search.cpp
index 2fdd2840ea2b38915c453baf46783cc097909b35..94eb6155bf756bfc8f938b43cbd038947bd9ff75 100644 (file)
@@ -880,6 +880,7 @@ split_point_start: // At split points actual search starts from here
     // Initialize a MovePicker object for the current position
     MovePickerExt<SpNode, Root> mp(pos, ttMove, depth, H, ss, (PvNode ? -VALUE_INFINITE : beta));
     CheckInfo ci(pos);
+    Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
     ss->bestMove = MOVE_NONE;
     futilityBase = ss->eval + ss->evalMargin;
     singularExtensionNode =   !Root
@@ -908,7 +909,7 @@ split_point_start: // At split points actual search starts from here
           moveCount = ++sp->moveCount;
           lock_release(&(sp->lock));
       }
-      else if (move == excludedMove)
+      else if (move == excludedMove || !pos.pl_move_is_legal(move, pinned))
           continue;
       else
           moveCount++;
@@ -1325,6 +1326,7 @@ split_point_start: // At split points actual search starts from here
     // be generated.
     MovePicker mp(pos, ttMove, depth, H);
     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
@@ -1332,6 +1334,9 @@ split_point_start: // At split points actual search starts from here
     {
       assert(move_is_ok(move));
 
+      if (!pos.pl_move_is_legal(move, pinned))
+          continue;
+
       givesCheck = pos.move_gives_check(move, ci);
 
       // Futility pruning
@@ -1979,13 +1984,16 @@ split_point_start: // At split points actual search starts from here
     TTEntry* tte;
     int ply = 1;
 
-    assert(pv[0] != MOVE_NONE && pos.move_is_legal(pv[0]));
+    assert(pv[0] != MOVE_NONE && pos.move_is_pl(pv[0]));
 
     pos.do_move(pv[0], *st++);
 
+    Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
+
     while (   (tte = TT.probe(pos.get_key())) != NULL
            && tte->move() != MOVE_NONE
-           && pos.move_is_legal(tte->move())
+           && pos.move_is_pl(tte->move())
+           && pos.pl_move_is_legal(tte->move(), pinned)
            && ply < PLY_MAX
            && (!pos.is_draw() || ply < 2))
     {
@@ -2009,7 +2017,7 @@ split_point_start: // At split points actual search starts from here
     Value v, m = VALUE_NONE;
     int ply = 0;
 
-    assert(pv[0] != MOVE_NONE && pos.move_is_legal(pv[0]));
+    assert(pv[0] != MOVE_NONE && pos.move_is_pl(pv[0]));
 
     do {
         k = pos.get_key();