mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-08-26 07:22:20 +00:00
ru:: bfs
This commit is contained in:
parent
d831fa6f20
commit
6bf4635f12
@ -163,6 +163,9 @@ struct room {
|
||||
void fov_from(int sx, int sy);
|
||||
|
||||
void create_texture();
|
||||
|
||||
using bfs_progress = hr::function<bool(intxy)>;
|
||||
vector<intxy> bfs(intxy start, const bfs_progress& f);
|
||||
};
|
||||
|
||||
struct xy {
|
||||
|
@ -127,6 +127,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) {
|
||||
bool create = !rooms.count(c);
|
||||
|
Loading…
x
Reference in New Issue
Block a user