volatile SignalsType Signals;
LimitsType Limits;
- std::vector<Move> SearchMoves;
+ std::set<Move> SearchMoves;
Position RootPosition;
}
static Book book; // Defined static to initialize the PRNG only once
+ Move bm;
Position& pos = RootPosition;
Chess960 = pos.is_chess960();
elapsed_time(true);
// Populate RootMoves with all the legal moves (default) or, if a SearchMoves
// is given, with the subset of legal moves to search.
for (MoveList<MV_LEGAL> ml(pos); !ml.end(); ++ml)
- if (SearchMoves.empty() || count(SearchMoves.begin(), SearchMoves.end(), ml.move()))
+ if (SearchMoves.empty() || SearchMoves.count(ml.move()))
RootMoves.push_back(RootMove(ml.move()));
- if (Options["OwnBook"])
+ if (RootMoves.empty())
{
- Move bookMove = book.probe(pos, Options["Book File"], Options["Best Book Move"]);
+ cout << "info depth 0 score "
+ << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl;
- if (bookMove && count(RootMoves.begin(), RootMoves.end(), bookMove))
- {
- std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), bookMove));
- goto finalize;
- }
+ RootMoves.push_back(MOVE_NONE);
+ goto finalize;
+ }
+
+ if ( Options["OwnBook"]
+ && (bm = book.probe(pos, Options["Book File"], Options["Best Book Move"])) != MOVE_NONE
+ && count(RootMoves.begin(), RootMoves.end(), bm))
+ {
+ std::swap(RootMoves[0], *find(RootMoves.begin(), RootMoves.end(), bm));
+ goto finalize;
}
// Read UCI options: GUI could change UCI parameters during the game
finalize:
- // When we reach max depth we arrive here even without a StopRequest, but if
- // we are pondering or in infinite search, we shouldn't print the best move
- // before we are told to do so.
+ // When we reach max depth we arrive here even without Signals.stop is raised,
+ // but if we are pondering or in infinite search, we shouldn't print the best
+ // move before we are told to do so.
if (!Signals.stop && (Limits.ponder || Limits.infinite))
Threads.wait_for_stop_or_ponderhit();
bestValue = delta = -VALUE_INFINITE;
ss->currentMove = MOVE_NULL; // Hack to skip update gains
- // Handle the special case of a mated/stalemate position
- if (RootMoves.empty())
- {
- cout << "info depth 0 score "
- << score_to_uci(pos.in_check() ? -VALUE_MATE : VALUE_DRAW) << endl;
-
- RootMoves.push_back(MOVE_NONE);
- return;
- }
-
// Iterative deepening loop until requested to stop or target depth reached
while (!Signals.stop && ++depth <= MAX_PLY && (!Limits.maxDepth || depth <= Limits.maxDepth))
{
stop = true;
// Stop search early if one move seems to be much better than others
- if ( depth >= 10
+ if ( depth >= 12
&& !stop
- && ( bestMoveNeverChanged
+ && ( (bestMoveNeverChanged && pos.captured_piece_type())
|| elapsed_time() > (TimeMgr.available_time() * 40) / 100))
{
Value rBeta = bestValue - EasyMoveMargin;
(ss+1)->excludedMove = RootMoves[0].pv[0];
(ss+1)->skipNullMove = true;
- Value v = search<NonPV>(pos, ss+1, rBeta - 1, rBeta, (depth * ONE_PLY) / 2);
+ Value v = search<NonPV>(pos, ss+1, rBeta - 1, rBeta, (depth - 3) * ONE_PLY);
(ss+1)->skipNullMove = false;
(ss+1)->excludedMove = MOVE_NONE;
if ( (move = (ss-1)->currentMove) != MOVE_NULL
&& (ss-1)->eval != VALUE_NONE
&& ss->eval != VALUE_NONE
- && pos.captured_piece_type() == NO_PIECE_TYPE
+ && !pos.captured_piece_type()
&& !is_special(move))
{
Square to = to_sq(move);