+ if (Root)
+ {
+ // Finished searching the move. If StopRequest is true, the search
+ // was aborted because the user interrupted the search or because we
+ // ran out of time. In this case, the return value of the search cannot
+ // be trusted, and we break out of the loop without updating the best
+ // move and/or PV.
+ if (StopRequest)
+ break;
+
+ // Remember searched nodes counts for this move
+ rm->nodes += pos.nodes_searched() - nodes;
+
+ // Step 17. Check for new best move
+ if (!isPvMove && value <= alpha)
+ rm->pv_score = -VALUE_INFINITE;
+ else
+ {
+ // PV move or new best move!
+
+ // Update PV
+ ss->bestMove = move;
+ rm->pv_score = value;
+ rm->extract_pv_from_tt(pos);
+
+ // We record how often the best move has been changed in each
+ // iteration. This information is used for time managment: When
+ // the best move changes frequently, we allocate some more time.
+ if (!isPvMove && MultiPV == 1)
+ BestMoveChangesByIteration[Iteration]++;
+
+ // Inform GUI that PV has changed, in case of multi-pv UCI protocol
+ // requires we send all the PV lines properly sorted.
+ Rml->sort_multipv(moveCount);
+
+ for (int j = 0; j < Min(MultiPV, (int)Rml->size()); j++)
+ cout << (*Rml)[j].pv_info_to_uci(pos, alpha, beta, j) << endl;
+
+ // Update alpha. In multi-pv we don't use aspiration window
+ if (MultiPV == 1)
+ {
+ // Raise alpha to setup proper non-pv search upper bound
+ if (value > alpha)
+ alpha = bestValue = value;
+ }
+ else // Set alpha equal to minimum score among the PV lines
+ alpha = bestValue = (*Rml)[Min(moveCount, MultiPV) - 1].pv_score; // FIXME why moveCount?
+
+ } // PV move or new best move
+
+ ++rm;
+ }
+