]> git.sesse.net Git - stockfish/commitdiff
Delay checking for duplicated killer moves
authorMarco Costalba <mcostalba@gmail.com>
Sun, 1 Feb 2015 12:08:14 +0000 (13:08 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 1 Feb 2015 12:17:42 +0000 (13:17 +0100)
Follow the usual approach to delay computation
as far as possible, in case an earlier killer
cut-offs we avoid to do useless work.

This also greatly simplifies the code.

No functional change.

src/movepick.cpp

index 1f4ef1952d0a0c469ba654f31512c3c3966e7712..69d848d27564a0680e2c97d7baf97f02ef401dda 100644 (file)
@@ -201,28 +201,13 @@ void MovePicker::generate_next_stage() {
 
   case KILLERS_S1:
       cur = killers;
-      endMoves = cur + 2;
-
+      endMoves = cur + 6;
       killers[0].move = ss->killers[0];
       killers[1].move = ss->killers[1];
-      killers[2].move = killers[3].move = MOVE_NONE;
-      killers[4].move = killers[5].move = MOVE_NONE;
-
-      // In SMP case countermoves[] and followupmoves[] could have duplicated entries
-      // in rare cases (less than 1 out of a million). This is harmless.
-
-      // Be sure countermoves and followupmoves are different from killers
-      for (int i = 0; i < 2; ++i)
-          if (   countermoves[i] != killers[0].move
-              && countermoves[i] != killers[1].move)
-              (endMoves++)->move = countermoves[i];
-
-      for (int i = 0; i < 2; ++i)
-          if (   followupmoves[i] != killers[0].move
-              && followupmoves[i] != killers[1].move
-              && followupmoves[i] != killers[2].move
-              && followupmoves[i] != killers[3].move)
-              (endMoves++)->move = followupmoves[i];
+      killers[2].move = countermoves[0];
+      killers[3].move = countermoves[1];
+      killers[4].move = followupmoves[0];
+      killers[5].move = followupmoves[1];
       break;
 
   case QUIETS_1_S1:
@@ -307,18 +292,25 @@ Move MovePicker::next_move<false>() {
               &&  move != ttMove
               &&  pos.pseudo_legal(move)
               && !pos.capture(move))
+          {
+              // Check for duplicated entries
+              for (int i = 0; i < cur - 1 - killers; i++)
+                  if (move == killers[i])
+                      goto skip;
               return move;
+          }
+      skip:
           break;
 
       case QUIETS_1_S1: case QUIETS_2_S1:
           move = *cur++;
           if (   move != ttMove
-              && move != killers[0].move
-              && move != killers[1].move
-              && move != killers[2].move
-              && move != killers[3].move
-              && move != killers[4].move
-              && move != killers[5].move)
+              && move != killers[0]
+              && move != killers[1]
+              && move != killers[2]
+              && move != killers[3]
+              && move != killers[4]
+              && move != killers[5])
               return move;
           break;