- // Loop through all the moves in the root move list:
- for(int i = 0; i < rml.move_count() && !AbortSearch; i++) {
- int64_t nodes;
- Move move;
- UndoInfo u;
- Depth ext, newDepth;
-
- RootMoveNumber = i + 1;
- FailHigh = false;
-
- // Remember the node count before the move is searched. The node counts
- // are used to sort the root moves at the next iteration.
- nodes = nodes_searched();
-
- // Pick the next root move, and print the move and the move number to
- // the standard output:
- move = ss[0].currentMove = rml.get_move(i);
- if(current_search_time() >= 1000)
- std::cout << "info currmove " << move
- << " currmovenumber " << i + 1 << std::endl;
-
- // Decide search depth for this move:
- ext = extension(pos, move, true, pos.move_is_check(move), false, false);
- newDepth = (Iteration-2)*OnePly + ext + InitialDepth;
-
- // Make the move, and search it.
- pos.do_move(move, u, dcCandidates);
-
- if(i < MultiPV) {
- value = -search_pv(pos, ss, -beta, VALUE_INFINITE, newDepth, 1, 0);
- // If the value has dropped a lot compared to the last iteration,
- // set the boolean variable Problem to true. This variable is used
- // for time managment: When Problem is true, we try to complete the
- // current iteration before playing a move.
- Problem = (Iteration >= 2 &&
- value <= ValueByIteration[Iteration-1] - ProblemMargin);
- if(Problem && StopOnPonderhit)
- StopOnPonderhit = false;
- }
- else {
- value = -search(pos, ss, -alpha, newDepth, 1, true, 0);
- if(value > alpha) {
- // Fail high! Set the boolean variable FailHigh to true, and
- // re-search the move with a big window. The variable FailHigh is
- // used for time managment: We try to avoid aborting the search
- // prematurely during a fail high research.
- FailHigh = true;
- value = -search_pv(pos, ss, -beta, -alpha, newDepth, 1, 0);
+ // Loop through all the moves in the root move list
+ for (int i = 0; i < rml.move_count() && !AbortSearch; i++)
+ {
+ if (alpha >= beta)
+ {
+ // We failed high, invalidate and skip next moves, leave node-counters
+ // and beta-counters as they are and quickly return, we will try to do
+ // a research at the next iteration with a bigger aspiration window.
+ rml.set_move_score(i, -VALUE_INFINITE);
+ continue;
+ }
+ int64_t nodes;
+ Move move;
+ StateInfo st;
+ Depth ext, newDepth;
+
+ RootMoveNumber = i + 1;
+ FailHigh = false;
+
+ // Remember the node count before the move is searched. The node counts
+ // are used to sort the root moves at the next iteration.
+ nodes = nodes_searched();
+
+ // Reset beta cut-off counters
+ BetaCounter.clear();
+
+ // Pick the next root move, and print the move and the move number to
+ // the standard output.
+ move = ss[0].currentMove = rml.get_move(i);
+ if (current_search_time() >= 1000)
+ std::cout << "info currmove " << move
+ << " currmovenumber " << i + 1 << std::endl;
+
+ // Decide search depth for this move
+ bool dangerous;
+ ext = extension(pos, move, true, pos.move_is_capture(move), pos.move_is_check(move), false, false, &dangerous);
+ newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
+
+ // Make the move, and search it
+ pos.do_move(move, st, dcCandidates);
+
+ if (i < MultiPV)
+ {
+ // Aspiration window is disabled in multi-pv case
+ if (MultiPV > 1)
+ alpha = -VALUE_INFINITE;
+
+ value = -search_pv(pos, ss, -beta, -alpha, newDepth, 1, 0);
+ // If the value has dropped a lot compared to the last iteration,
+ // set the boolean variable Problem to true. This variable is used
+ // for time managment: When Problem is true, we try to complete the
+ // current iteration before playing a move.
+ Problem = (Iteration >= 2 && value <= IterationInfo[Iteration-1].value - ProblemMargin);
+
+ if (Problem && StopOnPonderhit)
+ StopOnPonderhit = false;
+ }
+ else
+ {
+ value = -search(pos, ss, -alpha, newDepth, 1, true, 0);
+ if (value > alpha)
+ {
+ // Fail high! Set the boolean variable FailHigh to true, and
+ // re-search the move with a big window. The variable FailHigh is
+ // used for time managment: We try to avoid aborting the search
+ // prematurely during a fail high research.
+ FailHigh = true;
+ value = -search_pv(pos, ss, -beta, -alpha, newDepth, 1, 0);
+ }