예제 #1
0
파일: gtb.c 프로젝트: JERUKA9/lucaschess
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, &gtb_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();
  }
}
예제 #2
0
파일: GTB.cpp 프로젝트: gekomad/Cinnamon
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;
}
예제 #3
0
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();
  }
}
예제 #4
0
/*
 * 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(&gtb_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;
}
예제 #5
0
// Copyright 2012 by Jon Dart. All Rights Reserved.
//
// Interface to Gaviota tablebase code

#include "gtb.h"
#include "gtb-probe.h"

static const int WDL_FRACTION = 96;
static const char **paths = tbpaths_init();

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;