- if (moveIsCapture)
- ss[ply].currentMoveCaptureValue =
- move_is_ep(move)? PawnValueMidgame : pos.midgame_value_of_piece_on(move_to(move));
- else
- ss[ply].currentMoveCaptureValue = Value(0);
-
- // Decide the new search depth
- bool dangerous;
- Depth ext = extension(pos, move, true, moveIsCapture, moveIsCheck, singleReply, mateThreat, &dangerous);
- Depth newDepth = depth - OnePly + ext;
-
- // Make and search the move
- StateInfo st;
- pos.do_move(move, st, dcCandidates);
-
- if (moveCount == 1) // The first move in list is the PV
- value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
- else
- {
- // Try to reduce non-pv search depth by one ply if move seems not problematic,
- // if the move fails high will be re-searched at full depth.
- if ( depth >= 2*OnePly
- && moveCount >= LMRPVMoves
- && !dangerous
- && !moveIsCapture
- && !move_promotion(move)
- && !move_is_castle(move)
- && !move_is_killer(move, ss[ply]))
- {
- ss[ply].reduction = OnePly;
- value = -search(pos, ss, -alpha, newDepth-OnePly, ply+1, true, threadID);
- }
- else
- value = alpha + 1; // Just to trigger next condition
-
- if (value > alpha) // Go with full depth non-pv search
- {
- ss[ply].reduction = Depth(0);
- value = -search(pos, ss, -alpha, newDepth, ply+1, true, threadID);
- if (value > alpha && value < beta)
- {
- // When the search fails high at ply 1 while searching the first
- // move at the root, set the flag failHighPly1. This is used for
- // time managment: We don't want to stop the search early in
- // such cases, because resolving the fail high at ply 1 could
- // result in a big drop in score at the root.
- if (ply == 1 && RootMoveNumber == 1)
- Threads[threadID].failHighPly1 = true;
-
- // A fail high occurred. Re-search at full window (pv search)
- value = -search_pv(pos, ss, -beta, -alpha, newDepth, ply+1, threadID);
- Threads[threadID].failHighPly1 = false;
- }
- }
- }
- pos.undo_move(move);
-
- assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
-
- // New best move?
- if (value > bestValue)
- {
- bestValue = value;
- if (value > alpha)
- {
- alpha = value;
- update_pv(ss, ply);
- if (value == value_mate_in(ply + 1))
- ss[ply].mateKiller = move;
- }
- // If we are at ply 1, and we are searching the first root move at
- // ply 0, set the 'Problem' variable if the score has dropped a lot
- // (from the computer's point of view) since the previous iteration:
- if ( ply == 1
- && Iteration >= 2
- && -value <= ValueByIteration[Iteration-1] - ProblemMargin)
- Problem = true;
- }