// turns all plains/desert into new things void complete_map(void) { int iter; for (iter = 0; iter < USE_SIZE; ++iter) { switch (grid[iter].type) { case PLAINS: { if (number(0, 3) == 0) { change_grid(iter, TEMPERATE_CROP); } else { change_grid(iter, FOREST); } // nothing stays plains break; } case DESERT: { if (number(0, 74) == 0) { change_grid(iter, OASIS); } else if (number(0, 24) == 0) { change_grid(iter, DESERT_CROP); } else if (number(0, 3) == 0) { change_grid(iter, GROVE); } // most spaces remain desert break; } } } }
// overwrites the top and bottom edges of the map with tundra void add_tundra(void) { int iter; // find edge tiles for (iter = 0; iter < USE_SIZE; ++iter) { if (Y_COORD(iter) < TUNDRA_HEIGHT + (!number(0, 2) ? 1 : 0)) { change_grid(iter, TUNDRA); } else if (Y_COORD(iter) >= (USE_HEIGHT - TUNDRA_HEIGHT - (!number(0, 2) ? 1 : 0))) { change_grid(iter, TUNDRA); } } }
/* Add a splotch of a given sect in a nice splotchy shape */ void splotch(int room, int type, struct island_data *isle) { int i, j, last_s, last_n, a, b, width_e, width_w, width_n, width_s; int loc, sect = PLAINS; if (sect == DESERT) { width_e = number(1, 3); width_w = number(1, 3); } else { width_e = number(2, 8); width_w = number(2, 8); } a = last_n = width_n = number((sect == DESERT ? 1 : 2), width_e); b = last_s = width_s = number((sect == DESERT ? 1 : 2), width_e); for (j = 0; j <= width_e; j++) { for (i = 0; i <= last_n; i++) { if ((loc = shift(room, j, i)) != -1 && grid[loc].type == sect) { change_grid(loc, type); } } for (i = 0; i <= last_s; i++) { if ((loc = shift(room, j, -i)) != -1 && grid[loc].type == sect) { change_grid(loc, type); } } last_n += number(last_n <= 0 ? 0 : -2, ((width_e - j) < last_n) ? -2 : 2); last_s += number(last_s <= 0 ? 0 : -2, ((width_e - j) < last_s) ? -2 : 2); } last_n = a; last_s = b; for (j = 0; j <= width_w; j++) { for (i = 0; i <= last_n; i++) { if ((loc = shift(room, -j, i)) != -1 && grid[loc].type == sect) { change_grid(loc, type); } } for (i = 0; i <= last_s; i++) { if ((loc = shift(room, -j, -i)) != -1 && grid[loc].type == sect) { change_grid(loc, type); } } last_n += number(last_n <= 0 ? 0 : -2, ((width_w - j) < last_n) ? -2 : 2); last_s += number(last_s <= 0 ? 0 : -2, ((width_w - j) < last_s) ? -2 : 2); } }
/* Add land to an island */ void land_mass(struct island_data *isle, int min_radius, int max_radius) { int i, j, last_s, last_n, a, b, loc; int sect = PLAINS; /* Island's heart */ change_grid(isle->loc, sect); isle->width[EAST] = number(min_radius, max_radius); isle->width[WEST] = number(min_radius, max_radius); a = last_n = isle->width[NORTH] = number(min_radius, MIN(isle->width[EAST], isle->width[WEST])); b = last_s = isle->width[SOUTH] = number(min_radius, MIN(isle->width[EAST], isle->width[WEST])); for (j = 0; j <= isle->width[EAST]; j++) { for (i = 0; i <= last_n; i++) { if ((loc = shift(isle->loc, j, i)) != -1) { change_grid(loc, sect); } } for (i = 0; i <= last_s; i++) { if ((loc = shift(isle->loc, j, -i)) != -1) { change_grid(loc, sect); } } last_n += number(last_n <= 0 ? 0 : -2, ((isle->width[EAST] - j) < last_n) ? -2 : 2); last_s += number(last_s <= 0 ? 0 : -2, ((isle->width[EAST] - j) < last_s) ? -2 : 2); } last_n = a; last_s = b; for (j = 0; j <= isle->width[WEST]; j++) { for (i = 0; i <= last_n; i++) { if ((loc = shift(isle->loc, -j, i)) != -1) { change_grid(loc, sect); } } for (i = 0; i <= last_s; i++) { if ((loc = shift(isle->loc, -j, -i)) != -1) { change_grid(loc, sect); } } last_n += number(last_n <= 0 ? 0 : -2, ((isle->width[WEST] - j) < last_n) ? -2 : 2); last_s += number(last_s <= 0 ? 0 : -2, ((isle->width[WEST] - j) < last_s) ? -2 : 2); } }
/* Add a pass through a mountain (at random) */ void add_pass(struct island_data *isle) { int x, y, room, loc; int sect = PLAINS; do { x = number(-1, 1); y = number(-1, 1); } while (x == 0 && y == 0); room = find_border(isle, x, y); /* invert directions */ x *= -1; y *= -1; while (room != -1) { if (!terrains[grid[room].type].is_land) { return; } if (grid[room].type == PLAINS) { sect = PLAINS; } if (grid[room].type == DESERT) { sect = DESERT; } if (grid[room].type == MOUNTAIN) { change_grid(room, sect); } if ((loc = shift(room, 0, 1)) != -1 && grid[loc].type == MOUNTAIN) { change_grid(loc, sect); } if ((loc = shift(room, 1, 0)) != -1 && grid[loc].type == MOUNTAIN) { change_grid(loc, sect); } room = shift(room, x, y); } }
// changes plains to <type> in a pattern roughly between y-start and y-end // y_start and y_end are PERCENTAGES of the map height void add_latitude_terrain(int type, double y_start, double y_end) { int x, y, to; for (x = 0; x < USE_WIDTH; ++x) { for (y = 0; y < USE_HEIGHT; ++y) { to = MAP(x, y); if (grid[to].type == PLAINS) { if (IS_IN_Y_PRC_RANGE(y + number(-1, 1), y_start, y_end)) { change_grid(to, type); } } } } }
// adds a start location (tower) void add_start_points(void) { struct island_data *isle; int count = 0; for (isle = island_list; isle && count < NUM_START_POINTS; isle = isle->next) { if (!number(0, 2) && (grid[isle->loc].type == PLAINS || grid[isle->loc].type == FOREST || grid[isle->loc].type == DESERT)) { change_grid(isle->loc, TOWER); count++; } } // repeat until success if (count == 0) { add_start_points(); } }
/** * Convert terrain from one thing to another near other terrain. * * @param int from Terrain to convert from. * @param int to Terrain to convert to. * @param int near Terrain it must be near. * @param int dist Distance it must be within. */ void replace_near(int from, int to, int near, int dist) { int x, y, hor, ver, at, loc; int found; for (x = 0; x < USE_WIDTH; ++x) { for (y = 0; y < USE_HEIGHT; ++y) { at = MAP(x, y); if (grid[at].type == from) { found = 0; for (hor = -dist; hor <= dist && !found; ++hor) { for (ver = -dist; ver <= dist && !found; ++ver) { loc = shift(at, hor, ver); if (loc != -1 && grid[loc].type == near && compute_distance(X_COORD(at), Y_COORD(at), X_COORD(loc), Y_COORD(loc)) <= dist) { change_grid(at, to); found = 1; } } } } } } }
/*---------------- 6. The most important subroutine of the main: "time_loop" ---------------*/ void time_loop(ALLDATA *A){ clock_t tstart, tend; short en=0, wt=0, out; long i, sy, r, c, j, l; double t, Dt, JD0, JDb, JDe, W, th, th0; double Vout, Voutsub, Voutsup, Vbottom, C0, C1; FILE *f; //double mean; STATEVAR_3D *S=NULL, *G=NULL; SOIL_STATE *L, *C; STATE_VEG *V; DOUBLEVECTOR *a, *Vsup_ch, *Vsub_ch; S=(STATEVAR_3D *)malloc(sizeof(STATEVAR_3D)); allocate_and_initialize_statevar_3D(S, (double)number_novalue, A->P->max_snow_layers, Nr, Nc); if(A->P->max_glac_layers>0){ G=(STATEVAR_3D *)malloc(sizeof(STATEVAR_3D)); allocate_and_initialize_statevar_3D(G, (double)number_novalue, A->P->max_glac_layers, Nr, Nc); } L=(SOIL_STATE *)malloc(sizeof(SOIL_STATE)); initialize_soil_state(L, A->P->total_pixel, Nl); C=(SOIL_STATE *)malloc(sizeof(SOIL_STATE)); initialize_soil_state(C, A->C->r->nh, Nl); V=(STATE_VEG *)malloc(sizeof(STATE_VEG)); initialize_veg_state(V, A->P->total_pixel); a=new_doublevector(A->P->total_pixel); Vsub_ch=new_doublevector(A->C->r->nh); Vsup_ch=new_doublevector(A->C->r->nh); time( &start_time ); //periods i_sim = i_sim0; do{ //runs A->I->time = A->P->delay_day_recover*86400.;//Initialize time A->P->delay_day_recover = 0.; do{ if( A->I->time > (A->P->end_date->co[i_sim] - A->P->init_date->co[i_sim])*86400. - 1.E-5){ printf("Number of times the simulation #%ld has been run: %ld\n",i_sim,i_run); f=fopen(logfile, "a"); fprintf(f,"Number of times the simulation #%ld has been run: %ld\n",i_sim,i_run); fclose(f); print_run_average(A->S, A->T, A->P); i_run++; A->I->time = 0.0;//Initialize time A->M->line_interp_WEB_LR = 0; A->M->line_interp_Bsnow_LR = 0; for (i=1; i<=A->M->st->Z->nh; i++) { A->M->line_interp_WEB[i-1] = 0; A->M->line_interp_Bsnow[i-1] = 0; } if(i_run <= A->P->run_times->co[i_sim]){ reset_to_zero(A->P, A->S, A->L, A->N, A->G, A->E, A->M, A->W); init_run(A->S, A->P); } }else { //find time step from file or inpts set_time_step(A->P, A->I); //time at the beginning of the time step JD0 = A->P->init_date->co[i_sim]+A->I->time/secinday; //time step variables t = 0.; Dt = A->P->Dt; //time step subdivisions do{ JDb = A->P->init_date->co[i_sim]+(A->I->time+t)/secinday; if (t + Dt > A->P->Dt) Dt = A->P->Dt - t; //iterations do{ JDe = A->P->init_date->co[i_sim]+(A->I->time+t+Dt)/secinday; //copy state variables on copy_snowvar3D(A->N->S, S); copy_doublevector(A->N->age, a); if (A->P->max_glac_layers>0) copy_snowvar3D(A->G->G, G); copy_soil_state(A->S->SS, L); copy_soil_state(A->C->SS, C); copy_veg_state(A->S->VS, V); /*for (j=1; j<=A->W->H1->nh; j++) { l=A->T->lrc_cont->co[j][1]; r=A->T->lrc_cont->co[j][2]; c=A->T->lrc_cont->co[j][3]; printf("START %ld %ld %ld %e\n",l,r,c,A->S->SS->P->co[l][A->T->j_cont[r][c]]); }*/ //init initialize_doublevector(Vsub_ch, 0.); initialize_doublevector(Vsup_ch, 0.); Vout = 0.; Voutsub = 0.; Voutsup = 0.; Vbottom = 0.; //meteo tstart=clock(); meteo_distr(A->M->line_interp_WEB, A->M->line_interp_WEB_LR, A->M, A->W, A->T, A->P, JD0, JDb, JDe); tend=clock(); t_meteo+=(tend-tstart)/(double)CLOCKS_PER_SEC; if(A->P->en_balance == 1){ tstart=clock(); en = EnergyBalance(Dt, JD0, JDb, JDe, L, C, S, G, V, a, A, &W); tend=clock(); t_energy+=(tend-tstart)/(double)CLOCKS_PER_SEC; } if(A->P->wat_balance == 1 && en == 0){ tstart=clock(); wt = water_balance(Dt, JD0, JDb, JDe, L, C, A, Vsub_ch, Vsup_ch, &Vout, &Voutsub, &Voutsup, &Vbottom); tend=clock(); t_water+=(tend-tstart)/(double)CLOCKS_PER_SEC; } if (en != 0 || wt != 0) { if(Dt > A->P->min_Dt) Dt *= 0.5; out = 0; f = fopen(logfile, "a"); if (en != 0) { fprintf(f,"Energy balance not converging\n"); }else { fprintf(f,"Water balance not converging\n"); } fprintf(f,"Reducing time step to %f s, t:%f s\n",Dt,t); fclose(f); }else { out = 1; } //printf("Dt:%f min:%f\n",Dt,A->P->min_Dt); }while( out == 0 && Dt > A->P->min_Dt ); /*if (en != 0 || wt != 0) { f = fopen(FailedRunFile, "w"); fprintf(f, "Simulation Period:%ld\n",i_sim); fprintf(f, "Run Time:%ld\n",i_run); fprintf(f, "Number of days after start:%f\n",A->I->time/86400.); if (en != 0 && wt == 0) { fprintf(f, "ERROR: Energy balance does not converge, Dt:%f\n",Dt); }else if (en == 0 && wt != 0) { fprintf(f, "ERROR: Water balance does not converge, Dt:%f\n",Dt); }else { fprintf(f, "ERROR: Water and energy balance do not converge, Dt:%f\n",Dt); } fclose(f); t_error("Fatal Error! Geotop is closed. See failing report."); }*/ if (en != 0 || wt != 0) { //f = fopen(FailedRunFile, "w"); f = fopen(logfile, "a"); //fprintf(f, "Simulation Period:%ld\n",i_sim); //fprintf(f, "Run Time:%ld\n",i_run); //fprintf(f, "Number of days after start:%f\n",A->I->time/86400.); if (en != 0 && wt == 0) { fprintf(f, "WARNING: Energy balance does not converge, Dt:%f\n",Dt); }else if (en == 0 && wt != 0) { fprintf(f, "WARNING: Water balance does not converge, Dt:%f\n",Dt); }else { fprintf(f, "WARNING: Water and energy balance do not converge, Dt:%f\n",Dt); } fclose(f); //t_error("Fatal Error! Geotop is closed. See failing report."); } t += Dt; if (A->P->state_pixel == 1 && A->P->dUzrun == 1) { for (j=1; j<=A->P->rc->nrh; j++) { for (l=1; l<=Nl; l++){ r = A->P->rc->co[j][1]; c = A->P->rc->co[j][2]; sy = A->S->type->co[r][c]; th = theta_from_psi(A->S->SS->P->co[l][A->T->j_cont[r][c]], A->S->SS->thi->co[l][A->T->j_cont[r][c]], l, A->S->pa->co[sy], PsiMin); if(th > A->S->pa->co[sy][jsat][l]-A->S->SS->thi->co[l][A->T->j_cont[r][c]]) th = A->S->pa->co[sy][jsat][l]-A->S->SS->thi->co[l][A->T->j_cont[r][c]]; C0 = A->S->pa->co[sy][jct][l]*(1.-A->S->pa->co[sy][jsat][l])*A->S->pa->co[sy][jdz][l] + c_ice*A->S->SS->thi->co[l][A->T->j_cont[r][c]] + c_liq*th; th0 = th; th = theta_from_psi(L->P->co[l][A->T->j_cont[r][c]], L->thi->co[l][A->T->j_cont[r][c]], l, A->S->pa->co[sy], PsiMin); if(th > A->S->pa->co[sy][jsat][l]-L->thi->co[l][A->T->j_cont[r][c]]) th = A->S->pa->co[sy][jsat][l]-L->thi->co[l][A->T->j_cont[r][c]]; C1 = A->S->pa->co[sy][jct][l]*(1.-A->S->pa->co[sy][jsat][l])*A->S->pa->co[sy][jdz][l] + c_ice*L->thi->co[l][A->T->j_cont[r][c]] + c_liq*th; A->S->dUzrun->co[j][l] += 1.E-6*( 0.5*(C0+C1)*(L->T->co[l][A->T->j_cont[r][c]] - A->S->SS->T->co[l][A->T->j_cont[r][c]]) + Lf*(th-th0)*A->S->pa->co[sy][jdz][l] ); } } } //write state variables copy_snowvar3D(S, A->N->S); copy_doublevector(a, A->N->age); if (A->P->max_glac_layers>0) copy_snowvar3D(G, A->G->G); copy_soil_state(L, A->S->SS); copy_soil_state(C, A->C->SS); copy_veg_state(V, A->S->VS); add_doublevector(Vsub_ch, A->C->Vsub); add_doublevector(Vsup_ch, A->C->Vsup); A->C->Vout += Vout; A->W->Voutbottom += Vbottom; A->W->Voutlandsub += Voutsub; A->W->Voutlandsup += Voutsup; //printf("%f\n",A->I->time); //record time step odb[ootimestep] = Dt * (Dt/A->P->Dtplot_basin->co[i_sim]); //write output variables fill_output_vectors(Dt, W, A->E, A->N, A->G, A->W, A->M, A->P, A->I, A->T, A->S); //reset Dt if (Dt < A->P->Dt) Dt *= 2.; }while(t < A->P->Dt); if(A->P->blowing_snow==1){ tstart=clock(); windtrans_snow(A->N, A->M, A->W, A->L, A->T, A->P, A->I->time); tend=clock(); t_blowingsnow+=(tend-tstart)/(double)CLOCKS_PER_SEC; } tstart=clock(); write_output(A->I, A->W, A->C, A->P, A->T, A->L, A->S, A->E, A->N, A->G, A->M); tend=clock(); t_out+=(tend-tstart)/(double)CLOCKS_PER_SEC; A->I->time += A->P->Dt;//Increase TIME } }while(i_run <= A->P->run_times->co[i_sim]);//end of time-cycle if (A->P->newperiodinit != 0) end_period_1D(A->S, A->T, A->P); if (i_sim < A->P->init_date->nh) change_grid(i_sim, i_sim+1, A->P, A->T, A->L, A->W, A->C); reset_to_zero(A->P, A->S, A->L, A->N, A->G, A->E, A->M, A->W); init_run(A->S, A->P); i_sim++; i_run0 = 1; i_run = i_run0; }while (i_sim <= A->P->init_date->nh); deallocate_statevar_3D(S); if(A->P->max_glac_layers>0) deallocate_statevar_3D(G); deallocate_soil_state(L); deallocate_soil_state(C); deallocate_veg_state(V); free_doublevector(a); free_doublevector(Vsub_ch); free_doublevector(Vsup_ch); }
/* Add a river to the island */ void add_river(struct island_data *isle) { int x, y, room; int hor, ver, to; int found = 0; clear_pass(); do { x = number(-1, 1); y = number(-1, 1); } while (x == 0 && y == 0); room = find_border(isle, x, y); /* invert directions */ x *= -1; y *= -1; while (room != -1) { if (!terrains[grid[room].type].is_land) return; change_grid(room, RIVER); grid[room].pass = 1; for (hor = number(-1, 0); hor <= 1; ++hor) { for (ver = number(-1, 0); ver <= 1; ++ver) { if (hor == 0 && ver == 0) { // safe to skip self continue; } to = shift(room, hor, ver); if (to != -1) { // if we hit another river, stop AFTER this sect if (grid[to].type == RIVER && grid[to].pass == 0) { found = 1; } if (terrains[grid[to].type].is_land) { change_grid(to, RIVER); grid[to].pass = 1; } } } } if (found) { return; } /* Alter course */ if (!number(0, 2)) { if (x == 0) x += number(-1, 1); else if (y == 0) y += number(-1, 1); else if (x > 0 && y > 0) { if ((y -= number(0, 1))) x -= number(0, 1); } else if (x < 0 && y < 0) { if ((y += number(0, 1))) x += number(0, 1); } else if (x < 0 && y > 0) { if ((y -= number(0, 1))) x += number(0, 1); } else if (y < 0 && x > 0) { if ((y += number(0, 1))) x -= number(0, 1); } // verify bounds to prevent leaps x = MAX(-1, MIN(x, 1)); y = MAX(-1, MIN(y, 1)); } room = shift(room, x, y); } }
/* Add a mountain range to an island */ void add_mountains(struct island_data *isle) { int x, y, room; int hor, ver, to; int found = 0; clear_pass(); do { x = number(-1, 1); y = number(-1, 1); } while (x == 0 && y == 0); room = find_border(isle, x, y); /* invert directions */ x *= -1; y *= -1; while (room != -1) { if (!terrains[grid[room].type].is_land) return; if (grid[room].type == MOUNTAIN && grid[room].pass == 0) { return; } if (grid[room].type == PLAINS) { change_grid(room, MOUNTAIN); } grid[room].pass = 1; for (hor = -2; hor <= 2; ++hor) { for (ver = -2; ver <= 2; ++ver) { // skip the corners to make a "rounded brush" if (((hor == ver) || (hor == -1 * ver)) && (hor == -2 || hor == 2)) { continue; } to = shift(room, hor, ver); if (to != -1 && number(0, 10) && grid[to].type == PLAINS) { // if we find a mountain that already exists, we stop AFTER this round if (grid[to].type == MOUNTAIN && grid[to].pass == 0) { found = 1; } change_grid(to, MOUNTAIN); grid[to].pass = 1; } } } // break out if (found) { return; } /* Alter course */ if (!number(0, 4)) { if (x == 0) x += number(-1, 1); else if (y == 0) y += number(-1, 1); else if (x > 0 && y > 0) { if ((y -= number(0, 1))) x -= number(0, 1); } else if (x < 0 && y < 0) { if ((y += number(0, 1))) x += number(0, 1); } else if (x < 0 && y > 0) { if ((y -= number(0, 1))) x += number(0, 1); } else if (y < 0 && x > 0) { if ((y += number(0, 1))) x -= number(0, 1); } } room = shift(room, x, y); } }
void load_and_shift_map(int dist) { char fname[256], line[1024]; FILE *index, *wld; int block, vnum, island, type, junk; // nowork if (dist == 0) { printf("Shift by distance 0: no work to do.\n"); return; } init_grid(); printf("Loaded existing map...\n"); // load in existing map if (!(index = fopen("index", "r"))) { printf("ERROR: Unable to load index file.\n"); exit(1); } while (fscanf(index, "%d.wld\n", &block) == 1) { sprintf(fname, "%d.wld", block); printf("Loading file %s ...\n", fname); if (!(wld = fopen(fname, "r"))) { printf("ERROR: Unable to open world file %s.\n", fname); exit(1); } while (get_line(wld, line)) { if (*line == '$') { break; } else if (*line == '#') { // found entry vnum = atoi(line + 1); if (!get_line(wld, line) || sscanf(line, "%d %d %d", &island, &type, &junk) != 3) { printf("Error reading room #%d\n", vnum); exit(1); } change_grid(vnum, sect_to_terrain(type)); grid[vnum].island_id = island; // trailing 'S' line get_line(wld, line); } else { printf("Unknown line in %s: %s\n", fname, line); exit(1); } } } shift_map_x(dist); print_map_graphic(); print_map_to_files(); printf("Map shifted %d on X-axis.\n", dist); output_stats(); }
// sets up island numbers and converts trapped ocean to lake void number_islands_and_fix_lakes(void) { int first_ocean_done = FALSE, changed = FALSE; struct num_data_t *ndt; int old, x, y, pos; int iter, use_id, use_land; int top_id = 0; // initialize for (iter = 0; iter < USE_SIZE; ++iter) { grid[iter].island_id = 0; // anything that stays zero will be made a lake } // find and create basic stack for (iter = 0; iter < USE_SIZE; ++iter) { if (grid[iter].island_id == 0) { if (terrains[grid[iter].type].is_land) { use_id = ++top_id; use_land = TRUE; } else if (!first_ocean_done) { // non-land use_id = -1; use_land = FALSE; first_ocean_done = TRUE; } else { continue; // skip } old = grid[iter].island_id; push_ndt(iter); while ((ndt = pop_ndt())) { grid[ndt->loc].island_id = use_id; for (x = -1; x <= 1; ++x) { for (y = -1; y <= 1; ++y) { if (x != 0 || y != 0) { pos = shift(ndt->loc, x, y); if (pos != -1 && grid[pos].island_id == old && terrains[grid[pos].type].is_land == use_land) { push_ndt(pos); } } } } free(ndt); } } } // now find unreachable land and turn to lake for (iter = 0; iter < USE_SIZE; ++iter) { if (grid[iter].island_id == 0) { change_grid(iter, LAKE); changed = TRUE; } } // should only take 1 second time if (changed) { number_islands_and_fix_lakes(); } }
int main() { const std::string gol_name = "Game of Life Mini V0.2"; const int delaz = 100; assert(delaz > 0); const std::chrono::milliseconds delay(delaz); const int x_size = 80, y_size = 80; const bool term = false, sfml = true; assert(x_size > 2); assert(x_size <= 100); assert(y_size > 2); assert(y_size <= 100); assert(generation_loop > 0); const int dot_size = 8; const int window_x = x_size*dot_size, window_y = y_size*dot_size; assert(x_size > 0); assert(y_size > 0); std::vector < std::vector<int>> life_grid(y_size, std::vector<int>(x_size, 0)); std::vector < std::vector<int>> change_grid(y_size, std::vector<int>(x_size, 0)); initialize_grid(life_grid); for (int pos = 0; pos < y_size; ++pos) { life_grid[pos][pos] = 1; life_grid[y_size - 1 - pos][pos] = 1; } const std::string life_dot_img = "Life_Dot.png"; sf::Texture life_dot_tex; if (!life_dot_tex.loadFromFile(life_dot_img)) { std::cout << life_dot_img << " not found!\n"; } sf::Sprite life_dot_sprite; life_dot_sprite.setTexture(life_dot_tex); sf::RenderWindow window(sf::VideoMode(window_x, window_y), gol_name, sf::Style::Default); int cur_gen = 0; while (window.isOpen()) { if (sfml) { show_grid_sfml(life_grid, window, life_dot_sprite, dot_size); } if (term) { show_grid_term(life_grid, cur_gen); } next_generation(life_grid, change_grid); life_grid = change_grid; ++cur_gen; std::this_thread::sleep_for(delay); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { window.close(); return 1; } } return 0; }