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");
32 struct joseki_dict
*jd
= joseki_init(bsize
);
35 while (fgets(linebuf
, 1024, f
)) {
38 while (isspace(*line
)) line
++;
41 hash_t h
= strtoull(line
, &line
, 16);
42 while (isspace(*line
)) line
++;
43 enum stone color
= *line
++ == 'b' ? S_BLACK
: S_WHITE
;
44 while (isspace(*line
)) line
++;
47 char *cs
= strrchr(line
, ' '); assert(cs
);
51 coord_t
**ccp
= &jd
->patterns
[h
].moves
[color
- 1];
53 *ccp
= calloc2(count
+ 1, sizeof(coord_t
));
56 assert(cc
- *ccp
< count
);
57 coord_t
*c
= str2coord(line
, bsize
);
60 line
+= strcspn(line
, " ");
61 line
+= strspn(line
, " ");
68 fprintf(stderr
, "Joseki dictionary for board size %d loaded.\n", bsize
- 2);
73 joseki_done(struct joseki_dict
*jd
)