- Value rBeta = bestValue - 2 * PawnValueMg;
- ss->excludedMove = RootMoves[0].pv[0];
- ss->skipNullMove = true;
- Value v = search<NonPV>(pos, ss, rBeta - 1, rBeta, (depth - 3) * ONE_PLY, true);
- ss->skipNullMove = false;
- ss->excludedMove = MOVE_NONE;
-
- if (v < rBeta)
- stop = true;
+ // Take some extra time if the best move has changed
+ if (depth > 4 * ONE_PLY && multiPV == 1)
+ Time.pv_instability(BestMoveChanges);
+
+ // Stop the search if only one legal move is available or all
+ // of the available time has been used or we matched an easyMove
+ // from the previous search and just did a fast verification.
+ if ( RootMoves.size() == 1
+ || Time.elapsed() > Time.available()
+ || ( RootMoves[0].pv[0] == easyMove
+ && BestMoveChanges < 0.03
+ && Time.elapsed() > Time.available() / 10))
+ {
+ // If we are allowed to ponder do not stop the search now but
+ // keep pondering until the GUI sends "ponderhit" or "stop".
+ if (Limits.ponder)
+ Signals.stopOnPonderhit = true;
+ else
+ Signals.stop = true;
+ }