goto finalize;
}
- if (Options["OwnBook"] && !Limits.infinite)
+ if (Options["OwnBook"] && !Limits.infinite && !Limits.mate)
{
Move bookMove = book.probe(RootPos, Options["Book File"], Options["Best Book Move"]);
if (depth > 2 && BestMoveChanges)
bestMoveNeverChanged = false;
+ // Do we have found a "mate in x"?
+ if ( Limits.mate
+ && bestValue >= VALUE_MATE_IN_MAX_PLY
+ && VALUE_MATE - bestValue <= 2 * Limits.mate)
+ Signals.stop = true;
+
// Do we have time for the next iteration? Can we stop searching now?
if (Limits.use_time_management() && !Signals.stopOnPonderhit)
{
ss->staticEval, ss->evalMargin);
}
+ // Handling of UCI command 'mate in x moves'. We simply return if after
+ // 'x' moves we still have not checkmated the opponent.
+ if (PvNode && !RootNode && !inCheck && Limits.mate && ss->ply > 2 * Limits.mate)
+ return eval;
+
// Update gain for the parent non-capture move given the static position
// evaluation before and after the move.
if ( (move = (ss-1)->currentMove) != MOVE_NULL
struct LimitsType {
LimitsType() { memset(this, 0, sizeof(LimitsType)); }
- bool use_time_management() const { return !(movetime | depth | nodes | infinite); }
+ bool use_time_management() const { return !(mate | movetime | depth | nodes | infinite); }
- int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, infinite, ponder;
+ int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder;
};
else if (token == "depth") is >> limits.depth;
else if (token == "nodes") is >> limits.nodes;
else if (token == "movetime") is >> limits.movetime;
+ else if (token == "mate") is >> limits.mate;
else if (token == "infinite") limits.infinite = true;
else if (token == "ponder") limits.ponder = true;
}