@@ -368,6 +368,7 @@ void Thread::search() {
368368
369369 size_t pvFirst = 0 ;
370370 pvLast = 0 ;
371+ Depth adjustedDepth = rootDepth;
371372
372373 // MultiPV loop. We perform a full root search for each PV line
373374 for (pvIdx = 0 ; pvIdx < multiPV && !Threads.stop ; ++pvIdx)
@@ -401,9 +402,11 @@ void Thread::search() {
401402 // Start with a small aspiration window and, in the case of a fail
402403 // high/low, re-search with a bigger window until we don't fail
403404 // high/low anymore.
405+ int failedHighCnt = 0 ;
404406 while (true )
405407 {
406- bestValue = ::search<PV>(rootPos, ss, alpha, beta, rootDepth, false );
408+ adjustedDepth = std::max (ONE_PLY, rootDepth - failedHighCnt * ONE_PLY);
409+ bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false );
407410
408411 // Bring the best move to the front. It is critical that sorting
409412 // is done with a stable algorithm because all the values but the
@@ -425,7 +428,7 @@ void Thread::search() {
425428 && multiPV == 1
426429 && (bestValue <= alpha || bestValue >= beta)
427430 && Time.elapsed () > 3000 )
428- sync_cout << UCI::pv (rootPos, rootDepth , alpha, beta) << sync_endl;
431+ sync_cout << UCI::pv (rootPos, adjustedDepth , alpha, beta) << sync_endl;
429432
430433 // In case of failing low/high increase aspiration window and
431434 // re-search, otherwise exit the loop.
@@ -436,12 +439,17 @@ void Thread::search() {
436439
437440 if (mainThread)
438441 {
442+ failedHighCnt = 0 ;
439443 failedLow = true ;
440444 Threads.stopOnPonderhit = false ;
441445 }
442446 }
443447 else if (bestValue >= beta)
448+ {
444449 beta = std::min (bestValue + delta, VALUE_INFINITE);
450+ if (mainThread)
451+ ++failedHighCnt;
452+ }
445453 else
446454 break ;
447455
@@ -455,15 +463,15 @@ void Thread::search() {
455463
456464 if ( mainThread
457465 && (Threads.stop || pvIdx + 1 == multiPV || Time.elapsed () > 3000 ))
458- sync_cout << UCI::pv (rootPos, rootDepth , alpha, beta) << sync_endl;
466+ sync_cout << UCI::pv (rootPos, adjustedDepth , alpha, beta) << sync_endl;
459467 }
460468
461469 if (!Threads.stop )
462- completedDepth = rootDepth ;
470+ completedDepth = adjustedDepth ;
463471
464472 if (rootMoves[0 ].pv [0 ] != lastBestMove) {
465473 lastBestMove = rootMoves[0 ].pv [0 ];
466- lastBestMoveDepth = rootDepth ;
474+ lastBestMoveDepth = adjustedDepth ;
467475 }
468476
469477 // Have we found a "mate in x"?
0 commit comments