Makefile: Use XLDFLAGS inst. of LDFLAGS for profiling options
[pachi/peepo.git] / zzgo.c
blob9d7a2a501f96c25ab9bd766101eec9c295b41c51
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 "random/random.h"
12 #include "uct/uct.h"
13 #include "gtp.h"
14 #include "random.h"
15 #include "version.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_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, "uct")) {
36 engine = E_UCT;
37 } else {
38 fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
39 exit(1);
41 break;
42 case 'd':
43 debug_level = atoi(optarg);
44 break;
45 case 's':
46 seed = atoi(optarg);
47 break;
48 default: /* '?' */
49 fprintf(stderr, "Pachi version %s\n", PACHI_VERSION);
50 fprintf(stderr, "Usage: %s [-e random|montecarlo|uct] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [ENGINE_ARGS]\n",
51 argv[0]);
52 exit(1);
56 fast_srandom(seed);
57 if (DEBUGL(0))
58 fprintf(stderr, "Random seed: %d", 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);
80 if (DEBUGL(1))
81 board_print(b, stderr);
83 return 0;