void partitioning<Grid>::read_partition(std::istream& in) { int p; partial_mapping<int,int> part_nums(-1); CellIterator C = TheGrid().FirstCell(); char c; in >> c; in.putback(c); if(isdigit(c)) { while(in && ! C.IsDone()) { in >> p; int np = ranges.size()-1; //NumOfPartitions(); for( int pp = 0; pp <= p - np; ++pp) add_partition(); // if( part_nums(p) == -1) { // part_nums[p] = add_partition(); // } add_cell(p,*C); ++C; } if(!in && ! C.IsDone()) { std::cerr << "partitioning<Grid>::read_partition(): input ended prematurely!\n" << "creating new partition for the remaining cells.\n"; p = add_partition(); while(! C.IsDone()) { add_cell(p,*C); ++C; } } } else {
END_TEST START_TEST (test_copy_cell) { apr_pool_t* pool = NULL; apr_pool_create(&pool, NULL); cell* parent = sexpr_cell(pool); cell* childa = sym_cell(pool, "a"); cell* childb = sym_cell(pool, "b"); cell* childc = sym_cell(pool, "c"); add_cell(pool, parent, childc); add_cell(pool, parent, childb); add_cell(pool, parent, childa); cell* clone = copy_cell(pool, parent); ck_assert_int_eq(3, clone->count); cell* clonec = pop_cell(pool, clone, 0); ck_assert_ptr_ne(clonec, childc); ck_assert_str_eq(clonec->sym, childc->sym); cell* cloneb = pop_cell(pool, clone, 0); ck_assert_ptr_ne(cloneb, childb); ck_assert_str_eq(cloneb->sym, childb->sym); cell* clonea = pop_cell(pool, clone, 0); ck_assert_ptr_ne(clonea, childa); ck_assert_str_eq(clonea->sym, childa->sym); ck_assert_int_eq(0, clone->count); apr_pool_destroy(pool); }
void row::add_cell(const cell &cell, const string &name) { const auto index = _cells.size(); add_cell(cell); _map[name] = boost::numeric_cast<int>(index); }
int is_correct_syntax(const char *str, t_node **list, t_type *type) { char **split; int ret; if ((ret = is_correct_syntax2(str, type))) return (ret); split = ft_strsplit(str, ' '); if (tablen(split) == 3 && !ft_contain(split[0], '-') && !name_exist(*list, split[0])) { add_cell(list, split, *type); freetab(split); return (NODE); } else if (tablen(split) == 1) ret = is_correct_syntax3(str, split, list); if (ret == EDGE) return (ret); else { ft_putstr_fd("Syntax error : ", 2); ft_putendl_fd(str, 2); } freetab(split); return (FALSE); }
void set_result(const std::string& cell_name, const std::string& cell_content, const std::string& table_name, const std::string& row_name, const std::string& type_name) { loader.instantiate(); const boost::regex e("\\[template\\s+" + cell_name + "\\[\\]([^\\n]*)\\]$"); boost::smatch what; if(regex_search(content, what, e)) { content.replace(what.position(1), what.length(1), cell_content); } else { // Need to add new content: std::string::size_type pos = content.find("[/Cell Content:]"); std::string t = "\n[template " + cell_name + "[] " + cell_content + "]"; if(pos != std::string::npos) content.insert(pos + 16, t); else { content.insert(0, t); content.insert(0, "[/Cell Content:]"); } } // // Check to verify that our content is actually used somewhere, // if not we need to create a place for it: // if(content.find("[" + cell_name + "]") == std::string::npos) add_cell(cell_name, table_name, row_name, type_name); }
~content_loader() { boost::interprocess::named_mutex mu(boost::interprocess::open_or_create, "handle_test_result"); boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(mu); boost::filesystem::path p(__FILE__); p = p.parent_path(); p /= "doc"; p /= "performance_tables.qbk"; path_to_content = p; if(boost::filesystem::exists(p)) { boost::filesystem::ifstream is(p); if(is.good()) { do { char c = static_cast<char>(is.get()); if(c != EOF) content.append(1, c); } while(is.good()); } } // // Now iterate through results and add them one at a time: // for(auto i = items_to_add.begin(); i != items_to_add.end(); ++i) { add_cell(static_cast<boost::uintmax_t>(std::get<0>(*i) / 1e-9), std::get<1>(*i), std::get<2>(*i), std::get<3>(*i)); } // // Write out the results: // boost::filesystem::ofstream os(path_to_content); os << content; }
int user_action(char board1[BOARD_SIZE][BOARD_SIZE], char board2[BOARD_SIZE][BOARD_SIZE], char user) { switch (user) { case 'a': add_cell(board2) ; break ; case 'r': remove_cell(board2) ; break ; case 'n': apply_rules(board1, board2) ; break ; case 'q': return 0 ; case 'p': while (1) { apply_rules(board1, board2) ; copy_board(board1, board2) ; printf("\033[2J\033[H") ; usleep(500000) ; print_board(board1) ; } } return 1 ; }
BOOL cpy_cell(PWumf *l, PWumf w) { PWumf w1 = new_wumf(w->dwID, w->szUser, w->szPath, w->szComp,w->szUNC, w->dwSess, w->dwPerm, w->dwAttr); if (!w1) return FALSE; w1->mark = w->mark; return add_cell(l, w1); }
void compute_floorplan (void) { coor footprint; /* footprint of initial board is zero */ footprint[0] = 0; footprint[1] = 0; bots_message("Computing floorplan "); #pragma omp parallel { #pragma omp single #if defined(MANUAL_CUTOFF) || defined(IF_CUTOFF) || defined(FINAL_CUTOFF) bots_number_of_tasks = add_cell(1, footprint, board, gcells,0); #else bots_number_of_tasks = add_cell(1, footprint, board, gcells); #endif } bots_message(" completed!\n"); }
static void process_interval_stats(stats_t stats_interval, GtkTreeIter *parent, GtkTreeIter *row) { double value; const char *unit; char value_str[40]; GtkTreeStore *store; store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(yearly_tree))); /* Year or month */ snprintf(value_str, sizeof(value_str), "%d", stats_interval.period); add_row_to_tree(store, value_str, 0, row, parent); /* Dives */ snprintf(value_str, sizeof(value_str), "%d", stats_interval.selection_size); add_cell_to_tree(store, value_str, 1, row); /* Total duration */ add_cell_to_tree(store, get_time_string(stats_interval.total_time.seconds, 0), 2, row); /* Average dive duration */ add_cell_to_tree(store, get_minutes(stats_interval.total_time.seconds / stats_interval.selection_size), 3, row); /* Shortest duration */ add_cell_to_tree(store, get_minutes(stats_interval.shortest_time.seconds), 4, row); /* Longest duration */ add_cell_to_tree(store, get_minutes(stats_interval.longest_time.seconds), 5, row); /* Average depth */ add_cell(store, row, stats_interval.avg_depth.mm, 6, TRUE); /* Smallest maximum depth */ add_cell(store, row, stats_interval.min_depth.mm, 7, TRUE); /* Deepest maximum depth */ add_cell(store, row, stats_interval.max_depth.mm, 8, TRUE); /* Average air consumption */ add_cell(store, row, stats_interval.avg_sac.mliter, 9, FALSE); /* Smallest average air consumption */ add_cell(store, row, stats_interval.min_sac.mliter, 10, FALSE); /* Biggest air consumption */ add_cell(store, row, stats_interval.max_sac.mliter, 11, FALSE); /* Average water temperature */ value = get_temp_units(stats_interval.min_temp, &unit); if (stats_interval.combined_temp && stats_interval.combined_count) { snprintf(value_str, sizeof(value_str), "%.1f %s", stats_interval.combined_temp / (stats_interval.combined_count * 1.0), unit); add_cell_to_tree(store, value_str, 12, row); } else { add_cell_to_tree(store, "", 12, row); } /* Coldest water temperature */ if (value > -100.0) { snprintf(value_str, sizeof(value_str), "%.1f %s\t", value, unit); add_cell_to_tree(store, value_str, 13, row); } else { add_cell_to_tree(store, "", 13, row); } /* Warmest water temperature */ value = get_temp_units(stats_interval.max_temp, &unit); if (value > -100.0) { snprintf(value_str, sizeof(value_str), "%.1f %s", value, unit); add_cell_to_tree(store, value_str, 14, row); } else { add_cell_to_tree(store, "", 14, row); } }
void process_file(SESSION_INFO_1 s_info, FILE_INFO_3 f_info) { PWumf w = fnd_cell(&list, f_info.fi3_id); if (!w) { w = new_wumf(f_info.fi3_id, f_info.fi3_username, f_info.fi3_pathname, s_info.sesi1_cname, NULL, 0, f_info.fi3_permissions, GetFileAttributes(f_info.fi3_pathname)); w->mark = FALSE; if (!add_cell(&list, w)) msg(TranslateT("Error memory allocation")); if (WumfOptions.PopupsEnabled) ShowWumfPopup(w); if (WumfOptions.LogToFile) LogWumf(w); } else w->mark = FALSE; }
static void add_cells(Sheet *sheet, const psiconv_sheet_cell_list psi_cells, const psiconv_formula_list psi_formulas, const GnmStyle *default_style) { psiconv_u32 i; psiconv_sheet_cell psi_cell; /* psiconv_lists are actually arrays, so this isn't inefficient. */ for (i = 0; i < psiconv_list_length(psi_cells); i++) { /* If psiconv_list_get fails, something is very wrong... */ if ((psi_cell = psiconv_list_get(psi_cells,i))) add_cell(sheet,psi_cell,psi_formulas, default_style); } }
void compute_floorplan (void) { #pragma omp_to_hclib { coor footprint; /* footprint of initial board is zero */ footprint[0] = 0; footprint[1] = 0; bots_message("Computing floorplan "); #pragma omp parallel { #pragma omp single bots_number_of_tasks = add_cell(1, footprint, board, gcells, 0); } bots_message(" completed!\n"); } }
END_TEST START_TEST (test_add_pop_cell) { apr_pool_t* pool = NULL; apr_pool_create(&pool, NULL); cell* parent = sexpr_cell(pool); cell* childa = sym_cell(pool, "a"); cell* childb = sym_cell(pool, "b"); cell* childc = sym_cell(pool, "c"); //we start with a childless parent ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 0)); ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 1)); ck_assert_int_eq(0, parent->count); //adding something increases the count add_cell(pool, parent, childa); ck_assert_int_eq(1, parent->count); //we popping off a cell that doesn't exist should return NULL and not change the count cell* popped1 = pop_cell(pool, parent, 1); ck_assert_int_eq(1, parent->count); ck_assert_ptr_eq(NULL, popped1); //now we pop off a cell that should exist cell* popped2 = pop_cell(pool, parent, 0); ck_assert_int_eq(0, parent->count); ck_assert_ptr_eq(childa, popped2); //now the parent should be empty ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 0)); add_cell(pool, parent, childb); add_cell(pool, parent, childa); ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 2)); ck_assert_ptr_eq(childb, pop_cell(pool, parent, 0)); ck_assert_ptr_eq(childa, pop_cell(pool, parent, 0)); ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 0)); add_cell(pool, parent, childc); add_cell(pool, parent, childb); add_cell(pool, parent, childa); ck_assert_int_eq(3, parent->count); ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 3)); ck_assert_ptr_eq(childb, pop_cell(pool, parent, 1)); ck_assert_ptr_eq(childc, pop_cell(pool, parent, 0)); ck_assert_ptr_eq(childa, pop_cell(pool, parent, 0)); ck_assert_ptr_eq(NULL, pop_cell(pool, parent, 0)); apr_pool_destroy(pool); }
int load_file(char *file_name){ FILE *f=NULL; int x, y; int cnt, cnt_x; int i; int a=0, b=0; char c; trace(4,"load_file %s\n",file_name); if((f=fopen(file_name,"r"))==NULL){ trace(1,"can't open file %s\n", file_name); return ERR_CANNOT_OPEN_FILE; } fscanf(f,"x = %d, y = %d ",&x,&y); trace(4,"x=%d, y=%d\n",x,y); cnt_x=x; do{ if( fscanf(f,"%d",&cnt)==0){ cnt=1; } trace(4,"cnt=%d ,all=%d\n",cnt,cnt_x); c=fgetc(f); trace(4,"c=%c\n",c); if(c=='o'){ cnt_x-=cnt; for(i=0;i<cnt;i++){ trace(3,"read cell - 1st=%d,2nd=%d\n",i+a,b); add_cell(b,i+a); } a+=cnt; } if(c=='b'){ cnt_x-=cnt; a+=cnt; } if(c=='$' || c=='!'){ a=0; b++; cnt_x=x; } } while(c!='!'); fclose(f); return SUCCESS; }
void next_turn(){ //cell_q=NULL; cell_q_size=0; int i; coord x, y, j; cell * it; death=birth=0; //printf("next turn\n"); for(i=0;i<NUM2*(NUM1+1);i++){ it=hash_t[i].head; // printf("\t i=%d\n",i); if(it==NULL){ continue; } while(it!=NULL ){ x=it->x; y=it->y; check_field(x+1,y); check_field(x+1,y+1); check_field(x+1,y-1); check_field(x-1,y); check_field(x-1,y+1); check_field(x-1,y-1); check_field(x,y+1); check_field(x,y-1); check_field(x,y); it=it->next; } } print_que(); for(j=0;j<cell_q_size;j++) if(cell_q[j].alive==1) add_cell(cell_q[j].x,cell_q[j].y); else del_cell(cell_q[j].x,cell_q[j].y); //free(cell_q); turn++; }
void next_turn(){ q=NULL; max_q=0; int i; coord x, y, j; cell_list * it; death=birth=0; //printf("next turn\n"); for(i=0;i<NUM2*(NUM1+1);i++){ it=ht[i].head; // printf("\t i=%d\n",i); if(it==NULL){ continue; } while(it!=NULL ){ x=it->x; y=it->y; check_field(x+1,y); check_field(x+1,y+1); check_field(x+1,y-1); check_field(x-1,y); check_field(x-1,y+1); check_field(x-1,y-1); check_field(x,y+1); check_field(x,y-1); check_field(x,y); it=it->next; } } print_que(); for(j=0;j<max_q;j++) if(q[j].alive==1) add_cell(q[j].x,q[j].y); else del_live(q[j].x,q[j].y); free(q); turn++; }
void row::add_cells(const vector<cell> &cells) { for (const cell &c : cells) add_cell(c); }
int add_cell(int id, coor FOOTPRINT, ibrd BOARD, struct cell *CELLS) { int i, j, nn, area, nnc,nnl; ibrd board; coor footprint, NWS[DMAX]; nnc = 0; nnl = 0; /* for each possible shape */ for (i = 0; i < CELLS[id].n; i++) { /* compute all possible locations for nw corner */ nn = starts(id, i, NWS, CELLS); nnl += nn; /* for all possible locations */ for (j = 0; j < nn; j++) { #pragma omp task untied private(board, footprint,area) \ firstprivate(NWS,i,j,id,nn) \ shared(FOOTPRINT,BOARD,CELLS,MIN_AREA,MIN_FOOTPRINT,N,BEST_BOARD,nnc,bots_verbose_mode) { struct cell cells[N+1]; memcpy(cells,CELLS,sizeof(struct cell)*(N+1)); /* extent of shape */ cells[id].top = NWS[j][0]; cells[id].bot = cells[id].top + cells[id].alt[i][0] - 1; cells[id].lhs = NWS[j][1]; cells[id].rhs = cells[id].lhs + cells[id].alt[i][1] - 1; memcpy(board, BOARD, sizeof(ibrd)); /* if the cell cannot be layed down, prune search */ if (! lay_down(id, board, cells)) { bots_debug("Chip %d, shape %d does not fit\n", id, i); } else { /* calculate new footprint of board and area of footprint */ footprint[0] = max(FOOTPRINT[0], cells[id].bot+1); footprint[1] = max(FOOTPRINT[1], cells[id].rhs+1); area = footprint[0] * footprint[1]; /* if last cell */ if (cells[id].next == 0) { /* if area is minimum, update global values */ if (area < MIN_AREA) { #pragma omp critical if (area < MIN_AREA) { MIN_AREA = area; MIN_FOOTPRINT[0] = footprint[0]; MIN_FOOTPRINT[1] = footprint[1]; memcpy(BEST_BOARD, board, sizeof(ibrd)); bots_debug("N %d\n", MIN_AREA); } } /* if area is less than best area */ } else if (area < MIN_AREA) { int val = add_cell(cells[id].next, footprint, board,cells); #pragma omp atomic nnc += val; /* if area is greater than or equal to best area, prune search */ } else { bots_debug("T %d, %d\n", area, MIN_AREA); } } } } } #pragma omp taskwait return nnc+nnl; }
ucxx2( ) { CBOXPTR acellptr , bcellptr ; TIBOXPTR atileptr , btileptr ; TEBOXPTR atermptr , btermptr ; int error_light_is_on ; int cost ; int aorient , borient ; int a1LoBin, a1HiBin, b1LoBin, b1HiBin ; int a2LoBin, a2HiBin, b2LoBin, b2HiBin ; int startxa1 , endxa1 , startxa2 , endxa2 ; int startxb1 , endxb1 , startxb2 , endxb2 ; int anbin , bnbin , i ; int truth ; double temp ; acellptr = carray[ a ] ; axcenter = acellptr->cxcenter ; aycenter = acellptr->cycenter ; aorient = acellptr->corient ; atileptr = acellptr->tileptr ; aleft = atileptr->left ; aright = atileptr->right ; atermptr = atileptr->termsptr ; bcellptr = carray[ b ] ; bxcenter = bcellptr->cxcenter ; bycenter = bcellptr->cycenter ; borient = bcellptr->corient ; btileptr = bcellptr->tileptr ; bleft = btileptr->left ; bright = btileptr->right ; btermptr = btileptr->termsptr ; newbinpenal = binpenal ; newrowpenal = rowpenal ; newpenal = penalty ; new_old( bright-bleft-aright+aleft ) ; find_new_pos() ; a1LoBin = SetBin( startxa1 = axcenter + aleft ) ; a1HiBin = SetBin( endxa1 = axcenter + aright ) ; b1LoBin = SetBin( startxb1 = bxcenter + bleft ) ; b1HiBin = SetBin( endxb1 = bxcenter + bright ) ; a2LoBin = SetBin( startxa2 = anxcenter + aleft ) ; a2HiBin = SetBin( endxa2 = anxcenter + aright ) ; b2LoBin = SetBin( startxb2 = bnxcenter + bleft ) ; b2HiBin = SetBin( endxb2 = bnxcenter + bright ) ; old_assgnto_new2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ; sub_penal( startxa1 , endxa1 , ablock , a1LoBin , a1HiBin ) ; sub_penal( startxb1 , endxb1 , bblock , b1LoBin , b1HiBin ) ; add_penal( startxa2 , endxa2 , bblock , a2LoBin , a2HiBin ) ; add_penal( startxb2 , endxb2 , ablock , b2LoBin , b2HiBin ) ; binpen_chg = newbinpenal - binpenal ; rowpen_chg = newrowpenal - rowpenal ; newpenal = (int)( roLenCon * (double) newrowpenal + binpenCon * (double) newbinpenal ) ; error_light_is_on = 0 ; if( newpenal - penalty > P_limit ) { if( potential_errors < 100 ) { ++potential_errors ; error_light_is_on = 1 ; } else { earlyRej++ ; return( -1 ) ; } } if( ablock != bblock ) { term_newpos_a( atermptr , anxcenter , bycenter , aorient ) ; term_newpos_b( btermptr , bnxcenter , aycenter , borient ) ; } else { term_newpos( atermptr , anxcenter , bycenter , aorient ) ; term_newpos( btermptr , bnxcenter , aycenter , borient ) ; } cost = funccost ; delta_vert_cost = 0 ; if( ablock != bblock ) { new_dbox_a( atermptr , &cost ) ; new_dbox_a( btermptr , &cost ) ; } else { new_dbox( atermptr , &cost ) ; new_dbox( btermptr , &cost ) ; } wire_chg = cost - funccost ; truth = acceptt(funccost + penalty - cost - newpenal - delta_vert_cost); if( truth == 1 ) { if( error_light_is_on ) { error_count++ ; } new_assgnto_old2( a1LoBin , a1HiBin , b1LoBin , b1HiBin , a2LoBin , a2HiBin , b2LoBin , b2HiBin ) ; if( ablock != bblock ) { dbox_pos_2( atermptr ) ; dbox_pos_2( btermptr ) ; } else { dbox_pos( atermptr ) ; dbox_pos( btermptr ) ; } anbin = SetBin( anxcenter ) ; bnbin = SetBin( bnxcenter ) ; if( cellaptr != cellbptr ) { remv_cell( cellaptr , Apost ) ; remv_cell( cellbptr , Bpost ) ; add_cell( &binptr[bblock][anbin]->cell , a ) ; add_cell( &binptr[ablock][bnbin]->cell , b ) ; } else { remv_cell( cellaptr , Apost ) ; for( i = 1 ; i <= *cellaptr ; i++ ) { if( cellaptr[i] == b ) { break ; } } remv_cell( cellaptr , i ) ; add_cell( &binptr[ablock][anbin]->cell , a ) ; add_cell( &binptr[ablock][bnbin]->cell , b ) ; } if( wire_chg < 0 ) { temp = (double) - wire_chg ; total_wire_chg += temp ; sigma_wire_chg += (temp - mean_wire_chg) * (temp - mean_wire_chg) ; wire_chgs++ ; } acellptr->cblock = bblock ; acellptr->cxcenter = anxcenter ; acellptr->cycenter = bycenter ; bcellptr->cblock = ablock ; bcellptr->cxcenter = bnxcenter ; bcellptr->cycenter = aycenter ; funccost = cost ; binpenal = newbinpenal ; rowpenal = newrowpenal ; penalty = newpenal ; if( ablock != bblock ) { barray[ablock]->oldsize = barray[ablock]->newsize ; barray[bblock]->oldsize = barray[bblock]->newsize ; } return( 1 ) ; } else { return( 0 ) ; } }
/** Set up a Grid_LonLat with a given specification. @param spherical_clip Only realize grid cells that pass this test (before projection). @see EuclidianClip, SphericalClip */ void Grid_LonLat::realize( boost::function<bool(double, double, double, double)> const &spherical_clip) // boost::function<bool(Cell const &)> const &euclidian_clip { // Error-check the input parameters if (south_pole && latb[0] == -90.0) { std::cerr << "latb[] cannot include -90.0 if you're including the south pole cap" << std::endl; throw std::exception(); } if (south_pole && latb.back() == 90.0) { std::cerr << "latb[] cannot include 90.0 if you're including the north pole cap" << std::endl; throw std::exception(); } clear(); // Set up to project lines on sphere (and eliminate duplicate vertices) VertexCache vcache(this); // LineProjector projector(proj, &vcache); // printf("Using projection: \"%s\"\n", projector.proj.get_def().c_str()); // printf("Using lat-lon projection: \"%s\"\n", projector.llproj.get_def().c_str()); // ------------------- Set up the GCM Grid const int south_pole_offset = (south_pole ? 1 : 0); const int north_pole_offset = (north_pole ? 1 : 0); _ncells_full = nlon() * nlat(); _nvertices_full = -1; // We don't care for L0 grid // _nlon = lonb.size() - 1; // _nlat = latb.size() - 1 + south_pole_offset + north_pole_offset; // Get a bunch of points. (i,j) is gridcell's index in canonical grid for (int ilat=0; ilat < latb.size()-1; ++ilat) { double lat0 = latb[ilat]; double lat1 = latb[ilat+1]; for (int ilon=0; ilon< lonb.size()-1; ++ilon) { Cell cell; double lon0 = lonb[ilon]; double lon1 = lonb[ilon+1]; //printf("(ilon, ilat) = (%d, %d)\n", ilon, ilat); //printf("values = %f %f %f %f\n", lon0, lat0, lon1, lat1); if (!spherical_clip(lon0, lat0, lon1, lat1)) continue; // Project the grid cell boundary to a planar polygon int n = points_in_side; // Pre-compute our points so we use exact same ones each time. std::vector<double> lons; lons.reserve(n+1); for (int i=0; i<=n; ++i) lons.push_back(lon0 + (lon1-lon0) * ((double)i/(double)n)); std::vector<double> lats; lats.reserve(n+1); for (int i=0; i<=n; ++i) lats.push_back(lat0 + (lat1-lat0) * ((double)i/(double)n)); // Build a square out of them (in lon/lat space) for (int i=0; i<n; ++i) vcache.add_vertex(cell, lons[i], lat0); for (int i=0; i<n; ++i) vcache.add_vertex(cell, lon1, lats[i]); // Try to keep calculations EXACTLY the same for VertexCache for (int i=n; i>0; --i) vcache.add_vertex(cell, lons[i], lat1); for (int i=n; i>0; --i) vcache.add_vertex(cell, lon0, lats[i]); // Figure out how to number this grid cell cell.j = ilat + south_pole_offset; // 0-based 2-D index cell.i = ilon; cell.index = (cell.j * nlon() + cell.i); cell.area = graticule_area_exact(*this, lat0,lat1,lon0,lon1); //printf("Adding lon/lat cell %d (%d, %d) area=%f\n", cell.index, cell.i, cell.j, cell.area); add_cell(std::move(cell)); } } // Make the polar caps (if this grid specifies them) // North Pole cap double lat = latb.back(); if (north_pole && spherical_clip(0, lat, 360, 90)) { Cell pole; for (int ilon=0; ilon< lonb.size()-1; ++ilon) { double lon0 = lonb[ilon]; double lon1 = lonb[ilon+1]; int n = points_in_side; for (int i=0; i<n; ++i) { double lon = lon0 + (lon1-lon0) * ((double)i/(double)n); pole.add_vertex(vcache.add_vertex(lon, lat)); } } pole.i = nlon()-1; pole.j = nlat(); pole.index = (pole.j * nlon() + pole.i); pole.area = polar_graticule_area_exact(*this, 90.0 - lat); add_cell(std::move(pole)); } // South Pole cap lat = latb[0]; if (south_pole && spherical_clip(0, -90, 360, lat)) { Cell pole; for (int ilon=lonb.size()-1; ilon >= 1; --ilon) { double lon0 = lonb[ilon]; // Make the circle counter-clockwise double lon1 = lonb[ilon-1]; int n = points_in_side; for (int i=0; i<n; ++i) { double lon = lon0 + (lon1-lon0) * ((double)i/(double)n); pole.add_vertex(vcache.add_vertex(lon, lat)); } } pole.i = 0; pole.j = 0; pole.index = 0; pole.area = polar_graticule_area_exact(*this, 90.0 + lat); add_cell(std::move(pole)); } }
void player_choice(char current_board[BOARD_SIZE][BOARD_SIZE], char future_board[BOARD_SIZE][BOARD_SIZE], char player) //function used to interpret the player's choice { int row = 0; int column = 0; int i = 0; int j = 0; switch(player) { case 'a': //adding a cell case 'A': printf("Inserting a cell.\n"); printf("Enter a row (any positive int < 40): "); scanf("%d", &row); if((row < 0) || (row > 40)) { printf("Invalid input.\n"); return; } printf("Enter a column (any positive int < 40): "); scanf("%d", &column); if((column < 0) || (column > 40)) { printf("Invalid input.\n"); return; } add_cell(future_board, row, column); //all edits are made to the future board change_board(current_board, future_board); //the boards a switched (current board is updated) printf("\033[2J\033[H"); print_board(current_board); //current board is printed break; case 'r': //removing a cell case 'R': printf("Removing a cell.\n"); printf("Enter a row (any positive int < 40): "); scanf("%d", &row); if((row < 0) || (row > 40)) { printf("Invalid input.\n"); return; } printf("Enter a column (any positive int < 40): "); scanf("%d", &column); if((column < 0) || (column > 40)) { printf("Invalid input.\n"); return; } delete_cell(future_board, row, column); change_board(current_board, future_board); printf("\033[2J\033[H"); print_board(current_board); break; case 'n': //applying the rules of the game case 'N': for(i = 0; i < BOARD_SIZE; i++) //the functions will read the current board but will apply the changes to the future board { for(j = 0; j < BOARD_SIZE; j++) { life_or_death(current_board, future_board, i, j, check_neighbors(current_board, i, j)); } } change_board(current_board, future_board); //boards are switched printf("\033[2J\033[H"); print_board(current_board); break; default: return; break; } return; }