Exemple #1
0
board_t *board_hash_table_search(board_hash_table_t *table,
                                 board_t *board)
{
    uint64_t hash, hash2;
    uint32_t index;
    board_list_t *list;

    if(table == NULL || board == NULL)
        return NULL;

    hash = board_hash(board, &hash2);
    index = hash & (table->size - 1);

    for(list = table->data[index];
        list != NULL;
        list = list->next)
    {
        if(list->hash == hash && list->hash2 == hash2
           && board_compare(list->item, board))
        {
            return list->item;
        }
    }

    return NULL;
}
Exemple #2
0
void cache_board_value(board_t b, int depth, double value) {
    int hash = board_hash(b);
    int index = hash % HASH_SIZE;
    vcache[index].hash = hash;
    vcache[index].value = value;
    vcache[index].depth = depth;
}
Exemple #3
0
board_t *board_hash_table_insert(board_hash_table_t *table,
                                 board_t *board)
{
    board_t *board_new;
    board_list_t *list = NULL, *list_new;
    uint32_t index;
    uint64_t hash, hash2;

    if(table == NULL || board == NULL)
        return NULL;

    if(table->used >= ((table->size * 3) / 4)) {
        board_hash_table_expand(table, table->size * 2);
    }

    hash = board_hash(board, &hash2);
    index = hash & (table->size - 1);

    list = table->data[index];
    if(list != NULL) {

        for(;;) {
            if(list->hash == hash && list->hash2 == hash2
               && board_compare(list->item, board))
            {
                return list->item;
            }

            if(list->next == NULL)
                break;

            list = list->next;
        }
    }

    board_new = board_clone(board);
    if(board_new == NULL)
        return NULL;

    list_new = malloc(sizeof(*list_new));
    if(list_new == NULL) {
        board_free(board_new);
        return NULL;
    }

    list_new->item = board_new;
    list_new->hash = hash;
    list_new->hash2 = hash2;
    list_new->next = NULL;

    if(list != NULL)
        list->next = list_new;
    else
        table->data[index] = list_new;

    table->used++;

    return NULL;
}
Exemple #4
0
double query_board_value(board_t b, int depth) {
    int hash = board_hash(b);
    int index = hash % HASH_SIZE;
    qcnt++;
    if (vcache[index].hash == hash && vcache[index].depth >= depth) {
        return vcache[index].value;
    }
    qmiss++;
    return -1;
}