Add Lines::findChar() to search for starting points in mazes
This commit is contained in:
@@ -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<int>(pos), static_cast<int>(lines.size()) };
|
||||
}
|
||||
|
||||
LinesSolver::processDataLine(line);
|
||||
}
|
||||
|
||||
void GuardGallivant::finish()
|
||||
{
|
||||
start_ = findChar(getStartChar());
|
||||
tracePath();
|
||||
}
|
||||
|
||||
|
||||
@@ -227,7 +227,7 @@ void ReindeerMaze::buildPathSegmentGraph(WeightedEdgeGraph& graph, VertexAttache
|
||||
// Initializes the work list of crossing incidences.
|
||||
void ReindeerMaze::initializeWorkList(std::list<ReindeerMazeCrossing>& 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<ReindeerMazePathIncidence>& 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<ReindeerMazePathIncidence>& otherPathIncidences)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user