Introduce versioning
[pachi.git] / zzgo.c
blob88f124ff5b01a959fd6c4d415b54d5d935acffe4
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"
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_MONTECASINO, 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, "montecasino")) {
37 engine = E_MONTECASINO;
38 } else if (!strcasecmp(optarg, "uct")) {
39 engine = E_UCT;
40 } else {
41 fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
42 exit(1);
44 break;
45 case 'd':
46 debug_level = atoi(optarg);
47 break;
48 case 's':
49 seed = atoi(optarg);
50 break;
51 default: /* '?' */
52 fprintf(stderr, "Pachi version %s\n", PACHI_VERSION);
53 fprintf(stderr, "Usage: %s [-e random|montecarlo|montecasino] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [ENGINE_ARGS]\n",
54 argv[0]);
55 exit(1);
59 fast_srandom(seed);
60 if (DEBUGL(0))
61 fprintf(stderr, "Random seed: %d", seed);
63 char *e_arg = NULL;
64 if (optind < argc)
65 e_arg = argv[optind];
66 struct engine *e;
67 switch (engine) {
68 case E_RANDOM:
69 default:
70 e = engine_random_init(e_arg); break;
71 case E_MONTECARLO:
72 e = engine_montecarlo_init(e_arg); break;
73 case E_MONTECASINO:
74 e = engine_montecasino_init(e_arg); break;
75 case E_UCT:
76 e = engine_uct_init(e_arg); break;
80 char buf[256];
81 while (fgets(buf, 256, stdin)) {
82 if (DEBUGL(1))
83 fprintf(stderr, "IN: %s", buf);
84 gtp_parse(b, e, buf);
85 if (DEBUGL(1))
86 board_print(b, stderr);
88 return 0;