Ejemplo n.º 1
0
int main(int argc, char** argv) {

bool dfs = true;

if(argc !=3) {
	std::cout << "Bad number of arguments. 3 must be given.";
}	

else if((std::string)argv[2] != "-dfs" && (std::string)argv[2] != "-bfs") {
	std::cout << "The search option must be -dfs or -bfs";
}

else {

	try {	
		if((std::string)argv[2] == "-bfs") {
			dfs = false;
		}
		MazeReader* mazeR = new MazeReader((std::string)argv[1]);
		MazeWalker* mazeW = new MazeWalker(mazeR->getMaze(), mazeR->getStartRow(), mazeR->getStartCol(), mazeR->getRows(), mazeR->getCols(), dfs);

		mazeW->walkMaze(); 

		delete mazeR;
		delete mazeW;
	}
	catch(std::runtime_error e) {
		std::cout << e.what();
	}

}

};
Ejemplo n.º 2
0
int main(int argc, char** argv){
    if(argc != 3){
        std::cout<<"\nInvalid input\n"
                <<"[program] [filename] [-dfs || -bfs]\n";
    }
    else{
        std::string search = argv[2];
        if(search != "-bfs" && search != "-dfs"){

            std::cout<<"\nInvalid input\n"
                    <<"[program] [filename] [-dfs || -bfs]\n";
            return(0);
        }
        std::string file = argv[1];
        bool isDFS;

            if(search == "-bfs"){
                isDFS = false;
            }
            else{
                isDFS = true;
            }

        try{
            MazeReader* reader = new MazeReader(file);
            MazeWalker* walker = new MazeWalker(reader->getMaze(), reader->getStartRow(), reader->getStartCol(), reader->getRows(), reader->getCols(), isDFS);
            walker->walkMaze();

            delete reader;
            delete walker;
        }
        catch(MazeCreationException& e){
            std::cout<<e.what()<<std::endl;
        }

    }
    return(0);
}
Ejemplo n.º 3
0
int main(int argc, char** argv)
{
    string mode="";
    MazeReader* b;
    MazeWalker* g;
    if(argc>1)
    {
        mode=argv[1];
        string mode2="";
        if(mode == "-bfs")
        {
            mode2=argv[2];
            try
            {
                b=new MazeReader(mode2);
                const char* const* j=b->getMaze();
                int k=b->getCols();
                int l=b->getRows();
                int m=b->getStartCol();
                int n=b->getStartRow();
                Search o=Search::BFS;
                g=new MazeWalker(j, n, m, l, k, o);
                g->walkMaze();
                const int* const* visit=g->getVisited();
                cout << "Starting position: " << b->getStartRow() << "," << b->getStartCol() << endl;
                cout << "Size: " << b->getRows() << "," << b->getCols() << endl;
                for(int i=0; i< g->getVisitedRows(); i++)
                {
                    for(int j=0; j<g->getVisitedCols(); j++)
                    {
                        cout << visit[i][j] << " ";
                    }
                    cout << endl;
                }
                if(g->isGoalReached())
                {
                    cout << "We escaped!" << endl;
                }
                else
                {
                    cout << "No way out!" << endl;
                }
                delete b;
                delete g;

            }
            catch(exception& e)
            {
               cout << e.what() << endl;
            }




        }
        else if(mode=="-dfs")
        {
            mode2=argv[2];
            try
            {
                b=new MazeReader(mode2);

                const char* const* j=b->getMaze();
                int k=b->getCols();
                int l=b->getRows();
                int m=b->getStartCol();
                int n=b->getStartRow();
                Search o=Search::DFS;
                g=new MazeWalker(j, n, m, l, k, o);
                g->walkMaze();
                const int* const* visit=g->getVisited();
                cout << "Starting position: " << b->getStartRow() << "," << b->getStartCol() << endl;
                cout << "Size: " << b->getRows() << "," << b->getCols() << endl;
                for(int i=0; i< g->getVisitedRows(); i++)
                {
                    for(int j=0; j<g->getVisitedCols(); j++)
                    {
                        cout << visit[i][j] << " ";
                    }
                    cout << endl;
                }
                if(g->isGoalReached())
                {
                    cout << "We escaped!" << endl;
                }
                else
                {
                    cout << "No way out!" << endl;
                }
                delete b;
                delete g;
            }
            catch(exception& e)
            {
               cout << e.what() << endl;
            }

        }
        else if (mode == "-test")
        {
            Test a;
            a.runTests();
        }

    }
    else
    {
        cout << "Please give at least two command arguments." << endl;
    }


}