From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp | 128 ++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp (limited to 'Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp') diff --git a/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp new file mode 100644 index 0000000..b99a0ab --- /dev/null +++ b/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp @@ -0,0 +1,128 @@ +// 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