t-unit: two_eyes test suite
[pachi.git] / engine.h
blob45411069dc91855e02b0b7a305a08acb87bd524a
1 #ifndef PACHI_ENGINE_H
2 #define PACHI_ENGINE_H
4 #include "board.h"
5 #include "move.h"
6 #include "gtp.h"
8 struct move_queue;
10 typedef enum parse_code (*engine_notify_t)(struct engine *e, struct board *b, int id, char *cmd, char *args, char **reply);
11 typedef void (*engine_board_print_t)(struct engine *e, struct board *b, FILE *f);
12 typedef char *(*engine_notify_play_t)(struct engine *e, struct board *b, struct move *m, char *enginearg);
13 typedef char *(*engine_undo_t)(struct engine *e, struct board *b);
14 typedef char *(*engine_result_t)(struct engine *e, struct board *b);
15 typedef char *(*engine_chat_t)(struct engine *e, struct board *b, bool in_game, char *from, char *cmd);
16 /* Generate a move. If pass_all_alive is true, <pass> shall be generated only
17 * if all stones on the board can be considered alive, without regard to "dead"
18 * considered stones. */
19 typedef coord_t *(*engine_genmove_t)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive);
20 typedef char *(*engine_genmoves_t)(struct engine *e, struct board *b, struct time_info *ti, enum stone color,
21 char *args, bool pass_all_alive, void **stats_buf, int *stats_size);
22 /* Evaluate feasibility of player @color playing at all free moves. Will
23 * simulate each move from b->f[i] for time @ti, then set
24 * 1-max(opponent_win_likelihood) in vals[i]. */
25 typedef void (*engine_evaluate_t)(struct engine *e, struct board *b, struct time_info *ti, floating_t *vals, enum stone color);
26 /* One dead group per queued move (coord_t is (ab)used as group_t). */
27 typedef void (*engine_dead_group_list_t)(struct engine *e, struct board *b, struct move_queue *mq);
28 /* Pause any background thinking being done, but do not tear down
29 * any data structures yet. */
30 typedef void (*engine_stop_t)(struct engine *e);
31 /* e->data and e will be free()d by caller afterwards. */
32 typedef void (*engine_done_t)(struct engine *e);
34 /* GoGui hooks */
35 typedef float (*engine_owner_map_t)(struct engine *e, struct board *b, coord_t c);
36 typedef void (*engine_best_moves_t)(struct engine *e, struct board *b, enum stone color);
37 typedef void (*engine_live_gfx_hook_t)(struct engine *e);
39 /* This is engine data structure. A new engine instance is spawned
40 * for each new game during the program lifetime. */
41 struct engine {
42 char *name;
43 char *comment;
45 /* If set, do not reset the engine state on clear_board. */
46 bool keep_on_clear;
48 engine_notify_t notify;
49 engine_board_print_t board_print;
50 engine_notify_play_t notify_play;
51 engine_chat_t chat;
52 engine_undo_t undo;
53 engine_result_t result;
54 engine_genmove_t genmove;
55 engine_genmoves_t genmoves;
56 engine_evaluate_t evaluate;
57 engine_dead_group_list_t dead_group_list;
58 engine_stop_t stop;
59 engine_done_t done;
60 engine_owner_map_t owner_map;
61 engine_best_moves_t best_moves;
62 engine_live_gfx_hook_t live_gfx_hook;
63 void *data;
66 static inline void
67 engine_board_print(struct engine *e, struct board *b, FILE *f)
69 (e->board_print ? e->board_print(e, b, f) : board_print(b, f));
72 static inline void
73 engine_done(struct engine *e)
75 if (e->done) e->done(e);
76 if (e->data) free(e->data);
77 free(e);
81 #endif