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 assert(ti_default
.period
!= TT_NULL
);
114 testfile
= strdup(optarg
);
117 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
118 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",
126 fprintf(stderr
, "Random seed: %d\n", seed
);
128 struct board
*b
= board_init();
129 struct time_info ti
[S_MAX
];
130 ti
[S_BLACK
] = ti_default
;
131 ti
[S_WHITE
] = ti_default
;
135 e_arg
= argv
[optind
];
136 struct engine
*e
= init_engine(engine
, e_arg
, b
);
144 while (fgets(buf
, 4096, stdin
)) {
146 fprintf(stderr
, "IN: %s", buf
);
147 gtp_parse(b
, e
, ti
, buf
);
149 if (!e
->keep_on_clear
) {
152 e
= init_engine(engine
, e_arg
, b
);
153 ti
[S_BLACK
] = ti_default
;
154 ti
[S_WHITE
] = ti_default
;
156 engine_reset
= false;