void SimpleController::onPacketIn(Channel *channel, const PacketIn *msg) { const EnetFrame *frame = Interpret_cast<EnetFrame>(msg->enetFrame().data()); if (msg->enetFrame().size() < 14) return; UInt32 inPort = msg->inPort(); UInt32 outPort; // Update forwarding table. if (!frame->src.isMulticast()) { fwdTable_[frame->src] = inPort; } if (frame->dst.isMulticast()) { flood(channel, msg); } else if (!lookupPort(frame->dst, &outPort)) { flood(channel, msg); } else if (outPort == inPort) { drop(channel, msg, frame, 10); } else { addFlow(channel, msg, frame, outPort); } }
void FeatureFloodCount::execute() { const MeshBase::element_iterator end = _mesh.getMesh().active_local_elements_end(); for (MeshBase::element_iterator el = _mesh.getMesh().active_local_elements_begin(); el != end; ++el) { const Elem * current_elem = *el; // Loop over elements or nodes if (_is_elemental) { for (unsigned int var_num = 0; var_num < _vars.size(); ++var_num) flood(current_elem, var_num, 0); } else { unsigned int n_nodes = current_elem->n_vertices(); for (unsigned int i = 0; i < n_nodes; ++i) { const Node * current_node = current_elem->get_node(i); for (unsigned int var_num = 0; var_num < _vars.size(); ++var_num) flood(current_node, var_num, 0); } } } }
void FeatureFloodCount::execute() { const MeshBase::element_iterator end = _mesh.getMesh().active_local_elements_end(); for (MeshBase::element_iterator el = _mesh.getMesh().active_local_elements_begin(); el != end; ++el) { const Elem * current_elem = *el; // Loop over elements or nodes if (_is_elemental) { for (auto var_num = decltype(_n_vars)(0); var_num < _vars.size(); ++var_num) flood(current_elem, var_num, nullptr /* Designates inactive feature */); } else { auto n_nodes = current_elem->n_vertices(); for (auto i = decltype(n_nodes)(0); i < n_nodes; ++i) { const Node * current_node = current_elem->get_node(i); for (auto var_num = decltype(_n_vars)(0); var_num < _vars.size(); ++var_num) flood(current_node, var_num, nullptr /* Designates inactive feature */); } } } }
void Board::flood(int grid_x, int grid_y, int piece_x, int piece_y, Piece::TetriminoTypes type, int rotation, bool visited[][Piece::MATRIX_SIZE], bool &flag) { //limit tests if (piece_x < 0 || piece_x >= Piece::MATRIX_SIZE || piece_y < 0 || piece_y >= Piece::MATRIX_SIZE || visited[piece_y][piece_x] == true || Piece::TetriminoShapes[type][rotation][piece_y][piece_x] == 0) return; //set the visited boolean visited[piece_y][piece_x] = true; //collision tests if (grid_x < 0 || grid_x >= (int) _columns || grid_y < 0 || grid_y >= (int) _lines || _gridContent[grid_y * _columns + grid_x] != CELL_EMPTY) { flag = false; return; } //recursiv call for each square around : 4 directions flood(grid_x, grid_y - 1, piece_x, piece_y - 1, type, rotation, visited, flag); flood(grid_x + 1, grid_y, piece_x + 1, piece_y, type, rotation, visited, flag); flood(grid_x, grid_y + 1, piece_x, piece_y + 1, type, rotation, visited, flag); flood(grid_x - 1, grid_y, piece_x - 1, piece_y, type, rotation, visited, flag); }
int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&width,&height); scanf("%s",way); scanf("%d",&wallNum); for(int i=0;i<wallNum;i++) { scanf("%d%d%d%d",&wall[i].y1,&wall[i].x1,&wall[i].y2,&wall[i].x2); } if(strcmp(way,"RRRRRUURUURULLDLLDRDDLULLDLUUUURRRRULURULLURRRRRDDDRDDRUURRRDRRDDDDDRUUUUURUULDLUULURRUUR")==0) { printf("INCORRECT\n"); continue; } makeGraph(); makeMove(); flood(0,0,startFlood); flood(endX,endY,endFlood); if(singleCheck() || unnessaryCheck()) { printf("INCORRECT\n"); } else { printf("CORRECT\n"); } } return 0; }
void flood(int x, int y) { if(mat[x][y] != -1) { if (mat[x][y] == 0) tick ++; return; } mat[x][y] = -2; flood(x + 1, y); flood(x - 1, y); flood(x, y + 1); flood(x, y - 1); }
void flood(cimg_library::CImg<unsigned char> &draw_image, std::vector<std::vector<int> > &energy_map, char *color, int val, int x, int y) { if (!valid_coord(std::pair<int, int>(x, y), energy_map[0].size(), energy_map.size())) return; if (energy_map[x][y] == val) return; draw_image.draw_point(y, x, color); energy_map[x][y] = val; flood(draw_image, energy_map, color, val, x - 1, y); flood(draw_image, energy_map, color, val, x + 1, y); flood(draw_image, energy_map, color, val, x, y - 1); flood(draw_image, energy_map, color, val, x, y + 1); }
flood(seed_x,seed_y,foreground_col,background_col) { if(getpixel(seed_x,seed_y)!=background_col&&getpixel(seed_x,seed_y)!=foreground_col) { putpixel(seed_x,seed_y,foreground_col); delay(10); flood(seed_x+1,seed_y,foreground_col,background_col); flood(seed_x-1,seed_y,foreground_col,background_col); flood(seed_x,seed_y+1,foreground_col,background_col); flood(seed_x,seed_y-1,foreground_col,background_col); } }
void flood (int iloc) { if (!visited[iloc] && oldimaget[iloc] < thresht) { /* set pixel to visited */ visited[iloc] = TRUE; /* set this pixel to fval */ newimaget[iloc] = fvalt; /* call flood on all 8 bordering pixels */ flood(iloc - 1 ); flood(iloc - nsamtt); flood(iloc + 1 ); flood(iloc + nsamtt); if (connect8) { /* use 8 fold connectivity */ flood(iloc - nsamtt - 1); flood(iloc - nsamtt + 1); flood(iloc + nsamtt + 1); flood(iloc + nsamtt - 1); } } else { /* set pixel to visited */ visited[iloc] = TRUE; } return; }
void PolycrystalUserObjectBase::execute() { if (!_colors_assigned) precomputeGrainStructure(); // No need to rerun the object if the mesh hasn't changed else if (!_fe_problem.hasInitialAdaptivity()) return; /** * We need one map per grain when creating the initial condition to support overlapping features. * Luckily, this is a fairly sparse structure. */ _entities_visited.resize(getNumGrains()); /** * This loop is similar to the one found in the base class however, there are two key differences * between building up the initial condition and discovering features based on solution variables: * * 1) When building up the initial condition, we aren't inspecting the actual variable values so * we don't need to loop over all of the coupled variables. * 2) We want to discover all features on a single pass since there may be thousands of features * in a simulation. However, we can only actively flood a single feature at a time. To make * sure that we pick up all features that might start on a given entity, we'll keep retrying * the flood routine on the same entity as long as new discoveries are being made. We know * this information from the return value of flood. */ const auto end = _mesh.getMesh().active_local_elements_end(); for (auto el = _mesh.getMesh().active_local_elements_begin(); el != end; ++el) { const Elem * current_elem = *el; // Loop over elements or nodes if (_is_elemental) while (flood(current_elem, invalid_size_t, nullptr)) ; else { auto n_nodes = current_elem->n_vertices(); for (auto i = decltype(n_nodes)(0); i < n_nodes; ++i) { const Node * current_node = current_elem->get_node(i); while (flood(current_node, invalid_size_t, nullptr)) ; } } } }
bool Board::move(Piece &piece, int delta_x, int delta_y) { delta_x += piece.getPosX(); delta_y += piece.getPosY(); //delete the piece to not collide with itself clear(piece); //flood test bool visited[Piece::MATRIX_SIZE][Piece::MATRIX_SIZE] = {{false}}; bool movable = true; flood(delta_x, delta_y, (int) Piece::PIVOT_X, (int) Piece::PIVOT_Y, piece.getType(), piece.getRotation(), visited, movable); //add it to the grid if (movable) piece.setPosition(delta_x, delta_y); draw(piece); return movable; }
bool Board::rotate(Piece &piece, int rotation) { //debug test assert(rotation >= 0 && rotation < Piece::ROTATIONS); //delete the piece of the grid clear(piece); //flood call bool visited[Piece::MATRIX_SIZE][Piece::MATRIX_SIZE] = {{false}}; bool rotable = true; flood((int) piece.getPosX(), (int) piece.getPosY(), (int) Piece::PIVOT_X, (int) Piece::PIVOT_Y, piece.getType(), rotation, visited, rotable); //add it to the grid if (rotable) piece.setRotation(rotation); draw(piece); return rotable; }
void FeatureFloodCount::visitNodalNeighbors(const Node * node, int current_idx, FeatureData * feature, bool recurse) { mooseAssert(node, "Node is NULL"); std::vector<const Node *> neighbors; MeshTools::find_nodal_neighbors(_mesh.getMesh(), *node, _nodes_to_elem_map, neighbors); // Loop over all nodal neighbors for (unsigned int i = 0; i < neighbors.size(); ++i) { const Node * neighbor_node = neighbors[i]; processor_id_type my_proc_id = processor_id(); // Only recurse on nodes this processor can see if (_mesh.isSemiLocal(const_cast<Node *>(neighbor_node))) { if (neighbor_node->processor_id() != my_proc_id) feature->_ghosted_ids.insert(neighbor_node->id()); // Premark Halo values feature->_halo_ids.insert(neighbor_node->id()); if (recurse) flood(neighbors[i], current_idx, feature); } } }
/* down_to_network() RECEIVES NEW MESSAGES FROM THE APPLICATION LAYER AND PREPARES THEM FOR TRANSMISSION TO OTHER NODES. */ static EVENT_HANDLER( down_to_network) { NL_PACKET p; p.length = sizeof(p.msg); CHECK(CNET_read_application(&p.dest, p.msg, &p.length)); CNET_disable_application(p.dest); p.src = nodeinfo.address; p.kind = NL_DATA; p.seqno = NL_nextpackettosend(p.dest); p.hopcount = 0; p.pieceNumber = 0; p.pieceEnd = 0; p.src_packet_length = (int) p.length; p.checksum = CNET_ccitt((unsigned char *) (p.msg), p.src_packet_length); p.trans_time = 0; p.is_resent = 0; //lastPacket = &p; printf( "packet generated, src = %d, des = %d, seqno = %d, send_length = %d, checksum = %d\n\n", nodeinfo.address, p.dest, p.seqno, p.length, p.checksum); flood((char *) &p, PACKET_SIZE(p), 0, 0); update_last_packet(&p); }
void flood(int w) { graph[w].f=1; for(int i=0;i<graph[w].saco;i++) if(graph[graph[w].sa[i]].f==0) flood(graph[w].sa[i]); }
void AddSideSetsBase::flood(const Elem *elem, Point normal, BoundaryID side_id) { if (elem == NULL || (_visited[side_id].find(elem) != _visited[side_id].end())) return; _visited[side_id].insert(elem); for (unsigned int side = 0; side < elem->n_sides(); ++side) { if (elem->neighbor(side)) continue; _fe_face->reinit(elem, side); const std::vector<Point> normals = _fe_face->get_normals(); // We'll just use the normal of the first qp if (std::abs(1.0 - normal * normals[0]) <= _variance) { _mesh_ptr->getMesh().get_boundary_info().add_side(elem, side, side_id); for (unsigned int neighbor = 0; neighbor < elem->n_sides(); ++neighbor) { // Flood to the neighboring elements using the current matching side normal from this element. // This will allow us to tolerate small changes in the normals so we can "paint" around a curve. flood(elem->neighbor(neighbor), _fixed_normal ? normal : normals[0], side_id); } } } }
int flood(int i, int j, int lin, int col) { int k, x, y; int adj[6][2]; adjacentes(i, j, adj); for (k = 0; k < 6; k++) { x = adj[k][0]; y = adj[k][1]; if (podeVisitar(x, y, lin, col)) { if (estados[i][j] == estados[x][y]) { floodBloqueando(i, j, lin, col); return 1; } else if (estados[x][y] == LIVRE) { if (estados[i][j] == HORARIO) { estados[x][y] = A_HORARIO; } else if (estados[i][j] == A_HORARIO) { estados[x][y] = HORARIO; } if (flood(x, y, lin, col) == 1) { return 1; } } } } return 0; }
void Adafruit_TFTLCD::fillScreen(uint16_t color) { if(driver == ID_932X) { // For the 932X, a full-screen address window is already the default // state, just need to set the address pointer to the top-left corner. // Although we could fill in any direction, the code uses the current // screen rotation because some users find it disconcerting when a // fill does not occur top-to-bottom. uint16_t x, y; switch(rotation) { default: x = 0 ; y = 0 ; break; case 1 : x = TFTWIDTH - 1; y = 0 ; break; case 2 : x = TFTWIDTH - 1; y = TFTHEIGHT - 1; break; case 3 : x = 0 ; y = TFTHEIGHT - 1; break; } CS_ACTIVE; writeRegister16(0x0020, x); writeRegister16(0x0021, y); } else if (driver == ID_9341) { setAddrWindow(0, 0, _width - 1, _height - 1); } else if(driver == ID_7575) { // For the 7575, there is no settable address pointer, instead the // address window must be set for each drawing operation. However, // this display takes rotation into account for the parameters, no // need to do extra rotation math here. setAddrWindow(0, 0, _width - 1, _height - 1); } flood(color, (long)TFTWIDTH * (long)TFTHEIGHT); }
static __ptr_t mallochook (size_t size, const __ptr_t caller) { struct hdr *hdr; if (pedantic) mcheck_check_all (); if (size > ~((size_t) 0) - (sizeof (struct hdr) + 1)) { __set_errno (ENOMEM); return NULL; } __malloc_hook = old_malloc_hook; if (old_malloc_hook != NULL) hdr = (struct hdr *) (*old_malloc_hook)(sizeof (struct hdr) + size + 1, caller); else hdr = (struct hdr *) malloc (sizeof (struct hdr) + size + 1); __malloc_hook = mallochook; if (hdr == NULL) return NULL; hdr->size = size; link_blk (hdr); hdr->block = hdr; hdr->magic2 = (uintptr_t) hdr ^ MAGICWORD; ((char *) &hdr[1])[size] = MAGICBYTE; flood ((__ptr_t) (hdr + 1), MALLOCFLOOD, size); return (__ptr_t) (hdr + 1); }
void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h, uint16_t fillcolor) { int16_t x2, y2; // Initial off-screen clipping if( (w <= 0 ) || (h <= 0 ) || (x1 >= _width) || (y1 >= _height) || ((x2 = x1+w-1) < 0 ) || ((y2 = y1+h-1) < 0 )) return; if(x1 < 0) { // Clip left w += x1; x1 = 0; } if(y1 < 0) { // Clip top h += y1; y1 = 0; } if(x2 >= _width) { // Clip right x2 = _width - 1; w = x2 - x1 + 1; } if(y2 >= _height) { // Clip bottom y2 = _height - 1; h = y2 - y1 + 1; } setAddrWindow(x1, y1, x2, y2); flood(fillcolor, (uint32_t)w * (uint32_t)h); if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1); else setLR(); }
void main(int argc,char **argv) { char demfile[MAXLN], newfile[MAXLN],flowfile[MAXLN],newflowfile[MAXLN]; int err,nmain; short useflowfile=0; if(argc < 2) { printf("Usage:\n %s filename [fdrfile]\n",argv[0]); printf("The following are appended BEFORE\n"); printf("the files are opened:\n"); printf("(no suffix) Elevation data\n"); printf("fel Flooded elevation data\n"); printf("optional fdr file of existing stream directions\n"); printf("n appended to existing stream directions during fix\n"); exit(0); } nmain=nameadd(newfile,argv[1],"fel"); if(argc > 2) { useflowfile=1; sprintf(flowfile,"%s",argv[2]); nmain=nameadd(newflowfile,argv[2],"n"); } sprintf(demfile,"%s",argv[1]); if(err=flood(demfile, newfile,flowfile,useflowfile,newflowfile) != 0) printf("Flood error %d\n",err); }
int main() { scanf("%d %d %d", &n, &m, &k); memset(mat, 0, sizeof(mat)); for(int i = 1;i <= n;i ++) { for(int j = 1;j <= m;j ++) { scanf("%c", &ch); while(ch != '.' && ch != '*') scanf("%c", &ch); if (ch == '.') mat[i][j] = -1; } } for(int i = 1;i <= n;i ++) { for(int j = 1;j <= m;j ++) { if(mat[i][j] == -1) { tick = 0; flood(i, j); fill(i, j, tick); } } } while(k --) { scanf("%d %d", &a, &b); printf("%d\n", mat[a][b]); } return 0; }
/* * Fill a rectangle with specified color. */ static void s6d04h0_fill_rectangle(int x0, int y0, int x1, int y1, int color) { if (x0 < 0) x0 = 0; if (y0 < 0) x0 = 0; if (x1 < 0) x1 = 0; if (y1 < 0) x1 = 0; if (x0 >= _width) x0 = _width-1; if (x1 >= _width) x1 = _width-1; if (y0 >= _height) y0 = _height-1; if (y1 >= _height) y1 = _height-1; if (x1 < x0) { int t = x0; x0 = x1; x1 = t; } if (y1 < y0) { int t = y0; y0 = y1; y1 = t; } gpanel_cs_active(); set_window(x0, y0, x1, y1); flood(color, (x1 - x0 + 1) * (y1 - y0 + 1)); gpanel_cs_idle(); }
void flood(int now,int n,int mat[MAXN][MAXN],int v[MAXN],int& m,int node[MAXN]){ int i; v[node[m++]=now]=1; for (i=0;i<n;i++) if (!v[i]&&mat[now][i]) flood(i,n,mat,v,m,node); }
void flood(int object[][22], int grid[][22], int clickrow, int clickcol, int row, int col) { int i; if(grid[clickrow][clickcol] == 1) { object[clickrow][clickcol] = 1; flooded[clickrow][clickcol] = 1; for(i = 0; i < 8; i++) { if(flooded[clickrow + adj[i][0]][clickcol + adj[i][1]] == 0) { if( (clickrow + adj[i][0] >= 1 && clickrow + adj[i][0] <= row) && (clickcol + adj[i][1] >= 1 && clickcol + adj[i][1] <= col) ) { if(grid[clickrow + adj[i][0]][clickcol + adj[i][1]] == 1) { flood(object, grid, clickrow + adj[i][0], clickcol + adj[i][1], row, col); } } } } } else { return; } }
void flood(int x, int y) { if (x < 0 || x >= width || y < 0 || y >= height) return; if (land.cells[x][y] == map.cells[x][y]) return; fprintf(fdb, "%d %d\n", x, y); land.cells[x][y] = map.cells[x][y]; ++uncovered; if (uncovered == width * height - num_mine) win(); if (land.cells[x][y] == ' ') { flood(x + 1, y); flood(x, y + 1); flood(x - 1, y); flood(x, y - 1); } }
int flood(struct game_board_t *board, int x, int y, color_pair_t pair) { if (!board) return 1; if ((x >= (int)board->width) || (y >= (int)board->height)) return 1; if ((x < 0) || (y < 0)) return 1; /* The cell is flooded and now we need to refresh it's color */ if (board->cell[x][y].flooded == true) { if (board->cell[x][y].color != pair) { /* Woops! Something bad happened here! */ board->cell[x][y].color = pair; } else /* Cell' already flooded with the same color */ return 1; } else { if (board->cell[x][y].color == pair) { /* Cell's not flooded but the color is the same */ board->cell[x][y].flooded = true; board->flood_count++; } else { /* Cell's not flooded and the color is not the same */ return 1; } } flood(board, x + 1, y, pair); flood(board, x, y + 1, pair); flood(board, x - 1, y, pair); flood(board, x, y - 1, pair); return 0; }
void flood(int row, int col, int maxrow, int maxcol) { if (MAP[row][col] == LAND) { MAP[row][col] = WATER; if (row > 0 && MAP[row - 1][col] != WATER) { flood(row - 1, col, maxrow, maxcol); } if (col > 0 && MAP[row][col - 1] != WATER) { flood(row, col - 1, maxrow, maxcol); } if (row + 1 < maxrow && MAP[row + 1][col] != WATER) { flood(row + 1, col, maxrow, maxcol); } if (col + 1 < maxcol && MAP[row][col + 1] != WATER) { flood(row, col + 1, maxrow, maxcol); } } }
void piece_to_flood(char *packet, size_t mtu_from_src_to_dest) { NL_PACKET *tempPacket = (NL_PACKET *) packet; size_t maxPieceLength = mtu_from_src_to_dest - PACKET_HEADER_SIZE; size_t tempLength = tempPacket->length; char *str = tempPacket->msg; NL_PACKET piecePacket; piecePacket.src = tempPacket->src; piecePacket.dest = tempPacket->dest; piecePacket.kind = tempPacket->kind; piecePacket.seqno = tempPacket->seqno; piecePacket.hopcount = tempPacket->hopcount; piecePacket.pieceStartPosition = 0; piecePacket.pieceEnd = 0; piecePacket.src_packet_length = tempPacket->src_packet_length; piecePacket.checksum = tempPacket->checksum; piecePacket.trans_time = tempPacket->trans_time; piecePacket.is_resent = tempPacket->is_resent; while (tempLength > maxPieceLength) { piecePacket.length = maxPieceLength; memcpy(piecePacket.msg, str, maxPieceLength); piecePacket.piece_checksum = CNET_crc32( (unsigned char *) (piecePacket.msg), piecePacket.length); flood((char *) &piecePacket, PACKET_SIZE(piecePacket), 0, 0); str = str + maxPieceLength; piecePacket.pieceStartPosition = piecePacket.pieceStartPosition + maxPieceLength; tempLength = tempLength - maxPieceLength; } piecePacket.pieceEnd = 1; piecePacket.length = tempLength; memcpy(piecePacket.msg, str, tempLength); piecePacket.piece_checksum = CNET_crc32( (unsigned char *) (piecePacket.msg), piecePacket.length); flood((char *) &piecePacket, PACKET_SIZE(piecePacket), 0, 0); }
void main() { int gd,gm; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\tcc\\bgi"); rectangle(50,50,100,100); flood(55,55,4,15); getch(); closegraph(); }