Esempio n. 1
0
void trans_alloc(trans_t * trans) {

    uint32 size, target;

    ASSERT(trans!=NULL);

    // calculate size

    target = option_get_int("Hash");
    if (target < 4) target = 16;
    target *= 1024 * 1024;

    for (size = 1; size != 0 && size <= target; size *= 2)
        ;

    size /= 2;
    ASSERT(size>0&&size<=target);

    // allocate table

    size /= sizeof(entry_t);
    ASSERT(size!=0&&(size&(size-1))==0); // power of 2

    trans->size = size + (ClusterSize - 1); // HACK to avoid testing for end of table
    trans->mask = size - 1;

    trans->table = (entry_t *) my_malloc(trans->size*sizeof(entry_t));

    trans_clear(trans);

    ASSERT(trans_is_ok(trans));
}
Esempio n. 2
0
void trans_init(trans_t * trans) {

    ASSERT(trans!=NULL);

    ASSERT(sizeof(entry_t)==16);

    trans->size = 0;
    trans->mask = 0;
    trans->table = NULL;

    trans_set_date(trans,0);

    trans_clear(trans);

    // ASSERT(trans_is_ok(trans));
}
Esempio n. 3
0
static void loop_step() {

   char string[65536];

   // read a line

   get(string,65536);

   // parse

   if (false) {

   } else if (string_start_with(string,"debug ")) {

      // dummy

   } else if (string_start_with(string,"go ")) {

      if (!Searching && !Delay) {
         init();
         parse_go(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"isready")) {

      if (!Searching && !Delay) {
         init();
      }

      send("readyok"); // no need to wait when searching (dixit SMK)

   } else if (string_equal(string,"ponderhit")) {

      if (Searching) {

         ASSERT(Infinite);

         SearchInput->infinite = false;
         Infinite = false;

      } else if (Delay) {

         send_best_move();
         Delay = false;

      } else {

         ASSERT(false);
      }

   } else if (string_start_with(string,"position ")) {

      if (!Searching && !Delay) {
         init();
         parse_position(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"quit")) {

      ASSERT(!Searching);
      ASSERT(!Delay);

      exit(EXIT_SUCCESS);

   } else if (string_start_with(string,"setoption ")) {

      if (!Searching && !Delay) {
         parse_setoption(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"stop")) {

      if (Searching) {

         SearchInfo->stop = true;
         Infinite = false;

      } else if (Delay) {

         send_best_move();
         Delay = false;
      }

   } else if (string_equal(string,"uci")) {

      ASSERT(!Searching);
      ASSERT(!Delay);

      send("id name Gambit Fruit " VERSION);
      send("id author Ryan Benitez, Thomas Gaksch and Fabien Letouzey");

      option_list();

      send("uciok");

   } else if (string_equal(string,"ucinewgame")) {

      if (!Searching && !Delay && Init) {
         trans_clear(Trans);
      } else {
         ASSERT(false);
      }
   }
}
Esempio n. 4
0
static void parse_setoption(char string[]) {

   const char * name;
   char * value;

   // init

   name = strstr(string,"name ");
   value = strstr(string,"value ");

   if (name == NULL || value == NULL || name >= value) return; // ignore buttons

   value[-1] = '\0'; // HACK
   name += 5;
   value += 6;

   // update

   option_set(name,value);

   // update transposition-table size if needed

   if (Init && my_string_equal(name,"Hash")) { // Init => already allocated

      ASSERT(!Searching);

      if (option_get_int("Hash") >= 4) {
         trans_free();
         trans_alloc();
      }
   }

   // update endgame tablebases if needed

   if (my_string_equal(name,"NalimovPath")) {

      ASSERT(!Searching);
      tb_path(option_get_string("NalimovPath"));
   }

   if (my_string_equal(name,"NalimovCache")) {

      ASSERT(!Searching);
      tb_cache(option_get_int("NalimovCache"));
   }

   if (my_string_equal(name,"EgbbPath")) {

      ASSERT(!Searching);
      egbb_path(option_get_string("EgbbPath"));
   }

   if (my_string_equal(name,"EgbbCache")) {

      ASSERT(!Searching);
      egbb_cache(option_get_int("EgbbCache"));
   }

   // update pawn structure if needed

   if (my_string_equal(name,"Pawn Structure")) {

      ASSERT(!Searching);
      pawn_structure_set_option(option_get_int("Pawn Structure"));
      pst_init();
   }

   // update piece activity if needed

   if (my_string_equal(name,"Piece Activity")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update king safty if needed

   if (my_string_equal(name,"King Safety")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update pawn activity if needed

   if (my_string_equal(name,"Pawn Activity")) {

      ASSERT(!Searching);
      trans_clear();
      pst_init();
   }

   // update material if needed

   if (my_string_equal(name,"Material")) {

      ASSERT(!Searching);
      material_set_option(option_get_int("Material"));
   }

   // update piece value if needed

   if (my_string_equal(name,"Pawn")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Pawn"),MAT_PAWN);
   }

   if (my_string_equal(name,"Knight")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Knight"),MAT_KNIGHT);
   }

   if (my_string_equal(name,"Bishop")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Bishop"),MAT_BISHOP);
   }

   if (my_string_equal(name,"Rook")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Rook"),MAT_ROOK);
   }

   if (my_string_equal(name,"Queen")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Queen"),MAT_QUEEN);
   }

   if (my_string_equal(name,"Bishop Pair")) {

      ASSERT(!Searching);
      piece_set_option(option_get_int("Bishop Pair"),MAT_BISHOP_PAIR);
   }
}
Esempio n. 5
0
void loop_step(const char * input) {

   char string[65536];
   char buffer[256];

   // read a line

   if (input != NULL) {
      get_local(string,65536,input);
   } else {
      get_stdin(string,65536);
   }

   // parse

   if (false) {

   } else if (string_start_with(string,"debug ")) {

      if (!Searching) {
         parse_debug(string);
      } else {
         ASSERT(false);
      }

   } else if (string_start_with(string,"go ")) {

      if (!Searching && !Delay) {
         init();
         parse_go(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"isready")) {

      if (!Searching && !Delay) {
         init();
      }

      send("readyok"); // no need to wait when searching (fixit SMK)

   } else if (string_equal(string,"ponderhit")) {

      if (Searching) {

         ASSERT(Infinite);

         SearchInput->infinite = false;
         Infinite = false;

      } else if (Delay) {

         send_best_move();
         Delay = false;

      } else {

         ASSERT(false);
      }

   } else if (string_start_with(string,"position ")) {

      if (!Searching && !Delay) {
         init();
         parse_position(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"quit")) {

      ASSERT(!Searching); // violated by Arena UI
      ASSERT(!Delay);

      if (Searching && option_get_int("Threads") > 1) {

         // Arena issue

         SearchInfo->stop = true;
         Infinite = false;

         smp_sleep();
      }

      trans_free();
      tb_close();
      egbb_close();
      smp_close();

      exit(EXIT_SUCCESS);

   } else if (string_start_with(string,"setoption ")) {

      if (!Searching && !Delay) {
         parse_setoption(string);
      } else {
         ASSERT(false);
      }

   } else if (string_equal(string,"stop")) {

      if (Searching) {

         SearchInfo->stop = true;
         Infinite = false;

      } else if (Delay) {

         send_best_move();
         Delay = false;
      }

   } else if (string_equal(string,"uci")) {

      ASSERT(!Searching);
      ASSERT(!Delay);

      send("id name Fruit reloaded %s", my_version(buffer));
      send("id author Fabien Letouzey, Ryan Benitez and Daniel Mehrmann");

      option_list();

      send("uciok");

   } else if (string_equal(string,"ucinewgame")) {

      if (!Searching && !Delay && Init) {
         trans_clear();
         pawn_clear();
         material_clear();
      } else {
         ASSERT(false);
      }
   }
}