コード例 #1
0
ファイル: board.c プロジェクト: Aaylor/Abalone
/*  Initialise le board dont le pointeur est en parametre   */
board *init_board(board*b){
  /* Creation du tableau */
  char i;
  int j;
  /* On initialise toutes les cases à ' ' si elle n'existe pas, '.' sinon */
  for(i='A'; i <= 'I';i++){
    for(j=1; j <= 9; j++){
      if(j < min_col(i) || j > max_col(i))
	b->tab[c_to_key(i)][i_to_key(j)] = '0';
      else
	b->tab[c_to_key(i)][i_to_key(j)] = '.';
    }
  }

  /* On pose les pieces
   * Piece B */
  for(i='A'; i <='B'; i++){ /* Les lignes A et B sont totalement à remplir */
    for(j=min_col(i); j <= max_col(i); j++){
      b->tab[c_to_key(i)][i_to_key(j)] = 'B';
    }
  }
  b->tab[c_to_key('C')][i_to_key(3)] = 'B';
  b->tab[c_to_key('C')][i_to_key(4)] = 'B';
  b->tab[c_to_key('C')][i_to_key(5)] = 'B';
  /* Piece N */
  for(i='H'; i <='I'; i++){ /* Les lignes H et I sont totalement à remplir */
    for(j=min_col(i); j <= max_col(i); j++){
      b->tab[c_to_key(i)][i_to_key(j)] = 'N';
    }
  }
  b->tab[c_to_key('G')][i_to_key(5)] = 'N';
  b->tab[c_to_key('G')][i_to_key(6)] = 'N';
  b->tab[c_to_key('G')][i_to_key(7)] = 'N';
  return b;
}
コード例 #2
0
ファイル: GeneralAligner.hpp プロジェクト: npge/npge
 /** Run alignment algorithm.
 \param first_last Last aligned position in first sequence (output)
 \param second_last Last aligned position in second sequence (output)
 */
 void align(int& first_last, int& second_last) const {
     adjust_matrix_size();
     limit_range();
     make_frame();
     ASSERT_TRUE(!local() || max_errors() == -1);
     int& r_row = first_last;
     int& r_col = second_last;
     r_row = r_col = -1;
     for (int row = 0; row <= max_row(); row++) {
         int start_col = min_col(row);
         int stop_col = max_col(row);
         int min_score_col = start_col;
         for (int col = start_col; col <= stop_col; col++) {
             ASSERT_TRUE(col >= 0 && col < side());
             ASSERT_TRUE(in(row, col));
             int match = at(row - 1, col - 1) +
                         substitution(row, col);
             int gap1 = at(row, col - 1) + gap_penalty();
             int gap2 = at(row - 1, col) + gap_penalty();
             int score = std::min(match, std::min(gap1, gap2));
             if (local()) {
                 score = std::min(score, 0);
             }
             at(row, col) = score;
             if (score < at(row, min_score_col)) {
                 min_score_col = col;
             }
             track(row, col) = (score == match) ? MATCH :
                               (score == gap1) ? COL_INC :
                               ROW_INC;
         }
         if (max_errors() != -1 &&
                 at(row, min_score_col) > max_errors()) {
             break;
         }
         r_row = row;
         r_col = min_score_col;
     }
     if (max_errors() == -1) {
         // col -> max_col in this row
         ASSERT_TRUE(in(max_row(), max_col(max_row())));
         ASSERT_EQ(r_row, max_row());
         r_col = max_col(max_row());
         // if stopped earlier because of gap range
         int last_row = contents().first_size() - 1;
         int last_col = contents().second_size() - 1;
         if (r_row == last_row) {
             while (r_col < last_col) {
                 r_col += 1;
                 track(r_row, r_col) = COL_INC;
             }
         } else if (r_col == last_col) {
             while (r_row < last_row) {
                 r_row += 1;
                 track(r_row, r_col) = ROW_INC;
             }
         } else {
             throw Exception("row and column are not last");
         }
     }
 }
コード例 #3
0
/** execute_db_operator takes as input the db_operator and executes the query.
 * It should return the result (currently as a char*, although I'm not clear
 * on what the return type should be, maybe a result struct, and then have
 * a serialization into a string message).
 **/
char* execute_db_operator(db_operator* query) {
    status s;

    if (query->type == INSERT) {
        table* tbl1 = query->tables[0];
        for(size_t i = 0; i < tbl1->col_count; i++) {
            s = col_insert(query->columns[i], query->value1[i]);
            if (s.code != OK) {
                return s.error_message;
            }
        }
        return "Rows successfully inserted.";
    } else if (query->type == SELECT) {
        result* r = malloc(sizeof(struct result));
        if (query->columns) {
            s = select_data(query, &r);
        } else if (query->result1 && query->result2) {
            s = vec_scan(query, &r);
        } else {
            return "Cannot perform select\n";
        }

        if (s.code != OK) {
            return s.error_message;
        }
        int idx = catalogs[0]->var_count;
        catalogs[0]->names[idx] = query->name1;
        catalogs[0]->results[idx] = r;
        catalogs[0]->var_count++;
    } else if (query->type == PROJECT) {
        result* r = malloc(sizeof(struct result));
        status s = fetch(*(query->columns), query->result1->payload, query->result1->num_tuples, &r);
        if (s.code != OK) {
            return s.error_message;
        }
        int idx = catalogs[0]->var_count;
        catalogs[0]->names[idx] = query->name1;
        catalogs[0]->results[idx] = r;
        catalogs[0]->var_count++;
    } else if (query->type == ADD) {
        result* r = malloc(sizeof(struct result));
        s = add_col((int*)query->result1->payload, (int*)query->result2->payload, query->result1->num_tuples, &r);
        if (s.code != OK) {
            return s.error_message;
        }
        int idx = catalogs[0]->var_count;
        catalogs[0]->names[idx] = query->name1;
        catalogs[0]->results[idx] = r;
        // for (size_t i = 0; i < r->num_tuples; ++i)
        // {
        //     printf("%ld\n", ((long*)r->payload)[i]);
        // }
        catalogs[0]->var_count++;
    } else if (query->type == SUB) {
        result* r = malloc(sizeof(struct result));
        s = sub_col((int*)query->result1->payload, (int*)query->result2->payload, query->result1->num_tuples, &r);
        if (s.code != OK) {
            return s.error_message;
        }
        int idx = catalogs[0]->var_count;
        catalogs[0]->names[idx] = query->name1;
        catalogs[0]->results[idx] = r;
        catalogs[0]->var_count++;
    } else if (query->type == AGGREGATE) {
        result* r = malloc(sizeof(struct result));
        if (query->agg == MIN) {
            s = min_col(query->result1, &r);
        } else if (query->agg == MAX) {
            s = max_col(query->result1, &r);
        } else if (query->agg == AVG) {
            s = avg_col(query->result1, &r);
        } else if (query->agg == CNT) {
            s = count_col(query->result1->num_tuples, &r);
        } else {
            return "Failed aggregation";
        }

        if (s.code != OK) {
            return s.error_message;
        }

        int idx = catalogs[0]->var_count;
        catalogs[0]->names[idx] = query->name1;
        catalogs[0]->results[idx] = r;
        catalogs[0]->var_count++;
    }

    return "Success";
}