Pachi Doetsu-devel 3.99
[pachi.git] / zzgo.c
blobc1867fb623cff1b7c2a5982640f42ea9d86814b5
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 fprintf(stderr, "Random seed: %d\n", seed);
60 char *e_arg = NULL;
61 if (optind < argc)
62 e_arg = argv[optind];
63 struct engine *e;
64 switch (engine) {
65 case E_RANDOM:
66 default:
67 e = engine_random_init(e_arg); break;
68 case E_MONTECARLO:
69 e = engine_montecarlo_init(e_arg); break;
70 case E_UCT:
71 e = engine_uct_init(e_arg); break;
75 char buf[256];
76 while (fgets(buf, 256, stdin)) {
77 if (DEBUGL(1))
78 fprintf(stderr, "IN: %s", buf);
79 gtp_parse(b, e, buf);
81 return 0;