error checking for Grid
This commit is contained in:
@@ -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.
|
||||
|
@@ -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++) {
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user