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 by default (if no
100 * time_left GTP commands are received). Please
101 * see timeinfo.h:time_parse() description for
103 if (!time_parse(&ti_default
[S_BLACK
], optarg
)) {
104 fprintf(stderr
, "%s: Invalid -t argument %s\n", argv
[0], optarg
);
107 ti_default
[S_WHITE
] = ti_default
[S_BLACK
];
110 testfile
= strdup(optarg
);
113 fprintf(stderr
, "Pachi version %s\n", PACHI_VERSION
);
114 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",
121 fprintf(stderr
, "Random seed: %d\n", seed
);
123 struct board
*b
= board_init();
124 struct time_info ti
[S_WHITE
+1];
125 ti
[S_BLACK
] = ti_default
[S_BLACK
];
126 ti
[S_WHITE
] = ti_default
[S_WHITE
];
130 e_arg
= argv
[optind
];
131 struct engine
*e
= init_engine(engine
, e_arg
, b
);
139 while (fgets(buf
, 4096, stdin
)) {
141 fprintf(stderr
, "IN: %s", buf
);
142 gtp_parse(b
, e
, ti
, buf
);
144 if (!e
->keep_on_clear
) {
147 e
= init_engine(engine
, e_arg
, b
);
148 ti
[S_BLACK
] = ti_default
[S_BLACK
];
149 ti
[S_WHITE
] = ti_default
[S_WHITE
];
151 engine_reset
= false;