Skip to content

Commit

Permalink
Tweak time management (#142)
Browse files Browse the repository at this point in the history
Adds a minimum thinking time of 10ms, lowers move overhead to 30ms from 50, switches to using elapsed time rather than fixed points in time to check for timeout, and changes the OutOfTime logic to not check for timeout at 0 nodes as aborting a search at that point is nonsensical.

ELO   | 5.44 +- 4.25 (95%)
SPRT  | 10.0+0.1s Threads=1 Hash=32MB
LLR   | 3.00 (-2.94, 2.94) [0.00, 5.00]
Games | N: 15765 W: 4969 L: 4722 D: 6074
http://chess.grantnet.us/viewTest/4359/

ELO   | 6.61 +- 5.74 (95%)
SPRT  | 60.0+0.6s Threads=1 Hash=128MB
LLR   | 2.96 (-2.94, 2.94) [-2.50, 2.50]
Games | N: 7304 W: 1970 L: 1831 D: 3503
http://chess.grantnet.us/viewTest/4362/
  • Loading branch information
TerjeKir authored Jan 19, 2020
1 parent f7c531a commit 43a3c6c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ CONSTR InitReductions() {
// Check time situation
static bool OutOfTime(SearchInfo *info) {

if ( (info->nodes & 8192) == 0
if ( (info->nodes & 8191) == 8191
&& limits.timelimit
&& Now() >= limits.stop)
&& TimeSince(limits.start) >= limits.maxUsage)

return true;

Expand Down Expand Up @@ -497,7 +497,8 @@ static int AspirationWindow(Position *pos, SearchInfo *info) {
// Decides when to stop a search
static void InitTimeManagement() {

const int overhead = 50;
const int overhead = 30;
const int minTime = 10;

// Default to spending 1/30 of remaining time
if (limits.movestogo == 0)
Expand All @@ -514,11 +515,9 @@ static void InitTimeManagement() {

// Calculate how much time to use if given time constraints
if (limits.time) {
int timeThisMove = MIN(limits.time, (limits.time / limits.movestogo) + 2 * limits.inc);
int timeThisMove = MIN(limits.time, (limits.time / limits.movestogo) + 1.5 * limits.inc) - overhead;

limits.stop = limits.start
+ timeThisMove
- overhead;
limits.maxUsage = MAX(minTime, timeThisMove);

limits.timelimit = true;
} else
Expand Down
4 changes: 4 additions & 0 deletions src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ int Now() {
clock_gettime(CLOCK_MONOTONIC, &t);
return t.tv_sec * 1000 + t.tv_nsec / 1000000;
#endif
}

int TimeSince(const int time) {
return Now() - time;
}
3 changes: 2 additions & 1 deletion src/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#pragma once


int Now();
int Now();
int TimeSince(const int time);
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ typedef struct {

typedef struct {

int start, time, inc, movestogo, movetime, depth, stop;
int start, time, inc, movestogo, movetime, depth, maxUsage;
bool timelimit;

} SearchLimits;
Expand Down

0 comments on commit 43a3c6c

Please sign in to comment.