コード例 #1
0
ファイル: material.cpp プロジェクト: grefen/CGChess
void material_get_info( material_info_t *info, const board_t *board, int ThreadId )
{

	uint64 key;
	entry_t *entry;

	ASSERT(info != NULL);
	ASSERT(board != NULL);

	// probe

	if( UseTable )
	{

		Material[ThreadId]->read_nb++;

		key = board->material_key;
		entry = &Material[ThreadId]->table[KEY_INDEX(key) & Material[ThreadId]->mask];

		if( entry->lock == KEY_LOCK(key) )
		{

			// found

			Material[ThreadId]->read_hit++;

			*info = *entry;

			return;
		}
	}

	// calculation

	material_comp_info(info, board);

	// store

	if( UseTable )
	{

		Material[ThreadId]->write_nb++;

		if( entry->lock == 0 )
		{
			Material[ThreadId]->used++;
		}
		else
		{
			Material[ThreadId]->write_collision++;
		}

		*entry = *info;
		entry->lock = KEY_LOCK(key);
	}
}
コード例 #2
0
void material_get_info(material_info_t * info) 
{
   uint64 key;
   entry_t * entry;

   ASSERT(info!=NULL);
   

   // probe

   if (UseTable) {

      Material->read_nb++;

      key = Lock;
      entry = &Material->table[KEY_INDEX(key)&Material->mask];

      if (entry->lock == KEY_LOCK(key)) {

         // found

         Material->read_hit++;

         *info = *entry;

         return;
      }
   }

   // calculation

   material_comp_info(info);

   // store

   if (UseTable) {

      Material->write_nb++;

      if (entry->lock == 0) { // HACK: assume free entry
         Material->used++;
      } else {
         Material->write_collision++;
      }

      *entry = *info;
      entry->lock = KEY_LOCK(key);
   }

}
コード例 #3
0
ファイル: pawn.cpp プロジェクト: raimarHD/lcec
void pawn_get_info(pawn_info_t * info, const board_t * board, int ThreadId) {

   uint64 key;
   entry_t * entry;

   ASSERT(info!=NULL);
   ASSERT(board!=NULL);

   // probe

   if (UseTable) {

      Pawn[ThreadId]->read_nb++;

      key = board->pawn_key;
      entry = &Pawn[ThreadId]->table[KEY_INDEX(key)&Pawn[ThreadId]->mask];

      if (entry->lock == KEY_LOCK(key)) {

         // found

         Pawn[ThreadId]->read_hit++;

         *info = *entry;

         return;
      }
   }

   // calculation

   pawn_comp_info(info,board);

   // store

   if (UseTable) {

      Pawn[ThreadId]->write_nb++;

      if (entry->lock == 0) { // HACK: assume free entry
         Pawn[ThreadId]->used++;
      } else {
         Pawn[ThreadId]->write_collision++;
      }

      *entry = *info;
      entry->lock = KEY_LOCK(key);
   }
}
コード例 #4
0
ファイル: trans.cpp プロジェクト: zwegner/toga-mp
bool trans_retrieve(trans_t * trans, uint64 key, int * move, int * min_depth, int * max_depth, int * min_value, int * max_value) {

   entry_t * entry;
   int i;

   ASSERT(trans_is_ok(trans));
   ASSERT(move!=NULL);
   ASSERT(min_depth!=NULL);
   ASSERT(max_depth!=NULL);
   ASSERT(min_value!=NULL);
   ASSERT(max_value!=NULL);

   // init

   trans->read_nb++;

   // probe

   entry = trans_entry(trans,key);

   for (i = 0; i < ClusterSize; i++, entry++) {

      if (entry->lock == KEY_LOCK(key) /*^ entry->key1 ^ entry->key2 ^ entry->key3*/) {

         // found

         trans->read_hit++;
         if (entry->date != trans->date) {
            entry->date = trans->date;
            entry->lock == KEY_LOCK(key) /*^ entry->key1 ^ entry->key2 ^ entry->key3*/;
         }

         *move = entry->move;

         *min_depth = entry->min_depth;
         *max_depth = entry->max_depth;
         *min_value = entry->min_value;
         *max_value = entry->max_value;

         return true;
      }
   }

   // not found

   return false;
}
コード例 #5
0
void trans_store(trans_t * trans, uint64 key, int move, int depth, int min_value, int max_value) {

    entry_t * entry, * best_entry;
    int score, best_score;
    int i;

    ASSERT(trans_is_ok(trans));
    ASSERT(move>=0&&move<65536);
    ASSERT(depth>=-127&&depth<=+127);
    ASSERT(min_value>=-ValueInf&&min_value<=+ValueInf);
    ASSERT(max_value>=-ValueInf&&max_value<=+ValueInf);
    ASSERT(min_value<=max_value);

    // init

    trans->write_nb++;

    // probe

    best_entry = NULL;
    best_score = -32767;

    entry = trans_entry(trans,key);

    for (i = 0; i < ClusterSize; i++, entry++) {

        if (entry->lock == KEY_LOCK(key)) {

            // hash hit => update existing entry

            trans->write_hit++;
            if (entry->date != trans->date) trans->used++;

            entry->date = trans->date;

            if (trans_endgame || depth > entry->depth) entry->depth = depth;
            /* if (depth > entry->depth)  entry->depth = depth; // for replacement scheme */

            // if (move != MoveNone /* && depth >= entry->move_depth */) {
            if (move != MoveNone && (trans_endgame || depth >= entry->move_depth)) {
                entry->move_depth = depth;
                entry->move = move;
            }

            // if (min_value > -ValueInf /* && depth >= entry->min_depth */) {
            if (min_value > -ValueInf && (trans_endgame || depth >= entry->min_depth)) {
                entry->min_depth = depth;
                entry->min_value = min_value;
            }

            // if (max_value < +ValueInf /* && depth >= entry->max_depth */) {
            if (max_value < +ValueInf && (trans_endgame || depth >= entry->max_depth)) {
                entry->max_depth = depth;
                entry->max_value = max_value;
            }

            ASSERT(entry_is_ok(entry));

            return;
        }

        // evaluate replacement score

        score = trans->age[entry->date] * 256 - entry->depth;
        ASSERT(score>-32767);

        if (score > best_score) {
            best_entry = entry;
            best_score = score;
        }
    }

    // "best" entry found

    entry = best_entry;
    ASSERT(entry!=NULL);
    ASSERT(entry->lock!=KEY_LOCK(key));

    if (entry->date == trans->date) {
        trans->write_collision++;
    } else {
        trans->used++;
    }

    // store

    ASSERT(entry!=NULL);

    entry->lock = KEY_LOCK(key);
    entry->date = trans->date;

    entry->depth = depth;

    entry->move_depth = (move != MoveNone) ? depth : DepthNone;
    entry->move = move;

    entry->min_depth = (min_value > -ValueInf) ? depth : DepthNone;
    entry->max_depth = (max_value < +ValueInf) ? depth : DepthNone;
    entry->min_value = min_value;
    entry->max_value = max_value;

    ASSERT(entry_is_ok(entry));
}