@@ -597,7 +597,7 @@ namespace {
597597 Move ttMove, move, excludedMove, bestMove;
598598 Depth extension, newDepth;
599599 Value bestValue, value, ttValue, eval, maxValue, probCutBeta;
600- bool ttHit, ttPv, formerPv, givesCheck, improving, didLMR, priorCapture;
600+ bool ttHit, formerPv, givesCheck, improving, didLMR, priorCapture;
601601 bool captureOrPromotion, doFullDepthSearch, moveCountPruning,
602602 ttCapture, singularQuietLMR;
603603 Piece movedPiece;
@@ -644,6 +644,7 @@ namespace {
644644 assert (0 <= ss->ply && ss->ply < MAX_PLY);
645645
646646 (ss+1 )->ply = ss->ply + 1 ;
647+ (ss+1 )->ttPv = false ;
647648 (ss+1 )->excludedMove = bestMove = MOVE_NONE;
648649 (ss+2 )->killers [0 ] = (ss+2 )->killers [1 ] = MOVE_NONE;
649650 Square prevSq = to_sq ((ss-1 )->currentMove );
@@ -667,10 +668,11 @@ namespace {
667668 ttValue = ttHit ? value_from_tt (tte->value (), ss->ply , pos.rule50_count ()) : VALUE_NONE;
668669 ttMove = rootNode ? thisThread->rootMoves [thisThread->pvIdx ].pv [0 ]
669670 : ttHit ? tte->move () : MOVE_NONE;
670- ttPv = PvNode || (ttHit && tte->is_pv ());
671- formerPv = ttPv && !PvNode;
671+ if (!excludedMove)
672+ ss->ttPv = PvNode || (ttHit && tte->is_pv ());
673+ formerPv = ss->ttPv && !PvNode;
672674
673- if ( ttPv
675+ if ( ss-> ttPv
674676 && depth > 12
675677 && ss->ply - 1 < MAX_LPH
676678 && !priorCapture
@@ -748,7 +750,7 @@ namespace {
748750 if ( b == BOUND_EXACT
749751 || (b == BOUND_LOWER ? value >= beta : value <= alpha))
750752 {
751- tte->save (posKey, value_to_tt (value, ss->ply ), ttPv, b,
753+ tte->save (posKey, value_to_tt (value, ss->ply ), ss-> ttPv , b,
752754 std::min (MAX_PLY - 1 , depth + 6 ),
753755 MOVE_NONE, VALUE_NONE);
754756
@@ -798,7 +800,7 @@ namespace {
798800 else
799801 ss->staticEval = eval = -(ss-1 )->staticEval + 2 * Tempo;
800802
801- tte->save (posKey, VALUE_NONE, ttPv, BOUND_NONE, DEPTH_NONE, MOVE_NONE, eval);
803+ tte->save (posKey, VALUE_NONE, ss-> ttPv , BOUND_NONE, DEPTH_NONE, MOVE_NONE, eval);
802804 }
803805
804806 // Step 7. Razoring (~1 Elo)
@@ -824,7 +826,7 @@ namespace {
824826 && (ss-1 )->statScore < 22977
825827 && eval >= beta
826828 && eval >= ss->staticEval
827- && ss->staticEval >= beta - 30 * depth - 28 * improving + 84 * ttPv + 182
829+ && ss->staticEval >= beta - 30 * depth - 28 * improving + 84 * ss-> ttPv + 182
828830 && !excludedMove
829831 && pos.non_pawn_material (us)
830832 && (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor ))
@@ -898,6 +900,8 @@ namespace {
898900 assert (probCutBeta < VALUE_INFINITE);
899901 MovePicker mp (pos, ttMove, probCutBeta - ss->staticEval , &captureHistory);
900902 int probCutCount = 0 ;
903+ bool ttPv = ss->ttPv ;
904+ ss->ttPv = false ;
901905
902906 while ( (move = mp.next_move ()) != MOVE_NONE
903907 && probCutCount < 2 + 2 * cutNode)
@@ -938,6 +942,7 @@ namespace {
938942 return value;
939943 }
940944 }
945+ ss->ttPv = ttPv;
941946 }
942947
943948 // Step 11. If the position is not in TT, decrease depth by 2
@@ -1180,7 +1185,7 @@ namespace {
11801185 r++;
11811186
11821187 // Decrease reduction if position is or has been on the PV (~10 Elo)
1183- if (ttPv)
1188+ if (ss-> ttPv )
11841189 r -= 2 ;
11851190
11861191 if (moveCountPruning && !formerPv)
@@ -1209,7 +1214,7 @@ namespace {
12091214 // hence break make_move(). (~2 Elo)
12101215 else if ( type_of (move) == NORMAL
12111216 && !pos.see_ge (reverse_move (move)))
1212- r -= 2 + ttPv - (type_of (movedPiece) == PAWN);
1217+ r -= 2 + ss-> ttPv - (type_of (movedPiece) == PAWN);
12131218
12141219 ss->statScore = thisThread->mainHistory [us][from_to (move)]
12151220 + (*contHist[0 ])[movedPiece][to_sq (move)]
@@ -1387,8 +1392,17 @@ namespace {
13871392 if (PvNode)
13881393 bestValue = std::min (bestValue, maxValue);
13891394
1395+ // If no good move is found and the previous position was ttPv, then the previous
1396+ // opponent move is probably good and the new position is added to the search tree.
1397+ if (bestValue <= alpha)
1398+ ss->ttPv = ss->ttPv || ((ss-1 )->ttPv && depth > 3 );
1399+ // Otherwise, a counter move has been found and if the position is the last leaf
1400+ // in the search tree, remove the position from the search tree.
1401+ else if (depth > 3 )
1402+ ss->ttPv = ss->ttPv && (ss+1 )->ttPv ;
1403+
13901404 if (!excludedMove && !(rootNode && thisThread->pvIdx ))
1391- tte->save (posKey, value_to_tt (bestValue, ss->ply ), ttPv,
1405+ tte->save (posKey, value_to_tt (bestValue, ss->ply ), ss-> ttPv ,
13921406 bestValue >= beta ? BOUND_LOWER :
13931407 PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
13941408 depth, bestMove, ss->staticEval );
0 commit comments