Pattern gamma: Fix payload count for FEAT_L(L)DIST and FEAT_BORDER
[pachi/json.git] / zzgo.c
blob8df31b89fbaa5848c3609b972ee6cac8729a1725
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 "replay/replay.h"
12 #include "montecarlo/montecarlo.h"
13 #include "random/random.h"
14 #include "patternscan/patternscan.h"
15 #include "t-unit/test.h"
16 #include "uct/uct.h"
17 #include "gtp.h"
18 #include "random.h"
19 #include "version.h"
21 int debug_level = 1;
22 int seed;
24 int main(int argc, char *argv[])
26 struct board *b = board_init();
27 enum { E_RANDOM, E_REPLAY, E_PATTERNSCAN, E_MONTECARLO, E_UCT } engine = E_UCT;
28 char *testfile = NULL;
30 seed = time(NULL);
32 int opt;
33 while ((opt = getopt(argc, argv, "e:d:s:t:")) != -1) {
34 switch (opt) {
35 case 'e':
36 if (!strcasecmp(optarg, "random")) {
37 engine = E_RANDOM;
38 } else if (!strcasecmp(optarg, "patternscan")) {
39 engine = E_PATTERNSCAN;
40 } else if (!strcasecmp(optarg, "replay")) {
41 engine = E_REPLAY;
42 } else if (!strcasecmp(optarg, "montecarlo")) {
43 engine = E_MONTECARLO;
44 } else if (!strcasecmp(optarg, "uct")) {
45 engine = E_UCT;
46 } else {
47 fprintf(stderr, "%s: Invalid -e argument %s\n", argv[0], optarg);
48 exit(1);
50 break;
51 case 'd':
52 debug_level = atoi(optarg);
53 break;
54 case 's':
55 seed = atoi(optarg);
56 break;
57 case 't':
58 testfile = strdup(optarg);
59 break;
60 default: /* '?' */
61 fprintf(stderr, "Pachi version %s\n", PACHI_VERSION);
62 fprintf(stderr, "Usage: %s [-e random|replay|patternscan|montecarlo|uct] [-d DEBUG_LEVEL] [-s RANDOM_SEED] [-t FILENAME] [ENGINE_ARGS]\n",
63 argv[0]);
64 exit(1);
68 fast_srandom(seed);
69 fprintf(stderr, "Random seed: %d\n", seed);
71 char *e_arg = NULL;
72 if (optind < argc)
73 e_arg = argv[optind];
74 struct engine *e;
75 switch (engine) {
76 case E_RANDOM:
77 default:
78 e = engine_random_init(e_arg); break;
79 case E_REPLAY:
80 e = engine_replay_init(e_arg); break;
81 case E_PATTERNSCAN:
82 e = engine_patternscan_init(e_arg); break;
83 case E_MONTECARLO:
84 e = engine_montecarlo_init(e_arg); break;
85 case E_UCT:
86 e = engine_uct_init(e_arg); break;
90 if (testfile) {
91 unittest(testfile);
92 return 0;
95 char buf[4096];
96 while (fgets(buf, 4096, stdin)) {
97 if (DEBUGL(1))
98 fprintf(stderr, "IN: %s", buf);
99 gtp_parse(b, e, buf);
101 if (e->finish)
102 e->finish(e);
103 return 0;