UCT: Add policy= parameter, explore_p is now policy argument
[pachi.git] / zzgo.c
blob5d5700d2dbea90b619ea76ad31b53a7d89e0d19c
1 #include <getopt.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <time.h>
7 #include "board.h"
8 #include "debug.h"
9 #include "engine.h"
10 #include "montecarlo/montecarlo.h"
11 #include "montecasino/montecasino.h"
12 #include "random/random.h"
13 #include "uct/uct.h"
14 #include "gtp.h"
15 #include "random.h"
17 int debug_level = 1;
18 int seed;
20 int main(int argc, char *argv[])
22 struct board *b = board_init();
23 enum { E_RANDOM, E_MONTECARLO, E_MONTECASINO, E_UCT } engine = E_UCT;
25 seed = time(NULL);
27 int opt;
28 while ((opt = getopt(argc, argv, "e:d:s:")) != -1) {
29 switch (opt) {
30 case 'e':
31 if (!strcasecmp(optarg, "random")) {
32 engine = E_RANDOM;
33 } else if (!strcasecmp(optarg, "montecarlo")) {
34 engine = E_MONTECARLO;
35 } else if (!strcasecmp(optarg, "montecasino")) {
36 engine = E_MONTECASINO;
37 } else if (!strcasecmp(optarg, "uct")) {
38 engine = E_UCT;
39 } else {
40 fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
41 exit(1);
43 break;
44 case 'd':
45 debug_level = atoi(optarg);
46 break;
47 case 's':
48 seed = atoi(optarg);
49 break;
50 default: /* '?' */
51 fprintf(stderr, "Usage: %s [-e random|montecarlo|montecasino] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [ENGINE_ARGS]\n",
52 argv[0]);
53 exit(1);
57 fast_srandom(seed);
58 if (DEBUGL(0))
59 fprintf(stderr, "Random seed: %d", seed);
61 char *e_arg = NULL;
62 if (optind < argc)
63 e_arg = argv[optind];
64 struct engine *e;
65 switch (engine) {
66 case E_RANDOM:
67 default:
68 e = engine_random_init(e_arg); break;
69 case E_MONTECARLO:
70 e = engine_montecarlo_init(e_arg); break;
71 case E_MONTECASINO:
72 e = engine_montecasino_init(e_arg); break;
73 case E_UCT:
74 e = engine_uct_init(e_arg); break;
78 char buf[256];
79 while (fgets(buf, 256, stdin)) {
80 if (DEBUGL(1))
81 fprintf(stderr, "IN: %s", buf);
82 gtp_parse(b, e, buf);
83 if (DEBUGL(1))
84 board_print(b, stderr);
86 return 0;