Exemplo n.º 1
0
//finds route to target location and returns a pointer to the board that found it
Node* find_solution (Node *start, int height_coordinate, int width_coordinate){
    hash *hash_array = create_hash_table (HASH_TABLE_SIZE);
    set_hash_table (hash_array);
    Node *current, *previous, *parent;
    int target_found = 0;

    current = start;    
    parent = start;

    while (!target_found){
        previous = current;
        current->next = allocate_new_node (parent, previous);
        if (find_next_move (hash_array, start, current->next, parent->board, current->next->board) == 0){

            if (parent->next == NULL){
                printf("Couldn't find a solution\n");
                exit (1);
            }

            parent = parent->next;
            current->next->parent = parent;
            copy_board (current->next->board, parent->board);
    
        }
        target_found = check_for_target (current->next->board, height_coordinate, width_coordinate);
        current = current->next;
    }
    return current;
}
Exemplo n.º 2
0
 bool decode(tbnet::DataBuffer *input, tbnet::PacketHeader *header)
 {
    if (header->_dataLen < 20) {
       log_warn( "buffer data too few.");
       return false;
    }
    client_version = input->readInt32();
    server_version = input->readInt32();
    bucket_count = input->readInt32();
    copy_count = input->readInt32();
    down_slave_config_server = input->readInt64();
    data_need_move = input->readInt32();
    set_hash_table(NULL, input->readInt32());
    if (hash_table_size > input->getDataLen()) {
       log_warn( "buffer data too few.");
       return false;
    }
    if (hash_table_size > 0 && hash_table_data != NULL) {
       input->readBytes(hash_table_data, hash_table_size);
    }
    input->readBytes(group_name, 64);
    group_name[63] = '\0';
    plugins_flag = input->readInt32();
    plugins_dll_names.clear();
    plugins_version = input->readInt32();
    if (plugins_flag > 0) {
       plugins_dll_names.reserve(plugins_flag);
       for (int32_t i = 0; i < plugins_flag; i++) {
          char dll_name[TAIR_MAX_FILENAME_LEN];
          size_t len = input->readInt32();
          input->readBytes(dll_name, len);
          dll_name[len] = '\0';
          plugins_dll_names.push_back(dll_name);
       }
    }
    area_capacity_version = input->readInt32();
    vec_area_capacity_info.clear();
    uint32_t capacityInfoSize = input->readInt32();
    for(uint32_t i = 0; i < capacityInfoSize; i++) {
       uint32_t area = input->readInt32();
       uint64_t capacity = input->readInt64();
       vec_area_capacity_info.push_back(make_pair(area, capacity));
    }
    int size = input->readInt32();
    assert(migrated_info.size() % (copy_count + 1) == 0);
    for (int i = 0 ; i < size; ++i) {
       migrated_info.push_back(input->readInt64());
    }
    return true;
 }