Merge branch 'master' of git://repo.or.cz/pachi
[pachi/peepo.git] / zzgo.c
blob53c9cd5de0de94401fc60c6f34828c05a11566fc
1 #define DEBUG
2 #include <getopt.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <time.h>
8 #include "board.h"
9 #include "debug.h"
10 #include "engine.h"
11 #include "montecarlo/montecarlo.h"
12 #include "random/random.h"
13 #include "uct/uct.h"
14 #include "gtp.h"
15 #include "random.h"
16 #include "version.h"
18 int debug_level = 1;
19 int seed;
21 int main(int argc, char *argv[])
23 struct board *b = board_init();
24 enum { E_RANDOM, E_MONTECARLO, E_UCT } engine = E_UCT;
26 seed = time(NULL);
28 int opt;
29 while ((opt = getopt(argc, argv, "e:d:s:")) != -1) {
30 switch (opt) {
31 case 'e':
32 if (!strcasecmp(optarg, "random")) {
33 engine = E_RANDOM;
34 } else if (!strcasecmp(optarg, "montecarlo")) {
35 engine = E_MONTECARLO;
36 } else if (!strcasecmp(optarg, "uct")) {
37 engine = E_UCT;
38 } else {
39 fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
40 exit(1);
42 break;
43 case 'd':
44 debug_level = atoi(optarg);
45 break;
46 case 's':
47 seed = atoi(optarg);
48 break;
49 default: /* '?' */
50 fprintf(stderr, "Pachi version %s\n", PACHI_VERSION);
51 fprintf(stderr, "Usage: %s [-e random|montecarlo|uct] [-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_UCT:
72 e = engine_uct_init(e_arg); break;
76 char buf[256];
77 while (fgets(buf, 256, stdin)) {
78 if (DEBUGL(1))
79 fprintf(stderr, "IN: %s", buf);
80 gtp_parse(b, e, buf);
81 if (DEBUGL(1))
82 board_print(b, stderr);
84 return 0;