Allow defining total time not just time per move.
[pachi/derm.git] / timeinfo.h
blob010f87bd4bd43d0c1ec1c292d308413e4a139ef5
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 #include "board.h"
14 struct time_info {
15 /* For how long we can spend the time? */
16 enum time_period {
17 TT_NULL, // No time limit. Other structure elements are undef.
18 TT_MOVE, // Time for the next move.
19 TT_TOTAL, // Time for the rest of the game.
20 } period;
21 /* How are we counting the time? */
22 enum time_dimension {
23 TD_GAMES, // Fixed number of simulations to perform.
24 TD_WALLTIME, // Wall time to spend performing simulations.
25 } dim;
26 union {
27 int games; // TD_GAMES
28 struct { // TD_WALLTIME
29 /* Recommended wall time for next move or game (seconds). Does not
30 * include net lag. Play asap if 0. */
31 double recommended_time;
33 /* Absolute time at which our timer started for current move, 0 if
34 * not yet known. The engine always sees > 0. */
35 double timer_start;
36 } t;
37 } len;
40 /* Parse time information provided in custom format:
41 * =NUM - fixed number of simulations per move
42 * NUM - number of seconds to spend per move (can be float)
43 * _NUM - number of seconds to spend per game
45 * Returns false on parse error. */
46 bool time_parse(struct time_info *ti, char *s);
48 /* Start our timer. kgs does this (correctly) on "play" not "genmove"
49 * unless we are making the first move of the game. */
50 void time_start_timer(struct time_info *ti);
52 /* Set correct time information before making a move, and
53 * always make it time per move for the engine. */
54 void time_prepare_move(struct time_info *ti, struct board *board);
56 /* Returns the current time. */
57 double time_now(void);
59 /* Sleep for a given interval (in seconds). Return immediately if interval < 0. */
60 void time_sleep(double interval);
62 #endif