From 6bf4635f12de6fd1652acb6dbdc06e0353764a06 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 1 Aug 2025 17:03:39 +0200 Subject: [PATCH] ru:: bfs --- rogueviz/ru/classes.cpp | 3 +++ rogueviz/ru/room.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index 90392569..b2fbba52 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -163,6 +163,9 @@ struct room { void fov_from(int sx, int sy); void create_texture(); + + using bfs_progress = hr::function; + vector bfs(intxy start, const bfs_progress& f); }; struct xy { diff --git a/rogueviz/ru/room.cpp b/rogueviz/ru/room.cpp index ffa8b9c0..779dbb26 100644 --- a/rogueviz/ru/room.cpp +++ b/rogueviz/ru/room.cpp @@ -127,6 +127,28 @@ void room::fov_from(int sx, int sy) { } } } + +array, room_y> bfs_visited; +int bfs_id; + +vector room::bfs(intxy start, const bfs_progress& f) { + bfs_id++; + vector all = { start }; + for(int i=0; i 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);