I’m making a library that generates labyrinths or mazes. I represent a graph as adjacency lists. I generate a maze than I apply BFS or Dijkstra for path finding.
The problems begin when I print the maze. The problem is that structure of a printed maze needs manual setup. What I mean by this is that I have to calculate the width (rowBorder)
of the maze and print it row by row with three for loops:
for (size_t row = 0; row < graph.vertices(); row += graph.width())
{
const int rowBorder = row + graph.width();
for (int vertex = row; vertex < rowBorder; vertex++)
{
for (const auto& edge : graph.getAdjacencyList()[vertex])
{
//print stuff
}
}
}
It happens because adjacency list has a linear structure. List of ALL nodes std::vector<std::vector<Edge>>
and for every parent node I have set of nodes that parent node links to.
How can I represent an adjacency list with precalculated structure?
Maybe I should work with std::vector<std::vector<std::vector<Edge>>>
?
Or maybe some better solutions?