Beispiel #1
0
void print_board(world *w){
    for (int j=0; j<w->N; j++){
        for (int i=0; i<w->N; i++){
            int ind = xy2ind(w->N, i, j); 
            int ind2 = xy2ind(w->N, mod(i+1, w->N), j);
            printf("%c", SYMBOLS[(int)w->grid[ind]]);

            if (w->bondgrid[inds2bond(w->N, ind, ind2)] >= 0)
                printf(" - ");
            else
                printf("   ");
        }
        printf("\n");
        for (int i=0; i<w->N; i++){
            int ind = xy2ind(w->N, i, j); 
            int ind2 = xy2ind(w->N, i, mod(j+1, w->N));

            if (w->bondgrid[inds2bond(w->N, ind, ind2)] >= 0)
                printf("|   ");
            else
                printf("    ");
        }
        printf("\n");
    }
}
Beispiel #2
0
void add_zombie(world *w, int x, int y){
    int ind0 = xy2ind(w->N, x, y);
    if (w->grid[ind0] == SZ)
        return;
    else {
        w->grid[ind0] = SZ;
        w->S -= 1;
        w->Z += 1;

        w->sites[w->nsites] = ind0;
        w->nsites += 1;
        if (w->minx > x) w->minx = x;
        if (w->miny > y) w->miny = y;
        if (w->maxx < x) w->maxx = x;
        if (w->maxy < y) w->maxy = y;
    }

    for (int i=-1; i<=1; i+=2){
        int ind1 = xy2ind(w->N, mod(x+i, w->N), y);
        add_bond(w, ind0, ind1);
    }
    for (int i=-1; i<=1; i+=2){
        int ind1 = xy2ind(w->N, x, mod(y+i, w->N));
        add_bond(w, ind0, ind1);
    }
}
Beispiel #3
0
void save_xpm(world *w, char *filename){
    char header[] = "/* XPM */\nstatic char *mypic[] = {\n\"%i %i 3 1\",\n\". c #000000\",\n\"X c #FF0000\",\n\"  c #FFFFFF\",\n";
    char *contents = malloc(sizeof(char)*(w->N*(w->N+4) + 1280));

    int mins[] = {w->N/2-1, w->N/2-1};
    int maxs[] = {w->N/2+1, w->N/2+1};
    for (int j=0; j<w->N; j++){
        for (int i=0; i<w->N; i++){
            if (w->grid[xy2ind(w->N, i, j)] != SS){
                if (mins[0] > i) mins[0] = i;
                if (mins[1] > j) mins[1] = j;
                if (maxs[0] < i) maxs[0] = i;
                if (maxs[1] < j) maxs[1] = j;
            }
        }
    }

    printf("%i %i | %i %i\n", mins[0], maxs[0], mins[1], maxs[1]);
    int cursor = sprintf(contents, header, maxs[0]-mins[0], maxs[1]-mins[1]);
    for (int j=mins[1]; j<maxs[1]; j++){
        contents[cursor] = '\"'; 
        cursor++;

        for (int i=mins[0]; i<maxs[0]; i++){
            contents[cursor] = SYMBOLS[(int)w->grid[xy2ind(w->N, i, j)]];
            cursor++;
        }

        contents[cursor] = '\"'; cursor++;
        contents[cursor] = ','; cursor++;
        contents[cursor] = '\n'; cursor++;
    }
    contents[cursor-2] = '\n';
    contents[cursor-1] = '}';
    contents[cursor+0] = '\n';
    contents[cursor+1] = '\0';

    FILE *f = fopen(filename, "w");
    fprintf(f, "%s", contents);
    fclose(f);

    free(contents);
}
Beispiel #4
0
void kill_site(world *w, int x, int y){
    int ind0 = xy2ind(w->N, x, y);
    if (w->grid[ind0] != SZ)
        return;
    else {
        w->grid[ind0] = SR;
        w->Z -= 1;
        w->R += 1;

        w->sites[w->nsites] = ind0;
        w->nsites += 1;
    }

    for (int i=-1; i<=1; i+=2){
        int ind1 = xy2ind(w->N, mod(x+i, w->N), y);
        remove_bond(w, w->bondgrid[inds2bond(w->N, ind0, ind1)]);
    }
    for (int i=-1; i<=1; i+=2){
        int ind1 = xy2ind(w->N, x, mod(y+i, w->N));
        remove_bond(w, w->bondgrid[inds2bond(w->N, ind0, ind1)]);
    }
}
Beispiel #5
0
void bond2inds(int N, int b, int *ind0, int *ind1){
    int factor = N*N;
    int level = b / factor;
    *ind0 = mod(b, factor);

    int x0, y0, x1, y1;
    ind2xy(N, *ind0, &x0, &y0);

    x1 = mod(x0 - 1*(level==0) + 1*(level==1), N);
    y1 = mod(y0 - 1*(level==2) + 1*(level==3), N);
    *ind1 = xy2ind(N, x1, y1);

    if (*ind0 > *ind1) iswap(*ind0, *ind1);
}
Beispiel #6
0
int safssi_stdat(struct latlon gpos, fmproj myproj,
	osihdf *safssi, safssi_data *ssi) {

    int dx, dy, i, j, k, l, m;
    int nodata = 1;
    struct dto timeid;
    struct xy xyp;
    fmposxy tgxy;
    fmindxy tgin;
    fmposll tgll;
    fmimage rim;

    /*
     * Convert from image header to useable data structures, first
     * satellite id.
     */
    sprintf((*ssi).source,"%s", safssi->h.source);

    /*
     * The UCS info is converted
     */
    rim.Ax = safssi->h.Ax;
    rim.Ay = safssi->h.Ay;
    rim.Bx = safssi->h.Bx;
    rim.By = safssi->h.By;
    rim.iw = safssi->h.iw;
    rim.ih = safssi->h.ih;

    (*ssi).nav.Ax = rim.Ax;
    (*ssi).nav.Ay = rim.Ay;

    /*
     * Set UNIX time for product
     */
    timeid.mi = safssi->h.minute;
    timeid.ho = safssi->h.hour;
    timeid.dd = safssi->h.day;
    timeid.mm = safssi->h.month;
    timeid.yy = safssi->h.year;
    (*ssi).vtime = dto2unixtime(timeid);;

    /*
     * Get UCS position of the requested geographical position within the
     * image.
     */
    tgll.lat = (double) gpos.lat;
    tgll.lon = (double) gpos.lon;
    tgxy = ll2xy(tgll, myproj) ;
    tgin = xy2ind(rim, tgxy);
    if (tgin.x < 0 || tgin.y < 0) return(3);
    (*ssi).nav.Bx = (float) tgxy.x;
    (*ssi).nav.By = (float) tgxy.y;

    /*
     * Check bounding box size, these parameters are set by the init
     * function...
     */
    if ((*ssi).nav.iw%2 == 0 || (*ssi).nav.ih%2 == 0) {
	error("avhrr_stdat","area required must be odd\n");
	return(2); 
    }

    /*
     * Collect the actual data, l is used for pixel count within the
     * actual image, and k within the storage tile.
     */
    dx = (int) floorf((float) (*ssi).nav.iw/2.);
    dy = (int) floorf((float) (*ssi).nav.ih/2.);
    k = 0;
    for (i=(tgin.y-dy); i<=(tgin.y+dy); i++) {
	for (j=(tgin.x-dx); j<=(tgin.x+dx); j++) {
	    /*
	     * Check if within image coverage...
	     */
	    if (i < 0 || j < 0 || i >= rim.ih || j >= rim.iw) continue;
	    /*
	     * Navigation is performed in 2D while data is stored in 1D...
	     */
	    l = ivec(j,i,rim.iw);
	    /*
	     * Collect data...
	     */
	    (*ssi).data[k] = ((float *) safssi->d[0].data)[l];
	    (*ssi).qflg[k] = ((unsigned short *) safssi->d[1].data)[l];
		
	    k++;
	}
    }

    return(0);
}