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; if specified,
99 * GTP time information is ignored. Useful
100 * e.g. when you want to force your bot to
101 * play weaker while giving the opponent
102 * reasonable time to play, or force play
103 * by number of simulations in timed games. */
104 /* Please see timeinfo.h:time_parse()
105 * description for syntax details. */
106 if (!time_parse(&ti_default
, optarg
)) {
107 fprintf(stderr
, "%s: Invalid -t argument %s\n", argv
[0], optarg
);
110 ti_default
.ignore_gtp
= true;
111 /* Check for unsupported combinations. */
112 assert(ti_default
.period
!= TT_NULL
);
113 if (ti_default
.dim
== TD_GAMES
&& ti_default
.period
== TT_TOTAL
) {
114 fprintf(stderr
, "%s: Spreading fixed simulations# over the whole game is not supported\n", argv
[0]);
117 if (ti_default
.dim
== TD_WALLTIME
&& ti_default
.period
== TT_TOTAL
) {
118 fprintf(stderr
, "%s: Spreading fixed time over the whole game without GTP time_left aid is not supported for now\n", argv
[0]);
123 testfile
= strdup(optarg
);
126 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
127 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",
134 fprintf(stderr
, "Random seed: %d\n", seed
);
136 struct board
*b
= board_init();
137 struct time_info ti
[S_MAX
];
138 ti
[S_BLACK
] = ti_default
;
139 ti
[S_WHITE
] = ti_default
;
143 e_arg
= argv
[optind
];
144 struct engine
*e
= init_engine(engine
, e_arg
, b
);
152 while (fgets(buf
, 4096, stdin
)) {
154 fprintf(stderr
, "IN: %s", buf
);
155 gtp_parse(b
, e
, ti
, buf
);
157 if (!e
->keep_on_clear
) {
160 e
= init_engine(engine
, e_arg
, b
);
161 ti
[S_BLACK
] = ti_default
;
162 ti
[S_WHITE
] = ti_default
;
164 engine_reset
= false;