Skip to content

Commit

Permalink
Fix 25 days bug.
Browse files Browse the repository at this point in the history
Prevent time in milliseconds from overflowing after about 25 days.
Example: http://talkchess.com/forum/viewtopic.php?p=747757#747757
  • Loading branch information
syzygy committed Jan 16, 2018
1 parent bc3b30f commit 54302a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/misc.h
Expand Up @@ -61,7 +61,7 @@ INLINE void prefetch2(void *addr)
prefetch((uint8_t *)addr + 64);
}

typedef uint64_t TimePoint; // A value in milliseconds
typedef int64_t TimePoint; // A value in milliseconds

INLINE TimePoint now() {
struct timeval tv;
Expand Down
6 changes: 3 additions & 3 deletions src/search.c
Expand Up @@ -792,7 +792,7 @@ static int pv_is_draw(Pos *pos)

static void check_time(void)
{
int elapsed = time_elapsed();
TimePoint elapsed = time_elapsed();

// An engine may not stop pondering until told so by the GUI
if (Limits.ponder)
Expand All @@ -810,7 +810,7 @@ static void check_time(void)

static void uci_print_pv(Pos *pos, Depth depth, Value alpha, Value beta)
{
int elapsed = time_elapsed() + 1;
TimePoint elapsed = time_elapsed() + 1;
RootMoves *rm = pos->rootMoves;
int PVIdx = pos->PVIdx;
int multiPV = min(option_value(OPT_MULTI_PV), rm->size);
Expand Down Expand Up @@ -852,7 +852,7 @@ static void uci_print_pv(Pos *pos, Depth depth, Value alpha, Value beta)
if (elapsed > 1000)
printf(" hashfull %d", tt_hashfull());

printf(" tbhits %"PRIu64" time %d pv", tbhits, elapsed);
printf(" tbhits %"PRIu64" time %"PRIi64" pv", tbhits, elapsed);

for (int idx = 0; idx < rm->move[i].pv_size; idx++)
printf(" %s", uci_move(buf, rm->move[i].pv[idx], is_chess960()));
Expand Down
5 changes: 3 additions & 2 deletions src/timeman.h
Expand Up @@ -42,9 +42,10 @@ void time_init(int us, int ply);
#define time_optimum() Time.optimumTime
#define time_maximum() Time.maximumTime

INLINE int time_elapsed(void)
INLINE TimePoint time_elapsed(void)
{
return Limits.npmsec ? threads_nodes_searched() : now() - Time.startTime;
return Limits.npmsec ? (int64_t)threads_nodes_searched()
: now() - Time.startTime;
}

#endif
Expand Down

0 comments on commit 54302a0

Please sign in to comment.