]> git.sesse.net Git - stockfish/commitdiff
Document mate distance pruning
authorMarco Costalba <mcostalba@gmail.com>
Tue, 27 Dec 2011 15:01:33 +0000 (16:01 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 27 Dec 2011 17:53:00 +0000 (18:53 +0100)
It is simple but somewhat tricky code that deserves
a bit of documentation. A bit of renaming while there.

No functional change.

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

index b10eec60216db7805cda791065e5a67f011d2440..653ef834418ae29881fbb252481245e347f890b9 100644 (file)
@@ -640,11 +640,16 @@ namespace {
          || ss->ply > PLY_MAX) && !RootNode)
         return VALUE_DRAW;
 
          || ss->ply > PLY_MAX) && !RootNode)
         return VALUE_DRAW;
 
-    // Step 3. Mate distance pruning
+    // Step 3. Mate distance pruning. Even if we mate at the next move our score
+    // would be at best mate_in(ss->ply+1), but if alpha is already bigger because
+    // a shorter mate was found upward in the tree then there is no need to search
+    // further, we will never beat current alpha. Same logic but with reversed signs
+    // applies also in the opposite condition of being mated instead of giving mate,
+    // in this case return a fail-high score.
     if (!RootNode)
     {
     if (!RootNode)
     {
-        alpha = std::max(value_mated_in(ss->ply), alpha);
-        beta = std::min(value_mate_in(ss->ply+1), beta);
+        alpha = std::max(mated_in(ss->ply), alpha);
+        beta = std::min(mate_in(ss->ply+1), beta);
         if (alpha >= beta)
             return alpha;
     }
         if (alpha >= beta)
             return alpha;
     }
@@ -1122,7 +1127,7 @@ split_point_start: // At split points actual search starts from here
     // harmless because return value is discarded anyhow in the parent nodes.
     // If we are in a singular extension search then return a fail low score.
     if (!moveCount)
     // harmless because return value is discarded anyhow in the parent nodes.
     // If we are in a singular extension search then return a fail low score.
     if (!moveCount)
-        return excludedMove ? oldAlpha : inCheck ? value_mated_in(ss->ply) : VALUE_DRAW;
+        return excludedMove ? oldAlpha : inCheck ? mated_in(ss->ply) : VALUE_DRAW;
 
     // If we have pruned all the moves without searching return a fail-low score
     if (bestValue == -VALUE_INFINITE)
 
     // If we have pruned all the moves without searching return a fail-low score
     if (bestValue == -VALUE_INFINITE)
@@ -1365,7 +1370,7 @@ split_point_start: // At split points actual search starts from here
     // All legal moves have been searched. A special case: If we're in check
     // and no legal moves were found, it is checkmate.
     if (inCheck && bestValue == -VALUE_INFINITE)
     // All legal moves have been searched. A special case: If we're in check
     // and no legal moves were found, it is checkmate.
     if (inCheck && bestValue == -VALUE_INFINITE)
-        return value_mated_in(ss->ply);
+        return mated_in(ss->ply);
 
     // Update transposition table
     move = bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove;
 
     // Update transposition table
     move = bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove;
index ff7cc76684b7b5eb17b7a4b6c3bafdde55df80df..fc42ea76535feaf4c4a1df5cd1f59e4f32c44b32 100644 (file)
@@ -391,11 +391,11 @@ extern const Value PieceValueMidgame[17];
 extern const Value PieceValueEndgame[17];
 extern int SquareDistance[64][64];
 
 extern const Value PieceValueEndgame[17];
 extern int SquareDistance[64][64];
 
-inline Value value_mate_in(int ply) {
+inline Value mate_in(int ply) {
   return VALUE_MATE - ply;
 }
 
   return VALUE_MATE - ply;
 }
 
-inline Value value_mated_in(int ply) {
+inline Value mated_in(int ply) {
   return -VALUE_MATE + ply;
 }
 
   return -VALUE_MATE + ply;
 }