|
@@ -25,6 +25,7 @@ unsigned int identifyTile(unsigned int y, unsigned int x, unsigned int l) {
|
|
|
return y * l + x;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
class World
|
|
|
{
|
|
|
private:
|
|
@@ -222,6 +223,26 @@ class World
|
|
|
|
|
|
return targetIsReached;
|
|
|
}
|
|
|
+
|
|
|
+ void showResults(bool exitFound, const list<unsigned int>& discovered, const list<unsigned int>& path) {
|
|
|
+
|
|
|
+ markAll(discovered, DISCOVERED);
|
|
|
+
|
|
|
+ if (!path.empty()) {
|
|
|
+ markAll(path, TRACE);
|
|
|
+ }
|
|
|
+
|
|
|
+ display();
|
|
|
+
|
|
|
+ // Display DFS results
|
|
|
+ if (exitFound)
|
|
|
+ cout << "SUCCESS !" << endl;
|
|
|
+ else
|
|
|
+ cout << "FAILURE ..." << endl;
|
|
|
+
|
|
|
+ cout << discovered.size() << " tiles discovered;" << endl;
|
|
|
+ cout << path.size() << " path length.";
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
int main()
|
|
@@ -252,21 +273,7 @@ int main()
|
|
|
|
|
|
// Display DFS
|
|
|
cout << endl << "Depth-First Search" << endl;
|
|
|
-
|
|
|
- dfsWorld.markAll(dfsDiscovered, DISCOVERED);
|
|
|
- dfsWorld.markAll(dfsPath, TRACE);
|
|
|
- dfsWorld.markOne(start, ORIGIN);
|
|
|
- dfsWorld.markOne(end, TARGET);
|
|
|
- dfsWorld.display();
|
|
|
-
|
|
|
- // Display DFS results
|
|
|
- if (exitFound)
|
|
|
- cout << "SUCCESS !" << endl;
|
|
|
- else
|
|
|
- cout << "FAILURE ..." << endl;
|
|
|
-
|
|
|
- cout << dfsDiscovered.size() << " tiles discovered;" << endl;
|
|
|
- cout << dfsPath.size() << " path length.";
|
|
|
+ dfsWorld.showResults(exitFound, dfsDiscovered, dfsPath);
|
|
|
|
|
|
// End
|
|
|
return 0;
|