void generate_stack(bool** upper,bool** left, Point p, bool** visited, int m, int n) { stack<Point2> stack; Point2 p2(p.r, p.c); stack.push(p2); while(!stack.empty()) { Point2 &cur = stack.top(); if(cur.status == 0) { visited[cur.r][cur.c]=true; shuffle(cur.array); } if(cur.status < 4) { int d = cur.array[cur.status]; int r = cur.r + dr[d]; int c = cur.c + dc[d]; if(r>=0 && r<m && c>=0 && c<n && !visited[r][c]) { carve(upper, left, r, c, d); Point2 pp(r,c); stack.push(pp); } cur.status++; } else { stack.pop(); } } }
void DirectionalMap::generate() { //Method from: //http://www.roguebasin.com/index.php?title=Basic_directional_dungeon_generation //we start with all walls: reset(1); //Pick a starting x,y: int currentX = _width / 2; int currentY = 1; //and a starting width //recommended is anywhere from 3 to width: int currentW = (rand() % (_width/2 - 4)) + 3; //carve out the start: for(int i=0; i<_length; i++) { carve(currentX, currentY, currentW, 1); currentY += 1; if(rand() % 100 < _roughness) { int modifier = rand() % 2 + 1; if(rand() % 2 == 0) modifier *= -1; currentW += modifier; if(currentW < 3) { currentW = 3; } if(currentX + currentW >= _width) { currentX = _width - currentW - 1; } } if(rand() % 100 < _windyness) { //currentX += (rand() % 5) - 1; int modifier = rand() % 2 + 1; if(rand() % 2 == 0) modifier *= -1; currentX += modifier; if(currentX <0) { currentX = 1; } if(currentX + currentW >= _width) { currentX = _width - currentW - 1; } } } }
void generate_bfs(bool** upper,bool** left,Point p,bool** visited,int m,int n,int depth){ queue<Point> pq; //store the visited points in current level pq.push(p); visited[p.r][p.c]=true; int arr[]={0,1,2,3}; while(!pq.empty()){ int size=pq.size(); cout<<"size: "<<size<<endl; while(size--) { Point p=pq.front(); shuffle(arr); for(int i=0;i<4;i++) { int d=arr[i]; //for each point, walk depth steps int dps=depth; Point np(p.r,p.c); while(dps) { dps--; np.r+=dr[d]; np.c+=dc[d]; if(np.r>=0 && np.r<m && np.c>=0 && np.c<n && !visited[np.r][np.c]) { visited[np.r][np.c]=true; // if(dps==0) pq.push(np); carve(upper, left, np.r, np.c, d); }else break; d=rand()%4; }//while }//for pq.pop(); } } }
void generate(bool** upper,bool** left,Point p,bool** visited,int m,int n){ visited[p.r][p.c]=true; int arr[]={0, 1, 2, 3}; shuffle(arr); for(int i=0;i<4;i++) { int d=arr[i]; int r=p.r+dr[d]; int c=p.c+dc[d]; if(r>=0 && r<m && c>=0 && c<n && !visited[r][c]){ // cout<<"r: "<<r<<"c: "<<c<<endl; if(DEBUG && c==0) cout<<"dir: "<<d<<endl; carve(upper,left,r,c,d); Point pp(r,c); generate(upper,left,pp,visited,m,n); } } }
void Carver::start() { // If status_ is not Ok, the creation of our tmp FS failed if (!status_.ok()) { LOG(WARNING) << "Carver has not been properly constructed"; return; } for (const auto& p : carvePaths_) { if (!fs::exists(p)) { VLOG(1) << "File does not exist on disk: " << p; } else { Status s = carve(p); if (!s.ok()) { VLOG(1) << "Failed to carve file: " << p; } } } std::set<fs::path> carvedFiles; for (const auto& p : platformGlob((carveDir_ / "*").string())) { carvedFiles.insert(fs::path(p)); } auto s = compress(carvedFiles); if (!s.ok()) { VLOG(1) << "Failed to create carve archive: " << s.getMessage(); updateCarveValue(carveGuid_, "status", "ARCHIVE FAILED"); return; } s = postCarve(archivePath_); if (!s.ok()) { VLOG(1) << "Failed to post carve: " << s.getMessage(); updateCarveValue(carveGuid_, "status", "DATA POST FAILED"); return; } };