Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak time management #142

Merged
merged 5 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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