13 #include "replay/replay.h"
14 #include "montecarlo/montecarlo.h"
15 #include "random/random.h"
16 #include "patternscan/patternscan.h"
17 #include "t-unit/test.h"
37 static struct engine
*(*engine_init
[E_MAX
])(char *arg
, struct board
*b
) = {
40 engine_patternscan_init
,
41 engine_montecarlo_init
,
45 static struct engine
*init_engine(enum engine_id engine
, char *e_arg
, struct board
*b
)
47 char *arg
= e_arg
? strdup(e_arg
) : e_arg
;
48 assert(engine
< E_MAX
);
49 struct engine
*e
= engine_init
[engine
](arg
, b
);
54 static void done_engine(struct engine
*e
)
56 if (e
->done
) e
->done(e
);
57 if (e
->data
) free(e
->data
);
61 bool engine_reset
= false;
64 int main(int argc
, char *argv
[])
66 enum engine_id engine
= E_UCT
;
67 struct time_info ti_default
= { .period
= TT_NULL
};
68 char *testfile
= NULL
;
70 seed
= time(NULL
) ^ getpid();
73 while ((opt
= getopt(argc
, argv
, "e:d:s:t:u:")) != -1) {
76 if (!strcasecmp(optarg
, "random")) {
78 } else if (!strcasecmp(optarg
, "patternscan")) {
79 engine
= E_PATTERNSCAN
;
80 } else if (!strcasecmp(optarg
, "replay")) {
82 } else if (!strcasecmp(optarg
, "montecarlo")) {
83 engine
= E_MONTECARLO
;
84 } else if (!strcasecmp(optarg
, "uct")) {
87 fprintf(stderr
, "%s: Invalid -e argument %s\n", argv
[0], optarg
);
92 debug_level
= atoi(optarg
);
98 /* Time settings to follow by default (if no
99 * time_left GTP commands are received). Please
100 * see timeinfo.h:time_parse() description for
102 if (!time_parse(&ti_default
, optarg
)) {
103 fprintf(stderr
, "%s: Invalid -t argument %s\n", argv
[0], optarg
);
108 testfile
= strdup(optarg
);
111 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
112 fprintf(stderr
, "Usage: %s [-e random|replay|patternscan|montecarlo|uct] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [-t TIME_SETTINGS] [-u TEST_FILENAME] [ENGINE_ARGS]\n",
119 fprintf(stderr
, "Random seed: %d\n", seed
);
121 struct board
*b
= board_init();
122 struct time_info ti
= ti_default
;
126 e_arg
= argv
[optind
];
127 struct engine
*e
= init_engine(engine
, e_arg
, b
);
135 while (fgets(buf
, 4096, stdin
)) {
137 fprintf(stderr
, "IN: %s", buf
);
138 gtp_parse(b
, e
, &ti
, buf
);
140 if (!e
->keep_on_clear
) {
143 e
= init_engine(engine
, e_arg
, b
);
146 engine_reset
= false;