summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp')
-rw-r--r--Bachelor/Prog1/Prakt5/prg1p5_3/main.cpp128
1 files changed, 128 insertions, 0 deletions
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 <iostream>
+
+using std::cin;
+using std::cout;
+using std::endl;
+
+// contains function prototypes for functions srand and rand
+#include <cstdlib>
+
+// 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<maxLines;i++)
+ {
+ for (int j=0;j<maxRows;j++)
+ cout << array[i][j];
+ cout << "\n";
+ }
+ //cout << "\n" << count;
+ //system ("pause");
+} \ No newline at end of file