mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-09-09 22:06:01 +00:00
ru:: bfs
This commit is contained in:
@@ -163,6 +163,9 @@ struct room {
|
|||||||
void fov_from(int sx, int sy);
|
void fov_from(int sx, int sy);
|
||||||
|
|
||||||
void create_texture();
|
void create_texture();
|
||||||
|
|
||||||
|
using bfs_progress = hr::function<bool(intxy)>;
|
||||||
|
vector<intxy> bfs(intxy start, const bfs_progress& f);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xy {
|
struct xy {
|
||||||
|
@@ -128,6 +128,28 @@ void room::fov_from(int sx, int sy) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array<array<int, room_x>, room_y> bfs_visited;
|
||||||
|
int bfs_id;
|
||||||
|
|
||||||
|
vector<intxy> room::bfs(intxy start, const bfs_progress& f) {
|
||||||
|
bfs_id++;
|
||||||
|
vector<intxy> all = { start };
|
||||||
|
for(int i=0; i<isize(all); i++) {
|
||||||
|
auto at = all[i];
|
||||||
|
auto add = [&] (int x, int y) {
|
||||||
|
if(bfs_visited[y][x] == bfs_id) return;
|
||||||
|
bfs_visited[y][x] = bfs_id;
|
||||||
|
intxy v {x, y};
|
||||||
|
if(f(v)) all.push_back(v);
|
||||||
|
};
|
||||||
|
if(at.x > 0) add(at.x-1, at.y);
|
||||||
|
if(at.x < room_x-1) add(at.x+1, at.y);
|
||||||
|
if(at.y > 0) add(at.x, at.y-1);
|
||||||
|
if(at.y < room_y-1) add(at.x, at.y+1);
|
||||||
|
}
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
room *get_room_at(cell *c) {
|
room *get_room_at(cell *c) {
|
||||||
bool create = !rooms.count(c);
|
bool create = !rooms.count(c);
|
||||||
auto& r = rooms[c];
|
auto& r = rooms[c];
|
||||||
|
Reference in New Issue
Block a user