int main() { FILE *in = fopen( "bee.in", "r" ); int field; currentStep = 1; posX = 0; posY = -1; south( 2 ); for( int schale = 1; currentStep < 10000; schale ++ ) { northWest( schale ); north( schale ); northEast( schale ); southEast( schale ); south( schale + 1 ); southWest( schale ); } while( fscanf( in, "%d", &field )==1 ) { printf( "%d %d\n", fieldX[field], fieldY[field] ); } return 0; }
Cell *Cell::getNeighborWithImage(char anImage) { Cell *neighbors[4]; unsigned count = 0; if (north()->getImage() == anImage) neighbors[count++] = north(); if (south()->getImage() == anImage) neighbors[count++] = south(); if (east()->getImage() == anImage) neighbors[count++] = east(); if (west()->getImage() == anImage) neighbors[count++] = west(); if (!count) return this; else return neighbors[Ocean1->random->nextIntBetween(0,count-1)]; }
GeoDataCoordinates GeoDataLatLonAltBox::center() const { if ( isEmpty() ) return GeoDataCoordinates(); if( crossesDateLine() ) return GeoDataCoordinates( GeoDataCoordinates::normalizeLon(east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2), north() - (north() - south()) / 2, d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2); else return GeoDataCoordinates( east() - (east() - west()) / 2, north() - (north() - south()) / 2, d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2); }
std::vector< Ellipsoid_rasterizer::EuclideanVector >& Ellipsoid_rasterizer::rasterize() { GsTLInt center_id = cursor_.node_id( center_[0], center_[1], center_[2] ); appli_assert( center_id >= 0 && center_id < int(already_visited_.size()) ); already_visited_[ center_id ] = true; s_.push( center_id ); EuclideanVector west(-1,0,0); EuclideanVector east(1,0,0); EuclideanVector south(0,-1,0); EuclideanVector north(0,1,0); EuclideanVector down(0,0,-1); EuclideanVector up(0,0,1); // move away from center, until we reach the border of the ellipsoid while( ! s_.empty() ) { GsTLInt id = s_.top(); s_.pop(); GsTLGridNode loc; cursor_.coords( id, loc[0], loc[1], loc[2] ); check_node( loc+west ); check_node( loc+east ); check_node( loc+north ); check_node( loc+south ); check_node( loc+up ); check_node( loc+down ); } return ellipsoid_nodes_; }
void ModelExporter::processLight(const scene::INodePtr& node) { // Export lights as small polyhedron static const double EXTENTS = 8.0; std::vector<model::ModelPolygon> polys; Vertex3f up(0, 0, EXTENTS); Vertex3f down(0, 0, -EXTENTS); Vertex3f north(0, EXTENTS, 0); Vertex3f south(0, -EXTENTS, 0); Vertex3f east(EXTENTS, 0, 0); Vertex3f west(-EXTENTS, 0, 0); // Upper semi-diamond polys.push_back(createPolyCCW(up, south, east)); polys.push_back(createPolyCCW(up, east, north)); polys.push_back(createPolyCCW(up, north, west)); polys.push_back(createPolyCCW(up, west, south)); // Lower semi-diamond polys.push_back(createPolyCCW(down, south, west)); polys.push_back(createPolyCCW(down, west, north)); polys.push_back(createPolyCCW(down, north, east)); polys.push_back(createPolyCCW(down, east, south)); Matrix4 exportTransform = node->localToWorld().getPremultipliedBy(_centerTransform); _exporter->addPolygons("lights/default", polys, exportTransform); }
void flood_fill(int new_room) { int visited_num, i, j; do { visited_num = 0; for (i = 0; i < N; i++) { /* for each module */ for (j = 0; j < M; j++) { if (room[i][j] == visited) { // printf("[%d %d] ", i, j); visited_num++; room[i][j] = new_room; if (!west(module[i][j])) if (room[i][j-1] == nil) room[i][j-1] = visited; if (!north(module[i][j])) if (room[i-1][j] == nil) room[i-1][j] = visited; if (!east(module[i][j])) if (room[i][j+1] == nil) room[i][j+1] = visited; if (!south(module[i][j])) if (room[i+1][j] == nil) room[i+1][j] = visited; } } } size[new_room] += visited_num; } while (visited_num); }
//'@rdname neighbours //'@export // [[Rcpp::export]] DataFrame gh_neighbours(CharacterVector hashes){ unsigned int input_size = hashes.size(); CharacterVector north(input_size); CharacterVector ne(input_size); CharacterVector east(input_size); CharacterVector se(input_size); CharacterVector south(input_size); CharacterVector sw(input_size); CharacterVector west(input_size); CharacterVector nw(input_size); std::vector < std::string > holding(8); for(unsigned int i = 0; i < input_size; i++){ if((i % 10000) == 0){ Rcpp::checkUserInterrupt(); } if(CharacterVector::is_na(hashes[i])){ north[i] = NA_REAL; ne[i] = NA_REAL; east[i] = NA_REAL; se[i] = NA_REAL; south[i] = NA_REAL; sw[i] = NA_REAL; west[i] = NA_REAL; nw[i] = NA_REAL; } else { holding = cgeohash::all_neighbours(Rcpp::as<std::string>(hashes[i])); north[i] = holding[0]; ne[i] = holding[1]; east[i] = holding[2]; se[i] = holding[3]; south[i] = holding[4]; sw[i] = holding[5]; west[i] = holding[6]; nw[i] = holding[7]; } } return DataFrame::create(_["north"] = north, _["northeast"] = ne, _["east"] = east, _["southeast"] = se, _["south"] = south, _["southwest"] = sw, _["west"] = west, _["northwest"] = nw, _["stringsAsFactors"] = false); }
QString GeoDataLatLonAltBox::toString( GeoDataCoordinates::Unit unit ) const { switch( unit ){ case GeoDataCoordinates::Radian: return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" ) .arg( north() ).arg( west() ) .arg( d->m_maxAltitude ).arg( south() ) .arg( east() ).arg( d->m_minAltitude ); break; case GeoDataCoordinates::Degree: return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" ) .arg( north() * RAD2DEG ).arg( west() * RAD2DEG ) .arg( d->m_maxAltitude ).arg( south() * RAD2DEG ) .arg( east() * RAD2DEG ).arg( d->m_minAltitude ); break; } return QString( "GeoDataLatLonAltBox::text(): Error in unit: %1\n" ) .arg( unit ); }
void do_op(char C) { switch(C) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': push(C-'0'); break; case '+': addition(); break; case '-': subtraction(); break; case '*': multiplication(); break; case '/': division(); break; case '%': modulo(); break; case '^': north(); break; case '>': east(); break; case 'V': case 'v': south(); break; case '<': west(); break; case '?': spin(); break; case '!': lnot(); break; case '`': gt(); break; case '_': hif(); break; case '|': vif(); break; case '"': tsm(); break; case ':': dup(); break; case '\\': swap(); break; case '$': chomp(); break; case '#': jump(); break; case 'p': put(); break; case 'g': get(); break; case 'H': gate(); break; case '.': print_i(); break; case ',': print_c(); break; case '&': input_i(); break; case '~': input_c(); break; case '@': hacf(); break; case '{': left_b(); break; case '}': right_b(); break; case '[': carry_l(); break; case ']': carry_r(); break; case ';': empty(); break; case 'O': portal_o(); break; case 'B': portal_b(); break; default: /* DO NOTHING! */ break; } }
void menu()// NORTH AND SOUTH BOUND ROUTE { system("cls"); p("\n\n\n\t\t\t= Cavite Bus Transit =\n\n"); p("\n\t\t\t Ticket Transaction\n "); p("\n\n\tChoose Destination: "); p("[ 1 ] NORTH BOUND [ 2 ] SOUTH BOUND "); p("\n\n\tRoute: "); s("%d", &y); if (y == 1) north(); else if ( y == 2) south(); else {p("INVALID CHOICE!"); getch(); system("cls"); menu(); getch(); } }
int main() { int n; char s[6]; while (scanf("%d",&n),n) { init(); while (n--) { scanf("%s",s); if (strcmp(s,"north")==0) north(); else if (strcmp(s,"south")==0) south(); else if (strcmp(s,"east")==0) east(); else if (strcmp(s,"west")==0) west(); } printf("%d\n",dice[0]); } }
zz::map::location zz::map::location::adjacent( zz::map::direction direction ) const { switch( direction ) { case zz::map::north : return north( ); case zz::map::east : return east( ); case zz::map::south : return south( ); case zz::map::west : return west( ); } fprintf( stderr, "invalid direction provided to map::location::adjacent\n" ); fflush( stderr ); exit( EXIT_FAILURE ); }
void DrawPoint( const Vector2& point, float size ) { size *= 0.5f; Vector2 north(point + Vector2::UnitY * size ); Vector2 south(point - Vector2::UnitY * size ); Vector2 east(point + Vector2::UnitX * size ); Vector2 west(point - Vector2::UnitX * size ); float points[] = { north.X, north.Y, east.X, east.Y, south.X, south.Y, west.X, west.Y, }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, points); glDrawArrays(GL_LINE_LOOP, 0, 4); }
void ticketdest() { p("\n\tEnter Destination"); p("\n\t[ From ]: "); s("%d",&fr); p("\n\t[ To ]: "); s("%d",&to); p("\n\tNumber of Passengers: "); s("%d",&pass); if(to > fr) { destination(); p("\n\tFARE: %2.2f",fare); p("\n\tTotal Kilometer: %d\n", kmeter); p("\n\tPress Enter to proceed to SHOW SCREEN."); getch(); show(); } if(to < fr) { system("cls"); destination(); south(); ticketdest(); getch(); } }
int main () { int i,n,result; char roll[6]; while (1) { scanf("%d", &n); if (n==0) return 0; dice[kTOP] = 1; dice[kBOTTOM] = 6; dice[kNORTH] = 5; dice[kSOUTH] = 2; dice[kEAST] = 3; dice[kWEST] = 4; result = 1; for (i=0;i<n;i++) { scanf("%s", roll); switch (roll[0]) { case 'N': north(); break; case 'E': east(); break; case 'W': west(); break; case 'S': south(); break; case 'R': right(); break; case 'L': left(); break; } result += dice[kTOP]; } printf("%d\n", result); } }
static void make_see(int levelplayer, t_players *player, int fd, t_env *e) { int count; count = 0; dprintf(fd, "{"); while (count < levelplayer + 1) { if (player->orientation == O) west(count, fd, e, player); else if (player->orientation == N) north(count, fd, e, player); else if (player->orientation == E) east(count, fd, e, player); else if (player->orientation == S) south(count, fd, e, player); count = count + 1; if (count < levelplayer + 1 || count == 0) dprintf(fd, ","); } dprintf(fd, "}\n"); }
bool BoardEvaluator::IsFinished(Board &board, Colour *winningColour) { for (unsigned int i = 0; i < WIDTH; i++) { for (unsigned int j = 0; j < HEIGHT; j++) { Counter *counter = board.Space(i, j); if (counter != NULL) { // creating the dirctions to be searched in. North north(i, j); South south(i, j); East east(i, j); West west(i, j); NorthEast northEast(i, j); NorthWest northWest(i, j); SouthEast southEast(i, j); SouthWest southWest(i, j); bool retVal = false; Colour retCol = NULL_COLOUR; unsigned int conLength = CONNECT_LENGTH; Colour colour = (Colour)counter->GetColour(); if (RecursiveSearch(colour, &north, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &south, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &east, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &west, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &northEast, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &northWest, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &southEast, conLength - 1, board)) { retCol = colour; retVal = true; } if (RecursiveSearch(colour, &southWest, conLength - 1, board)) { retCol = colour; retVal = true; } if (retVal) { *winningColour = retCol; return true; } } } } return false; }
/** * \brief The work function * * This function does the actual work of activating the guide port outputs * for a given amount of time. */ void AsiGuidePort::run() { std::unique_lock<std::mutex> lock(_mutex); // we keep running until the _running variable becomes false // we are sure not to miss this event, because we carefully lock // the private data of the class all the time while (_running) { // find the time when the next action should finish int duration = 0; // first check for any right ascension movement if (0 != _ra) { if (_ra > 0) { west(); duration = _ra; } else { east(); duration = -_ra; } } else { rastop(); } // check whether any declination movement is needed if (0 != _dec) { if (_dec > 0) { north(); if (_dec < duration) { duration = _dec; } } else { south(); if (-_dec < duration) { duration = -_dec; } } } else { decstop(); } // so we are done, and wait for new information if (0 == duration) { // just wait for new information _condition.wait(lock); } else { // wait for the condition variable for the duration // in milliseconds. std::cv_status status = _condition.wait_for(lock, std::chrono::milliseconds(duration)); // if this times out, then we have waited for the // duration, so we change the _ra und _dec variables // accordingly if (status == std::cv_status::timeout) { if (_ra > 0) { _ra -= duration; } if (_ra < 0) { _ra += duration; } if (_dec > 0) { _dec -= duration; } if (_dec < 0) { _dec += duration; } } // in other cases, i.e. if it does not time out, // then new settings for _ra and _dec must have become // available, so we just loop around, and pick up the // new values } } }
rectangle(WIDTH, HEIGHT), rectangle(WIDTH, HEIGHT) ^ blob(bulk), blob(bulk) ^ bulk, 0, blob(bulk) ^ bulk, rectangle(WIDTH, HEIGHT) ^ blob(bulk), 0, 0, }; state *bulky_ten = &bulky_ten_; bulky_ten->ko = 0; state cho1_4_ = (state) { rectangle(9, 3), rectangle(9, 3) ^ rectangle(7, 2) ^ (3ULL << 7) ^ (1ULL << (2 * V_SHIFT)), south(east(rectangle(4, 1))), 0, 0, 0, 0, 0 }; state *cho1_4 = &cho1_4_; cho1_4->immortal = cho1_4->player; cho1_4->target = cho1_4->opponent; state cho1_ = cho1_4_; state *cho1 = &cho1_; cho1->opponent |= 1ULL << V_SHIFT; state cho2_ = cho1_;
LatLng southeast() const { return LatLng(south(), east()); }
AZ_MATRIX *user_Ke_build(struct user_partition *Edge_Partition) { double dcenter, doff, sigma = .0001; int ii,jj, horv, i, nx, global_id, nz_ptr, Nlocal_edges; /* Aztec matrix and temp variables */ int *Ke_bindx, *Ke_data_org = NULL; double *Ke_val; AZ_MATRIX *Ke_mat; int proc_config[AZ_PROC_SIZE], *cpntr = NULL; int *reordered_glob_edges = NULL, *reordered_edge_externs = NULL; Nlocal_edges = Edge_Partition->Nlocal; nx = (int) sqrt( ((double) Edge_Partition->Nglobal/2) + .00001); Ke_bindx = (int *) malloc((7*Nlocal_edges+1)*sizeof(int)); Ke_val = (double *) malloc((7*Nlocal_edges+1)*sizeof(double)); Ke_bindx[0] = Nlocal_edges+1; dcenter = 2 + 2.*sigma/((double) ( 3 * nx * nx)); doff = -1 + sigma/((double) ( 6 * nx * nx)); for (i = 0; i < Nlocal_edges; i++) { global_id = (Edge_Partition->my_global_ids)[i]; invindex(global_id, &ii, &jj, nx, &horv); nz_ptr = Ke_bindx[i]; Ke_val[i] = dcenter; if (horv == HORIZONTAL) { if (jj != 0) { Ke_bindx[nz_ptr] = north(ii,jj,nx); Ke_val[nz_ptr++] = doff; Ke_bindx[nz_ptr] = east(ii,jj,nx); Ke_val[nz_ptr++] = -1.; if (ii != 0) {Ke_bindx[nz_ptr]=west(ii,jj,nx); Ke_val[nz_ptr++]= 1.;} jj--; } else { Ke_val[i] = 1. + 2.*sigma/((double) ( 3 * nx * nx)); jj = nx-1; } Ke_bindx[nz_ptr] = east(ii,jj,nx); Ke_val[nz_ptr++] = 1.; if (ii != 0){ Ke_bindx[nz_ptr]=west(ii,jj,nx); Ke_val[nz_ptr++]=-1.;} if (jj != 0){ Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=doff;} } else { if (ii != 0) { Ke_bindx[nz_ptr] = north(ii,jj,nx); Ke_val[nz_ptr++] = -1.; Ke_bindx[nz_ptr] = east(ii,jj,nx); Ke_val[nz_ptr++] = doff; if (jj != 0) {Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=1.;} ii--; } else { Ke_val[i] = 1 + 2.*sigma/((double) ( 3 * nx * nx)); ii = nx-1; } Ke_bindx[nz_ptr] = north(ii,jj,nx); Ke_val[nz_ptr++] = 1.; if (ii != 0) {Ke_bindx[nz_ptr]=west(ii,jj,nx); Ke_val[nz_ptr++]=doff;} if (jj != 0) {Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=-1.;} } Ke_bindx[i+1] = nz_ptr; } AZ_set_proc_config(proc_config, COMMUNICATOR); AZ_transform_norowreordering(proc_config, &(Edge_Partition->needed_external_ids), Ke_bindx, Ke_val, Edge_Partition->my_global_ids, &reordered_glob_edges, &reordered_edge_externs, &Ke_data_org, Nlocal_edges, 0, 0, 0, &cpntr, AZ_MSR_MATRIX); AZ_free(reordered_glob_edges); AZ_free(reordered_edge_externs); Edge_Partition->Nghost = Ke_data_org[AZ_N_external]; Ke_mat = AZ_matrix_create( Nlocal_edges ); AZ_set_MSR(Ke_mat, Ke_bindx, Ke_val, Ke_data_org, 0, NULL, AZ_LOCAL); return(Ke_mat); }