Exemple #1
0
static inline unsigned int 
is_alive(struct field * f, unsigned int x, unsigned int y)
{
    unsigned int count;
    unsigned int i, j;
    unsigned char *p;

    count = 0;

    for (i = x - 1; i <= x + 1; i++) {
	for (j = y - 1; j <= y + 1; j++) {
	    if (y != j || x != i) {
		count += cell_value(*cell_at(f, i, j), f->max_age);
	    }
	}
    }

    p = cell_at(f, x, y);
    if (*p) {
	if (count == 2 || count == 3) {
	    return ((*p) + 1);
	} else {
	    return (0);
	}
    } else {
	if (count == 3) {
	    return (1);
	} else {
	    return (0);
	}
    }
}
Exemple #2
0
int main(int argc, char** argv){

    char* path = NULL;
    char buffer[MAXSIZE] = {0};

    int fullOffset = 0;
    int lineNumber = 0;

    char str1[MAXSEQUENCE] = {0};
    char str2[MAXSEQUENCE] = {0};

    struct NWArray myarray;

    if(argc > 2){
        printf("Error too many arguments\n");
        return 1;
    }else if(argc == 2){
        path = argv[1];
        printf("Text file is : %s \n", path);
        printf("\n");
    }else if(argc < 2){
        printf("Error not enough arguments, path of text file is missing\n");
        return 1;
    }

    int sizeRead = 0;
    do{

// Acquisition of one line of "path" file in a buffer
        if((sizeRead = readLine(path, fullOffset, buffer, MAXSIZE) ) < 1){
            printf("This is the end of our program\n");
            break;
        }
        printf("Iteration : %d\nAcquired line is : %s\n", ++lineNumber, buffer);

// Separation of this buffer (according to " | ") in two strings
        parseLine(buffer, sizeRead, str1, str2, MAXSEQUENCE);

        fullOffset += sizeRead;

        printf("\t str1= %s", str1);
        printf("\t str2= %s\n", str2);


// Needleman Wunsh algorithm
        initArray(&myarray, strlen(str1)+1, strlen(str2)+1);
        NWAlgo(&myarray, str1, str2);
        printNW(&myarray);
        printf("The maximum combinaison that can be obtained is : ");
        printf("%d\n", cell_value(getCellXY(&myarray, strlen(str1), strlen(str2))));
        printf("\n");
        printf("-----------------------------------------------------------\n");
        printf("\n");
        destroyArray(&myarray);

    }while(sizeRead != 0);

    return 0;
}
VALUE method_next_state(VALUE self, VALUE state, VALUE rule) {
  VALUE next_state = method_dup_state(self, state);
  int height = (int)RARRAY_LEN(state);
  int width  = (int)RARRAY_LEN(rb_ary_entry(state, 0));
  for(int row = 0; row < height; row++) {
      VALUE row_array = rb_ary_entry(next_state, row);
      for(int col = 0; col < width; col++) {
          int new_value = cell_value(rule, neighbor_population_of(state, col, row));
          if(new_value == -1) {
            continue;
          }
          rb_ary_store(row_array, col, INT2FIX(new_value));
      }
  }
  return next_state;
}