12 #include "replay/replay.h"
13 #include "montecarlo/montecarlo.h"
14 #include "random/random.h"
15 #include "patternscan/patternscan.h"
16 #include "t-unit/test.h"
35 static struct engine
*(*engine_init
[E_MAX
])(char *arg
, struct board
*b
) = {
38 engine_patternscan_init
,
39 engine_montecarlo_init
,
43 static struct engine
*init_engine(enum engine_id engine
, char *e_arg
, struct board
*b
)
45 char *arg
= e_arg
? strdup(e_arg
) : e_arg
;
46 assert(engine
< E_MAX
);
47 struct engine
*e
= engine_init
[engine
](arg
, b
);
52 static void done_engine(struct engine
*e
)
54 if (e
->done
) e
->done(e
);
55 if (e
->data
) free(e
->data
);
59 bool engine_reset
= false;
62 int main(int argc
, char *argv
[])
64 enum engine_id engine
= E_UCT
;
65 char *testfile
= NULL
;
70 while ((opt
= getopt(argc
, argv
, "e:d:s:t:")) != -1) {
73 if (!strcasecmp(optarg
, "random")) {
75 } else if (!strcasecmp(optarg
, "patternscan")) {
76 engine
= E_PATTERNSCAN
;
77 } else if (!strcasecmp(optarg
, "replay")) {
79 } else if (!strcasecmp(optarg
, "montecarlo")) {
80 engine
= E_MONTECARLO
;
81 } else if (!strcasecmp(optarg
, "uct")) {
84 fprintf(stderr
, "%s: Invalid -e argument %s\n", argv
[0], optarg
);
89 debug_level
= atoi(optarg
);
95 testfile
= strdup(optarg
);
98 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
99 fprintf(stderr
, "Usage: %s [-e random|replay|patternscan|montecarlo|uct] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [-t FILENAME] [ENGINE_ARGS]\n",
106 fprintf(stderr
, "Random seed: %d\n", seed
);
108 struct board
*b
= board_init();
112 e_arg
= argv
[optind
];
113 struct engine
*e
= init_engine(engine
, e_arg
, b
);
121 while (fgets(buf
, 4096, stdin
)) {
123 fprintf(stderr
, "IN: %s", buf
);
124 gtp_parse(b
, e
, buf
);
126 if (!e
->keep_on_clear
) {
129 e
= init_engine(engine
, e_arg
, b
);
131 engine_reset
= false;