diff --git a/include/aoc/GuardGallivant.hpp b/include/aoc/GuardGallivant.hpp index 86d3fbd..1ad59ef 100644 --- a/include/aoc/GuardGallivant.hpp +++ b/include/aoc/GuardGallivant.hpp @@ -28,7 +28,6 @@ class GuardGallivant public: virtual const std::string getPuzzleName() const override; virtual const int getPuzzleDay() const override; - virtual void processDataLine(const std::string& line) override; virtual void finish() override; private: typedef Grid VisitGrid; diff --git a/include/aoc/ReindeerMaze.hpp b/include/aoc/ReindeerMaze.hpp index a55f3d1..2340d12 100644 --- a/include/aoc/ReindeerMaze.hpp +++ b/include/aoc/ReindeerMaze.hpp @@ -44,7 +44,6 @@ class ReindeerMaze void initializeWorkList(std::list& crossings, const int entryVertex); void addCheckedIncidence(std::vector& incidences, const Point2 start, const Point2 direction); - Point2 findStart() const; void addPathSegmentEdges(WeightedEdgeGraph& graph, const ReindeerMazePathIncidence& pathIncidence, const std::vector& otherPathIncidences); std::pair makePositionsIdPair(const Point2& position1, const Point2& position2); diff --git a/include/aoc/common/Lines.hpp b/include/aoc/common/Lines.hpp index 0d815ff..2e2aa5f 100644 --- a/include/aoc/common/Lines.hpp +++ b/include/aoc/common/Lines.hpp @@ -32,6 +32,7 @@ class Lines bool isInBounds(const Point2& point) const; char getCharAt(const Point2& point) const; void setCharAt(const Point2& point, const char value); + Point2 findChar(const char c) const; }; std::ostream& operator<<(std::ostream& os, const Lines& lines); diff --git a/include/aoc/framework/LinesSolver-impl.hpp b/include/aoc/framework/LinesSolver-impl.hpp index d353c87..5840bdf 100644 --- a/include/aoc/framework/LinesSolver-impl.hpp +++ b/include/aoc/framework/LinesSolver-impl.hpp @@ -46,3 +46,9 @@ void LinesSolver::setCharAt(const Point2& point, const char value) { lines.setCharAt(point, value); } + +template +Point2 LinesSolver::findChar(const char c) const +{ + return lines.findChar(c); +} diff --git a/include/aoc/framework/LinesSolver.hpp b/include/aoc/framework/LinesSolver.hpp index d6da17b..5fd176d 100644 --- a/include/aoc/framework/LinesSolver.hpp +++ b/include/aoc/framework/LinesSolver.hpp @@ -33,4 +33,5 @@ class LinesSolver bool isInBounds(const Point2& point) const; char getCharAt(const Point2& point) const; void setCharAt(const Point2& point, const char value); + Point2 findChar(const char c) const; }; diff --git a/src/GuardGallivant.cpp b/src/GuardGallivant.cpp index 4fdce50..f366a25 100644 --- a/src/GuardGallivant.cpp +++ b/src/GuardGallivant.cpp @@ -25,19 +25,9 @@ const int GuardGallivant::getPuzzleDay() const return 6; } -void GuardGallivant::processDataLine(const std::string& line) -{ - auto pos = line.find(getStartChar()); - if (pos != std::string::npos) - { - start_ = Point2{ static_cast(pos), static_cast(lines.size()) }; - } - - LinesSolver::processDataLine(line); -} - void GuardGallivant::finish() { + start_ = findChar(getStartChar()); tracePath(); } diff --git a/src/ReindeerMaze.cpp b/src/ReindeerMaze.cpp index 8c88bd3..1b4c7b9 100644 --- a/src/ReindeerMaze.cpp +++ b/src/ReindeerMaze.cpp @@ -227,7 +227,7 @@ void ReindeerMaze::buildPathSegmentGraph(WeightedEdgeGraph& graph, VertexAttache // Initializes the work list of crossing incidences. void ReindeerMaze::initializeWorkList(std::list& crossings, const int entryVertex) { - Point2 start{ findStart() }; + Point2 start{ findChar(getStartChar()) }; crossings.emplace_back(start); crossings.back().incidences.emplace_back(Point2::left, entryVertex); addCheckedIncidence(crossings.back().incidences, start, Point2::right); @@ -243,21 +243,6 @@ void ReindeerMaze::addCheckedIncidence(std::vector& i } } -Point2 ReindeerMaze::findStart() const -{ - for (int j = 0; j < lines.size(); j++) - { - for (int i = 0; i < lines[j].size(); i++) - { - if (lines[j][i] == getStartChar()) - { - return { i, j }; - } - } - } - return { 0, 0 }; -} - void ReindeerMaze::addPathSegmentEdges(WeightedEdgeGraph& graph, const ReindeerMazePathIncidence& pathIncidence, const std::vector& otherPathIncidences) { diff --git a/src/common/Lines.cpp b/src/common/Lines.cpp index ba024bb..f12d4b0 100644 --- a/src/common/Lines.cpp +++ b/src/common/Lines.cpp @@ -33,6 +33,21 @@ void Lines::setCharAt(const Point2& point, const char value) at(point.y)[point.x] = value; } +Point2 Lines::findChar(const char c) const +{ + for (int j = 0; j < size(); j++) + { + for (int i = 0; i < at(j).size(); i++) + { + if (at(j)[i] == c) + { + return { i, j }; + } + } + } + return { -1, -1 }; +} + std::ostream& operator<<(std::ostream& os, const Lines& lines) { for (const auto& line : lines)