Represent time as double instead of struct timespec to simplify the
[pachi.git] / timeinfo.h
blob724d3e75e6b49ef1cd7f81474b3217f442bfbea0
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. */
7 /* Note that some ways of specifying time (TD_GAMES) may not make sense
8 * with all engines. */
10 #include <stdbool.h>
12 struct time_info {
13 /* For how long we can spend the time? */
14 enum time_period {
15 TT_NULL, // No time limit. Other structure elements are undef.
16 TT_MOVE, // Time for the next move.
17 TT_TOTAL, // Time for the rest of the game.
18 } period;
19 /* How are we counting the time? */
20 enum time_dimension {
21 TD_GAMES, // Fixed number of simulations to perform.
22 TD_WALLTIME, // Wall time to spend performing simulations.
23 } dim;
24 union {
25 int games; // TD_GAMES
26 struct { // TD_WALLTIME
27 /* Recommended wall time for next move or game (seconds). Does not
28 * include net lag. Play asap if 0. */
29 double recommended_time;
30 } t;
31 } len;
34 /* Parse time information provided in custom format:
35 * =NUM - fixed number of simulations per move
36 * NUM - number of seconds to spend per move (can be float)
37 * _NUM - number of seconds to spend per game
39 * Returns false on parse error. */
40 bool time_parse(struct time_info *ti, char *s);
42 /* Returns the current time. */
43 double time_now(void);
45 /* Sleep for a given interval (in seconds). Return immediately if interval < 0. */
46 void time_sleep(double interval);
48 #endif