diff options
Diffstat (limited to 'src/2022/day14/aoc.h')
-rw-r--r-- | src/2022/day14/aoc.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/2022/day14/aoc.h b/src/2022/day14/aoc.h index d2143f6..fa4412c 100644 --- a/src/2022/day14/aoc.h +++ b/src/2022/day14/aoc.h @@ -81,6 +81,10 @@ struct cave { return {p.x - rock::t3.minx, p.y}; } + rock::pos to(rock::pos p, int dx) { + return {p.x - rock::t3.minx + dx, p.y}; + } + char& get(rock::pos p) const noexcept { return *(space + p.y * width + p.x); } @@ -122,6 +126,29 @@ struct cave { } } + void mark(rock& r, int dx) { + for (size_t i = 0; i < r.rs.size() - 1 ; i++) { + auto r1 = r.rs[i]; + auto r2 = r.rs[i+1]; + if (r1.x == r2.x) { + int min = r1.y < r2.y ? r1.y : r2.y; + int max = r1.y > r2.y ? r1.y : r2.y; + for (int j = min; j <= max; j++) { + auto p = to({r1.x, j}, dx); + get(p) = '#'; + } + } + if (r1.y == r2.y) { + int min = r1.x < r2.x ? r1.x : r2.x; + int max = r1.x > r2.x ? r1.x : r2.x; + for (int j = min; j <= max; j++) { + auto p = to({j, r1.y}, dx); + get(p) = '#'; + } + } + } + } + void print() const noexcept { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { |