bool GTB::load() { if (path.size() == 0)return false; memset(installedPieces, 0, sizeof(installedPieces)); if (!FileUtil::fileExists(path)) { cout << "file not found " << path << endl; return false; } tbstats_reset(); paths = tbpaths_done(paths); paths = tbpaths_init(); _assert(paths); paths = tbpaths_add(paths, path.c_str()); restart(); unsigned av = tb_availability(); if (0 != (av & 2)) { setInstalledPieces(3); cout << "3-pc TBs complete\n"; } else if (0 != (av & 1)) { cout << "Some 3-pc TBs available\n"; } else { cout << "No 3-pc TBs available\n"; } if (0 != (av & 8)) { setInstalledPieces(4); cout << "4-pc TBs complete\n"; } else if (0 != (av & 4)) { cout << "Some 4-pc TBs available\n"; } else { cout << "No 4-pc TBs available\n"; } if (0 != (av & 32)) { setInstalledPieces(5); cout << "5-pc TBs complete\n"; } else if (0 != (av & 16)) { cout << "Some 5-pc TBs available\n"; } else { cout << "No 5-pc TBs available\n"; } cout << endl; if (!getAvailable()) { return false; } setCacheSize(cacheSize); tb_init(verbosity, scheme, paths); tbcache_init(cacheSize * 1024 * 1024, wdl_fraction); tbstats_reset(); return true; }
void gtb_init() { int av; //already initialized if(gtb_ok) gtb_clear(); if(gtb_cachesize == 0 || gtb_dec_scheme < 0 || gtb_dec_scheme > 9 || gtb_path[0] == 0) { gtb_ok == false; return; } gtb_paths = tbpaths_init(); gtb_paths = tbpaths_add(gtb_paths, >b_path[0]); tb_init(GTB_VERBOSE, gtb_dec_scheme, gtb_paths); tbcache_init(gtb_cachesize, WDL_FRACTION); tbstats_reset(); gtb_ok = (tb_is_initialized() && tbcache_is_on()); if(!gtb_ok) return; av = tb_availability(); if(av & 16) gtb_max_men = 5; else if(av & 8) gtb_max_men = 4; else if(av & 2) gtb_max_men = 3; else { gtb_max_men = 0; gtb_ok = false; gtb_clear(); } }
void init_egtb() { bool useTbs = Options["UseGaviotaTb"].value<bool>(); std::string newTbPaths = Options["GaviotaTbPath"].value<std::string>(); int newTbSize = Options["GaviotaTbCache"].value<int>(); int newCompressionScheme = get_compression_scheme_from_string(Options["GaviotaTbCompression"].value<std::string>()); Chess960 = Options["UCI_Chess960"].value<bool>(); // If we don't use the tablebases, close them out (in case previously open). if (!useTbs) { close_egtb(); return; } // Check if we need to initialize or reinitialize. if (newTbSize != TbSize || newTbPaths != TbPaths || newCompressionScheme != CompressionScheme) { // Close egtbs before reinitializing. close_egtb(); TbSize = newTbSize; TbPaths = newTbPaths; CompressionScheme = newCompressionScheme; // Parse TbPaths string which can contain many paths separated by ';' paths = tbpaths_init(); std::string substr; size_t prev_pos = 0, pos = 0; while( (pos = TbPaths.find(';', prev_pos)) != std::string::npos ) { if ((substr = trim(TbPaths.substr(prev_pos, pos-prev_pos))) != "") paths = tbpaths_add(paths, substr.c_str()); prev_pos = pos + 1; } if (prev_pos < TbPaths.size() && (substr = trim(TbPaths.substr(prev_pos))) != "") paths = tbpaths_add(paths, substr.c_str()); //Finally initialize tablebases tb_init(0, CompressionScheme, paths); tbcache_init(TbSize * 1024 * 1024, 124); tbstats_reset(); } }
/* * Given a string identifying the location of Gaviota tb's, load those * tb's for use during search. */ bool load_gtb(char* gtb_pathlist, int cache_size_bytes) { if (tb_is_initialized()) unload_gtb(); assert(tb_paths == NULL); assert(cache_size_bytes >= 0); assert(tb_WHITE_TO_MOVE == WHITE && tb_BLACK_TO_MOVE == BLACK); char* path = NULL; tb_paths = tbpaths_init(); while ((path = strsep(>b_pathlist, ";"))) { if (!*path) continue; tb_paths = tbpaths_add(tb_paths, path); } int verbosity = 0; tb_init(verbosity, options.gtb_scheme, tb_paths); if (!cache_size_bytes) cache_size_bytes = DEFAULT_GTB_CACHE_SIZE; tbcache_init(cache_size_bytes, WDL_CACHE_FRACTION); tbstats_reset(); bool success = tb_is_initialized() && tbcache_is_on(); if (success) { if (options.verbosity) { printf("info string loaded Gaviota TBs\n"); } worker_task_ready = false; worker_quit = false; #ifdef WINDOWS_THREADS worker_mutex = CreateMutex(NULL, FALSE, NULL); worker_thread = CreateThread( NULL, 0, gtb_probe_firm_worker, NULL, 0, NULL); if (!worker_thread) { printf("Thread creation failed\n"); } #else pthread_mutex_init(&worker_mutex, NULL); if (pthread_create(&worker_thread, NULL, gtb_probe_firm_worker, NULL)) perror("Worker thread creation failed.\n"); #endif } else if (options.verbosity) { printf("info string failed to load Gaviota TBs\n"); } return success; }
int GaviotaTb::initTB(const string &path, const string &scheme, uint64 cache_size) { if (NULL == paths) { cerr << "error in path initialization for Gaviota TBs" << endl; return 0; } paths = tbpaths_add(paths, path.c_str()); if (NULL == paths) { cerr << "error in path initialization for Gaviota TBs" << endl; return 0; } int intScheme; if (scheme == "cp1") intScheme = tb_CP1; else if (scheme == "cp2") intScheme = tb_CP2; else if (scheme == "cp3") intScheme = tb_CP3; else if (scheme == "cp4") intScheme = tb_CP4; else { cerr << "unrecognized compression scheme for GTBs: " << scheme << endl; return 0; } char *initinfo = tb_init (0, intScheme, paths); tbcache_init((size_t)cache_size, WDL_FRACTION); tbstats_reset(); if (initinfo != NULL) { cout << initinfo << endl; } int avail = tb_availability(); if (avail & (1<<6)) return 6; else if (avail & (1<<4)) return 5; else if (avail & (1<<2)) return 4; else if (avail & 1) return 3; else return 0; // error? }