void Maze::FindAllPaths(int x, int y, Route *route) { if (x < 0 || y < 0 || x >= mazeSize.width || y >= mazeSize.height || maze[x][y] == '#' || maze[x][y] == 1) return; maze[x][y] = 1; Point p; p.x = x; p.y = y; route->AddPointToRoute(p); //Search point in destinations Destination* destination = 0; for (int i = 0; i < cntDestinations; i++) { Destination* tempDest = Destinations[i]; Point point = tempDest->GetEndPoint(); if (point.x == p.x && point.y == p.y) { destination = Destinations[i]; break; } } if (destination == 0) { destination = new Destination(); destination->SetEndPoint(p); Destinations[cntDestinations] = destination; cntDestinations++; } //Clone route Route* newRoute = new Route(); int numPoints = route->GetCntPoints(); Point* oldRoutePoints =route->GetPoints(); for (int i = 0; i < numPoints; i++) newRoute->AddPointToRoute(oldRoutePoints[i]); destination->AddRoute(*newRoute); FindAllPaths(x, y + 1, route); FindAllPaths(x + 1, y, route); FindAllPaths(x, y - 1, route); FindAllPaths(x - 1, y, route); if (route->GetCntPoints() > 0) route->DeletePoint(); maze[x][y] = 0; }
void Maze::PrintAllDestinations(int x, int y) { Route route = Route(); FindAllPaths(x, y, &route); cout << "Destinations:" << endl; for (int i = 0; i < cntDestinations; i++) { if (Destinations[i]->GetEndPoint().x == x && Destinations[i]->GetEndPoint().y == y) continue; Point destEndPoint = Destinations[i]->GetEndPoint(); cout << '(' << destEndPoint.x << "," << destEndPoint.y << ") "; } cout << endl << "Routes:" << endl; for (int i = 0; i < cntDestinations; i++) { if (Destinations[i]->GetEndPoint().x == x && Destinations[i]->GetEndPoint().y == y) continue; Destination* destination = Destinations[i]; int cntRoutes = destination->GetCntRoutes(); Route* routes = new Route[cntRoutes]; destination->SortRoutes(); routes = destination->GetRoutes(); Point destEndPoint = destination->GetEndPoint(); cout << '(' << destEndPoint.x << "," << destEndPoint.y << ") " << endl; for (int j = 0; j < cntRoutes; j++) { Route route = routes[j]; Point* points = route.GetPoints(); int cntPoints = route.GetCntPoints(); for (int k = 0; k < cntPoints; k++) { Point point = points[k]; cout << '(' << point.x << "," << point.y << ") ";//<<endl; } cout << endl; } } }