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 /* time_info for none(ignored), black, white: */
68 struct time_info ti_default
[] = { { .period
= TT_NULL
}, { .period
= TT_NULL
}, { .period
= TT_NULL
}};
69 char *testfile
= NULL
;
71 seed
= time(NULL
) ^ getpid();
74 while ((opt
= getopt(argc
, argv
, "e:d:s:t:u:")) != -1) {
77 if (!strcasecmp(optarg
, "random")) {
79 } else if (!strcasecmp(optarg
, "patternscan")) {
80 engine
= E_PATTERNSCAN
;
81 } else if (!strcasecmp(optarg
, "replay")) {
83 } else if (!strcasecmp(optarg
, "montecarlo")) {
84 engine
= E_MONTECARLO
;
85 } else if (!strcasecmp(optarg
, "uct")) {
88 fprintf(stderr
, "%s: Invalid -e argument %s\n", argv
[0], optarg
);
93 debug_level
= atoi(optarg
);
99 /* Time settings to follow; if specified,
100 * GTP time information is ignored. Useful
101 * e.g. when you want to force your bot to
102 * play weaker while giving the opponent
103 * reasonable time to play, or force play
104 * by number of simulations in timed games. */
105 /* Please see timeinfo.h:time_parse()
106 * description for syntax details. */
107 if (!time_parse(&ti_default
[S_BLACK
], optarg
)) {
108 fprintf(stderr
, "%s: Invalid -t argument %s\n", argv
[0], optarg
);
111 ti_default
[S_BLACK
].ignore_gtp
= true;
112 ti_default
[S_WHITE
] = ti_default
[S_BLACK
];
115 testfile
= strdup(optarg
);
118 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
119 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_WHITE
+1];
130 ti
[S_BLACK
] = ti_default
[S_BLACK
];
131 ti
[S_WHITE
] = ti_default
[S_WHITE
];
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
[S_BLACK
];
154 ti
[S_WHITE
] = ti_default
[S_WHITE
];
156 engine_reset
= false;