74 OpeningBook(
int width,
int height) : T{0}, width{width}, height{height}, depth{ -1} {}
88 void load(std::string filename) {
91 std::ifstream ifs(filename, std::ios::binary);
94 std::cerr <<
"Unable to load opening book: " << filename << std::endl;
96 }
else std::cerr <<
"Loading opening book from file: " << filename <<
". ";
98 char _width, _height, _depth, value_bytes, partial_key_bytes, log_size;
100 ifs.read(&_width, 1);
101 if(ifs.fail() || _width != width) {
102 std::cerr <<
"Unable to load opening book: invalid width (found: " << int(_width) <<
", expected: " << width <<
")" << std::endl;
106 ifs.read(&_height, 1);
107 if(ifs.fail() || _height != height) {
108 std::cerr <<
"Unable to load opening book: invalid height(found: " << int(_height) <<
", expected: " << height <<
")" << std::endl;
112 ifs.read(&_depth, 1);
113 if(ifs.fail() || _depth > width * height) {
114 std::cerr <<
"Unable to load opening book: invalid depth (found: " << int(_depth) <<
")" << std::endl;
118 ifs.read(&partial_key_bytes, 1);
119 if(ifs.fail() || partial_key_bytes > 8) {
120 std::cerr <<
"Unable to load opening book: invalid internal key size(found: " << int(partial_key_bytes) <<
")" << std::endl;
124 ifs.read(&value_bytes, 1);
125 if(ifs.fail() || value_bytes != 1) {
126 std::cerr <<
"Unable to load opening book: invalid value size (found: " << int(value_bytes) <<
", expected: 1)" << std::endl;
130 ifs.read(&log_size, 1);
131 if(ifs.fail() || log_size > 40) {
132 std::cerr <<
"Unable to load opening book: invalid log2(size)(found: " << int(log_size) <<
")" << std::endl;
136 if((T = initTranspositionTable(partial_key_bytes, log_size))) {
137 ifs.read(
reinterpret_cast<char *
>(T->getKeys()), T->getSize() * partial_key_bytes);
138 ifs.read(
reinterpret_cast<char *
>(T->getValues()), T->getSize() * value_bytes);
140 std::cerr <<
"Unable to load data from opening book" << std::endl;
144 std::cerr <<
"done" << std::endl;
146 else std::cerr <<
"Unable to initialize opening book" << std::endl;