// Programmieren 1, Praktikum 5, Aufgabe 3 // Sven Eisenhauer // 10.01.2005 // // file: main.cpp // // purpose: Find all exists of a given maze // #include using std::cin; using std::cout; using std::endl; // contains function prototypes for functions srand and rand #include // constant definitions const int maxLines=14; const int maxRows=14; const int startRow=1; const int startLine=3; //function prototypes //void mazePrint(const char[][maxRows], const int); void mazePrint(const char[][maxRows]); void mazeTraverse(char [][maxRows],int,int,int&); int main () { int exitCount=0; char maze[maxLines][maxRows] = { {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'}, {'.','#','#','#','#','#','#','#','#','#','#','#','#','.'}, {'.','#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#','.'}, {'.',' ',' ','#',' ','#',' ','#','#','#','#',' ','#','.'}, {'.','#','#','#',' ','#',' ',' ',' ',' ','#',' ','#','.'}, {'.',' ',' ',' ',' ',' ','#','#','#',' ','#',' ',' ','.'}, {'.','#','#','#','#',' ','#',' ','#',' ','#',' ','#','.'}, {'.','#',' ',' ','#',' ','#',' ','#',' ','#',' ','#','.'}, {'.','#','#',' ','#',' ','#',' ','#',' ','#',' ','#','.'}, {'.','#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#','.'}, {'.','#','#','#','#','#','#',' ','#','#','#',' ','#','.'}, {'.','#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#','.'}, {'.','#','#','#','#','#','#','#','#',' ','#','#','#','.'}, {'.','.','.','.','.','.','.','.','.','.','.','.','.','.'} }; mazeTraverse(maze,startRow,startLine,exitCount); cout << "\nNumber of Exits: " << exitCount << endl; return 0; } void mazeTraverse(char laby[][maxRows],int x,int y,int &count) { char temp=' '; if (x < maxLines && y < maxRows && x > 0 && y > 0) { if (laby[y][x] == ' ') laby[y][x] = 'x'; if (laby[y+1][x] == '.') { count++; itoa(count,&temp,10); laby[y+1][x]=temp; } if (laby[y][x+1] == '.') { count++; itoa(count,&temp,10); laby[y][x+1]=temp; } if (laby[y-1][x] == '.') { count++; itoa(count,&temp,10); laby[y-1][x]=temp; } if (laby[y][x-1] == '.') { count++; itoa(count,&temp,10); laby[y][x-1]=temp; } //mazePrint(laby,count); mazePrint(laby); if (laby[y+1][x] == ' ') mazeTraverse(laby,x,y+1,count); if (laby[y][x+1] == ' ') mazeTraverse(laby,x+1,y,count); if (laby[y-1][x] == ' ') mazeTraverse(laby,x,y-1,count); if (laby[y][x-1] == ' ') mazeTraverse(laby,x-1,y,count); } } void mazePrint(const char array[][maxRows]) //void mazePrint(const char array[][maxRows],const int count) { system ("cls"); for (int i=0;i