1 #ifndef ZZGO_TIMEINFO_H
2 #define ZZGO_TIMEINFO_H
4 /* Time-keeping information about time to spend on the next move and/or
5 * rest of the game. This is only a hint, an engine may decide to spend
6 * more or less time on a given move, provided it never forfeits on time. */
8 /* Note that some ways of specifying time (TD_GAMES) may not make sense
16 /* For how long we can spend the time? */
18 TT_NULL
, // No time limit. Other structure elements are undef.
19 TT_MOVE
, // Time for the next move.
20 TT_TOTAL
, // Time for the rest of the game. Never seen by engine.
22 /* How are we counting the time? */
24 TD_GAMES
, // Fixed number of simulations to perform.
25 TD_WALLTIME
, // Wall time to spend performing simulations.
27 /* The actual time count. */
29 int games
; // TD_GAMES
30 struct { // TD_WALLTIME
31 /* Recommended wall time for next move or game (seconds).
32 * Does not include net lag. Play asap if 0. */
33 double recommended_time
;
35 /* Maximum wall time for next move or game. Will lose on time
36 * if exceeded. Does not include net lag. Play asap if 0. */
39 /* Minimum net lag (seconds) to be reserved by the engine.
40 * The engine may use a larger safety margin. */
43 /* Absolute time at which our timer started for current move,
44 * 0 if not yet known. The engine always sees > 0. */
47 /* --- PRIVATE DATA --- */
48 /* Byoyomi time per move (even for TT_TOTAL). This time must
49 * be remembered to avoid rushing at the end of the main
50 * period. 0 if no byoyomi. An engine should only consider
51 * recommended_time, the generic time control code always sets it to
52 * the best option (play on main time or on byoyomi time). */
54 int byoyomi_periods
; /* > 0 only for non-canadian byoyomi */
57 /* If true, this time info is independent from GTP time_left updates,
58 * which will be ignored. This is the case if the time settings were
59 * forced on the command line. */
63 /* Parse time information provided in custom format:
64 * =NUM - fixed number of simulations per move
65 * NUM - number of seconds to spend per move (can be float)
66 * _NUM - number of seconds to spend per game
68 * Returns false on parse error. */
69 bool time_parse(struct time_info
*ti
, char *s
);
71 /* Update time settings according to gtp time_settings command. */
72 void time_settings(struct time_info
*ti
, int main_time
, int byoyomi_time
, int byoyomi_stones
, int byoyomi_periods
);
74 /* Update time information according to gtp time_left command. */
75 void time_left(struct time_info
*ti
, int time_left
, int stones_left
);
77 /* Start our timer. kgs does this (correctly) on "play" not "genmove"
78 * unless we are making the first move of the game. */
79 void time_start_timer(struct time_info
*ti
);
81 /* Returns true if we are in byoyomi (or should play as if in byo yomi
82 * because remaining time per move in main time is less than byoyomi time
84 bool time_in_byoyomi(struct time_info
*ti
);
86 /* Returns the current time. */
87 double time_now(void);
89 /* Sleep for a given interval (in seconds). Return immediately if interval < 0. */
90 void time_sleep(double interval
);
93 /* Based on existing time information, compute the optimal/maximal time
94 * to be spent on this move. */
97 /* stop at that time if possible */
99 double time
; // TD_WALLTIME
100 int playouts
; // TD_GAMES
102 /* stop no later than this */
104 double time
; // TD_WALLTIME
105 int playouts
; // TD_GAMES
109 /* fuseki_end and yose_start are percentages of expected game length. */
110 void time_stop_conditions(struct time_info
*ti
, struct board
*b
, int fuseki_end
, int yose_start
, struct time_stop
*stop
);