11 fbook_init(char *filename
, struct board
*b
)
13 FILE *f
= fopen(filename
, "r");
19 struct fbook
*fbook
= calloc(1, sizeof(*fbook
));
20 fbook
->bsize
= board_size(b
);
21 fbook
->handicap
= b
->handicap
;
22 for (int i
= 0; i
< 1<<fbook_hash_bits
; i
++)
23 fbook
->moves
[i
] = pass
;
26 fprintf(stderr
, "Loading opening fbook %s...\n", filename
);
28 /* Scratch board where we lay out the sequence;
29 * one for each transposition. */
31 for (int i
= 0; i
< 8; i
++) {
32 bs
[i
] = board_init(NULL
);
33 board_resize(bs
[i
], fbook
->bsize
- 2);
37 while (fgets(linebuf
, sizeof(linebuf
), f
)) {
39 linebuf
[strlen(linebuf
) - 1] = 0; // chop
42 * BSIZE COORD COORD COORD... | COORD
43 * We descend up to |, then add the new node
44 * with value minimax(1000), forcing UCT to
45 * always pick that node immediately. */
46 int bsize
= strtol(line
, &line
, 10);
47 if (bsize
!= fbook
->bsize
- 2)
49 while (isspace(*line
)) line
++;
51 for (int i
= 0; i
< 8; i
++) {
53 bs
[i
]->last_move
.color
= S_WHITE
;
56 while (*line
!= '|') {
57 coord_t
*c
= str2coord(line
, fbook
->bsize
);
59 for (int i
= 0; i
< 8; i
++) {
60 #define HASH_VMIRROR 1
61 #define HASH_HMIRROR 2
64 if (i
& HASH_VMIRROR
) {
65 coord
= coord_xy(b
, coord_x(coord
, b
), board_size(b
) - 1 - coord_y(coord
, b
));
67 if (i
& HASH_HMIRROR
) {
68 coord
= coord_xy(b
, board_size(b
) - 1 - coord_x(coord
, b
), coord_y(coord
, b
));
70 if (i
& HASH_XYFLIP
) {
71 coord
= coord_xy(b
, coord_y(coord
, b
), coord_x(coord
, b
));
73 struct move m
= { .coord
= coord
, .color
= stone_other(bs
[i
]->last_move
.color
) };
74 int ret
= board_play(bs
[i
], &m
);
79 while (!isspace(*line
)) line
++;
80 while (isspace(*line
)) line
++;
84 while (isspace(*line
)) line
++;
86 coord_t
*c
= str2coord(line
, fbook
->bsize
);
87 for (int i
= 0; i
< 8; i
++) {
89 fprintf(stderr
, "%c %"PRIhash
" (<%d> %s)\n",
90 is_pass(fbook
->moves
[bs
[i
]->hash
& fbook_hash_mask
]) ? '+' : 'C',
91 bs
[i
]->hash
& fbook_hash_mask
, i
, linebuf
);
93 fbook
->moves
[bs
[i
]->hash
& fbook_hash_mask
] = *c
;
98 for (int i
= 0; i
< 8; i
++) {
107 void fbook_done(struct fbook
*fbook
)