error checking for Grid

This commit is contained in:
Eric Mertens
2022-11-28 09:20:50 -08:00
parent 9601c42fc5
commit 833f496090
5 changed files with 42 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ namespace {
auto GatherOutput(Machine m) -> Grid
{
Grid grid;
std::vector<std::string> rows;
bool eol = true; // next output starts a new line
Run(m, []() -> ValueType {
@@ -25,16 +25,16 @@ auto GatherOutput(Machine m) -> Grid
},
[&](ValueType c) -> void {
if (eol) {
grid.rows.emplace_back();
rows.emplace_back();
eol = false;
}
if ('\n' == c) {
eol = true;
} else {
grid.rows.back().push_back(static_cast<char>(c));}
rows.back().push_back(static_cast<char>(c));}
}
);
return grid;
return Grid{std::move(rows)};
}
/// Find all the 4-way intersections.

View File

@@ -35,8 +35,8 @@ using Distances = std::map<Name,std::vector<std::pair<Name, std::int64_t>>>;
auto FindPortals(Grid const& grid) -> Portals {
Portals portals;
std::int64_t w = grid.rows[0].size();
std::int64_t h = grid.rows.size();
std::int64_t w = grid.Cols();
std::int64_t h = grid.Rows();
for (std::int64_t x = 1; x < w-1; x++) {
for (std::int64_t y = 1; y < h-1; y++) {

View File

@@ -24,8 +24,8 @@ namespace {
auto FindBugs(Grid const& grid) -> std::vector<Coord> {
std::vector<Coord> result;
std::int64_t w = grid.rows[0].size();
std::int64_t h = grid.rows.size();
std::int64_t w = grid.Cols();
std::int64_t h = grid.Rows();
grid.each([&](Coord c, char v) {
if (v == '#') result.push_back(c);