/* mazeInLab.cpp * * Maze problem - version for Lab 12 * Starting at the upper left, find your way to the lower right * where 0 is a path and 1 is a wall. */ #include <iostream> using namespace std; #define LIMIT 100 /* Global data structures */ const int maze[ LIMIT]= // 0 1 2 3 4 5 6 7 8 9 /* 0*/ {1,1,1,1,1,1,1,1,1,1, /*10*/ 1,0,0,0,0,1,1,1,1,1, /*20*/ 1,1,0,1,1,0,1,1,1,1, /*30*/ 1,1,0,0,0,0,0,1,1,1, /*40*/ 1,1,1,1,1,1,0,1,1,1, /*50*/ 1,1,1,1,0,0,0,1,1,1, /*60*/ 1,1,0,1,1,0,1,1,1,1, /*70*/ 1,1,0,0,0,0,1,1,1,1, /*80*/ 1,1,1,1,1,1,1,1,1,1, /*90*/ 1,1,1,1,1,1,1,1,1,1}; const int start = 11; const int finish = 62; int cameFrom[ 100]; const int moves[4]= {-1, -10, 1, 10}; // Left, up, right, down. bool solutionFound = false; // Make a move, from the perspective of square whose index is in current void makeMove( int current) { int i, nextMove; cout << current << " "; //Display square numbers as we go if (current == finish) { cout << " *** Reached finish! ***" << endl; solutionFound = true; } for (i=0; i<4; i++) { //Try all four moves nextMove = current + moves[ i]; if( (maze[ nextMove] != 1) && (nextMove != cameFrom[ current]) && !solutionFound ) { cameFrom[ nextMove] = current; makeMove( nextMove); } } //end for(i=0... } //end makeMove() int main() { cout << "Search Path Traversed: \n" << endl; makeMove( start); return 0; }//end main()