9 #include "joseki/base.h"
13 joseki_init(int bsize
)
15 struct joseki_dict
*jd
= calloc(1, sizeof(*jd
));
17 jd
->patterns
= calloc(1 << joseki_hash_bits
, sizeof(jd
->patterns
[0]));
22 joseki_load(int bsize
)
25 snprintf(fname
, 1024, "joseki%d.pdict", bsize
- 2);
26 FILE *f
= fopen(fname
, "r"); // XXX: size-dependent
32 struct joseki_dict
*jd
= joseki_init(bsize
);
35 while (fgets(linebuf
, 1024, f
)) {
38 hash_t h
= strtoull(line
, &line
, 16);
39 while (isspace(*line
)) line
++;
40 enum stone color
= *line
++ == 'b' ? S_BLACK
: S_WHITE
;
41 while (isspace(*line
)) line
++;
44 char *cs
= strrchr(line
, ' '); assert(cs
);
48 coord_t
**ccp
= &jd
->patterns
[h
].moves
[color
- 1];
50 *ccp
= calloc2(count
+ 1, sizeof(coord_t
));
53 assert(cc
- *ccp
< count
);
54 coord_t
*c
= str2coord(line
, bsize
);
57 line
+= strcspn(line
, " ");
58 line
+= strspn(line
, " ");
65 fprintf(stderr
, "Joseki dictionary for board size %d loaded.\n", bsize
- 2);
70 joseki_done(struct joseki_dict
*jd
)