Skip to content

Commit

Permalink
Support 'go mate x' (#370)
Browse files Browse the repository at this point in the history
Also works for getting mated in x. Can fail if Weiss thinks it's getting mated in x or fewer moves, when it should be a mating in x, but this should be extremely rare, if at all possible.

No impact on playing strength.
  • Loading branch information
TerjeKir authored Oct 17, 2020
1 parent e6bfd04 commit a56b467
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ static void *IterativeDeepening(void *voidThread) {
// Only the main thread concerns itself with the rest
if (!mainThread) continue;

// Stop searching after finding a short enough mate
if (MATE - abs(thread->score) <= 2 * Limits.mate) break;

bool uncertain = ss->pv.line[0] != thread->bestMove;

// Save bestMove and ponderMove before overwriting the pv next iteration
Expand Down
1 change: 1 addition & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
TimePoint start;
int time, inc, movestogo, movetime, depth;
int optimalUsage, maxUsage;
int mate;
bool timelimit, infinite;

} SearchLimits;
Expand Down
1 change: 1 addition & 0 deletions src/uci.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void ParseTimeControl(char *str, Color color) {
SetLimit(str, "movestogo", &Limits.movestogo);
SetLimit(str, "movetime", &Limits.movetime);
SetLimit(str, "depth", &Limits.depth);
SetLimit(str, "mate", &Limits.mate);

Limits.timelimit = Limits.time || Limits.movetime;

Expand Down

0 comments on commit a56b467

Please sign in to comment.