/* runmaze.C: contains 'main' function. */ #include #ifdef WIN32 #ifdef _DEBUG #include #endif #endif #include #include #include "Maze.h" #include "SquareMaze.h" #include "MazeRunner.h" #include "RandomMazeRunner.h" #include "VisualizeSquareMazeRunner.h" int main (int argc,char *argv[]) { SquareMaze *maze; bool showVisualization=false; bool showSolutionMode=false; double visualizationPauseInSec=0.1; // process command-line args int a; a=1; while (a] [-v] [-s]\n"; cout << "-v : show visualization"; cout << "-p : pause for seconds each time a new node is visited. Only valid with -v (visualization). Default pause time is " << visualizationPauseInSec << "\n"; cout << "-s : \"Show solution Mode\". The input to the program will be a maze, followed by one or more solutions. Show each solution.\n"; cout << "NOTE: visualization is not implemented under Windows\n"; } if (strcmp(argv[a],"-p")==0) { a++; if (a>=argc) { cout << "-p flag given, but did not follow. Run with -h flag for help\n"; exit(1); } visualizationPauseInSec=atof(argv[a]); } if (strcmp(argv[a],"-v")==0) { showVisualization=true; } if (strcmp(argv[a],"-s")==0) { showSolutionMode=true; } a++; } if ((showSolutionMode) && !showVisualization) { cout << "WARNING: -s flag given without -v flag. This has no effect.\n"; } maze=new SquareMaze(cin); //maze->DebugDump(cout); #ifndef WIN32 // this isn't implemented on Windows VisualizeSquareMazeRunner *visualizer=NULL; if (showVisualization) { visualizer=new VisualizeSquareMazeRunner(maze); visualizer->setPauseTime(visualizationPauseInSec); if (showSolutionMode) { char solutionAlg[256]; cin.getline(solutionAlg,256); cout << " Printing solution done by " << solutionAlg << " algorithm\n"; int x,y; visualizer->startSolutionPath(); while (SquareMaze::SquareMazeNode::readXY(cin,&x,&y)) { visualizer->addNextInSolutionPath(x,y); //cout << "(" << x << "," << y << ")\n"; } int length, nodes; cin >> length; cin >> nodes; cout << " Solution Length = " << length << endl; cout << " # of Nodes Expanded = " << nodes << endl; visualizer->doneSolutionPath(); cout << "Click mouse in solution display window to continue...\n"; cout << flush; visualizer->waitForMouseClick(); return 0; } } #endif // ********************************************************************* // Basically, this section is the only code you will ever have to modify // ********************************************************************* MazeRunner *randomMazeRunner; randomMazeRunner=new RandomMazeRunner; randomMazeRunner->solveMaze(maze,cout); // ********************************************************************* // End of Section // ********************************************************************* // clean up, in case we need to run another maze runner algorithm (like, oh say BFS) maze->reinitializeVisitationStateAndInfo(); #ifdef WIN32 #ifdef _DEBUG cout << flush; // convenient thing for the MSDEV debugger, so it doesn't exit the program too quickly cout << "Press a key to exit program"; getch(); #endif #endif return 0; }