From ad69a28c62fcd3a10409084998b946d4d444b883 Mon Sep 17 00:00:00 2001 From: Noah69420 Date: Thu, 12 Dec 2024 17:26:23 +0100 Subject: [PATCH 1/4] pipes_2_0 --- src/pipes_test.c | 95 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/src/pipes_test.c b/src/pipes_test.c index 8d31022..e3a3a30 100644 --- a/src/pipes_test.c +++ b/src/pipes_test.c @@ -4,6 +4,9 @@ #include #include +#include +#include + #define DEBUGGER_PIPES_TO_NUMBERS 0 #define DEBUGGER_RANDOM 0 @@ -12,12 +15,12 @@ #define INFILL_Y_PIPE 2 #define FILLER "░" // ░ -#define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid -#define GRID_GROESSE_Y 60 +// #define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid +// #define GRID_GROESSE_Y 60 #define MIN_LAENGE_PIPE 6 #define MAX_LAENGE_PIPE 6 -#define SLEEP_TIMER 10000 // in nano seconds -#define COLOR_CHANGING_PROBABILITY 10 // format: "(1 : your_number)", for every direction change +#define SLEEP_TIMER 5000 // in nano seconds +#define COLOR_CHANGING_PROBABILITY 5 // format: "(1 : your_number)", for every direction change #define RESET_COLOR "\033[0m" #define RED "\033[31m" @@ -35,6 +38,23 @@ void random_color() { color = colors[rand() % (sizeof(colors) / sizeof(colors[0]))]; } +int getch_directions(){ + int ch; + struct termios oldattr, newattr; + + tcgetattr(STDIN_FILENO, &oldattr); + newattr = oldattr; + newattr.c_lflag &= ~ICANON; + newattr.c_lflag &= ~ECHO; + newattr.c_cc[VMIN] = 1; + newattr.c_cc[VTIME] = 0; + tcsetattr(STDIN_FILENO, TCSANOW, &newattr); + ch = getchar(); + tcsetattr(STDIN_FILENO, TCSANOW, &oldattr); + + return ch; +} + void print_grid(int x, int y, char **grid) { for (int i = 0; i < y; i++) { printf("\n"); @@ -169,6 +189,9 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge) { if(laenge < 0){ for (int i = *y_start; i > *y_start + laenge/2; i--) { + if (i <= 0) { + return; + } grid[i][*x_start] = INFILL_Y_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -176,6 +199,9 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int } } else{ for (int i = *y_start; i < *y_start + laenge/2; i++) { + if (i <= 0) { + return; + } grid[i][*x_start] = INFILL_Y_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -195,7 +221,7 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int *y_start += laenge/2; } -int main_program() { +int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { int x_start = GRID_GROESSE_X / 2; int y_start = GRID_GROESSE_Y / 2; @@ -218,27 +244,45 @@ int main_program() { } } - int richtungswechsler = 1; - + //int richtungswechsler = 1; + while (!DEBUGGER_RANDOM) { if ((rand() %color_c_p) <= 1) { random_color(); } - if ((rand() %2)-1) { - laenge = ((rand() %max_l)+min_l); - } else { - laenge = ((rand() %max_l)+min_l)*-1; - } - if (richtungswechsler == 1) { - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - richtungswechsler *= -1; - } else { - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - richtungswechsler *= -1; + laenge = ((rand() %max_l)+min_l); + + //if ((rand() %2)-1) { + // laenge = ((rand() %max_l)+min_l); + //} else { + // laenge = ((rand() %max_l)+min_l)*-1; + //} + + char key_input = (char)getch_directions(); + + switch (key_input) { + case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + default: return 0; } + + // if (richtungswechsler == 1) { + // generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + // richtungswechsler *= -1; + // } else { + // generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + // richtungswechsler *= -1; + // } + } if (DEBUGGER_RANDOM) { @@ -256,22 +300,27 @@ int main_program() { for (int i = 0; i < GRID_GROESSE_Y; i++) { - free(grid[i]); - } - free(grid); + free(grid[i]); + } + free(grid); return 0; } -int pipes() { + +int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) { +//int main() { + //int GRID_GROESSE_X = 100; + //int GRID_GROESSE_Y = 50; pid_t pid; int status; while (1) { + pid = fork(); // Erzeuge einen neuen Prozess if (pid == 0) { // Kindprozess führt die Hauptlogik aus - main_program(); + main_program(GRID_GROESSE_X, GRID_GROESSE_Y); exit(0); // Normales Beenden, falls kein Fehler } else if (pid > 0) { // Elternprozess wartet auf das Kind From 916ad84e18df6fcb38245dc57771fcb77a8f122b Mon Sep 17 00:00:00 2001 From: Noah69420 Date: Thu, 12 Dec 2024 17:26:47 +0100 Subject: [PATCH 2/4] pipes_2_0 --- src/pipes_test.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pipes_test.h b/src/pipes_test.h index 9d60512..d8ee3af 100644 --- a/src/pipes_test.h +++ b/src/pipes_test.h @@ -1,7 +1 @@ - - - - -int pipes(); - - +int pipes(int GRIG_GROESSE_X, int GRID_GROESSE_Y); From 68d4d99b591389fa319e159e07240d50822b434a Mon Sep 17 00:00:00 2001 From: Noah69420 Date: Fri, 13 Dec 2024 16:39:11 +0100 Subject: [PATCH 3/4] bux fixing --- src/pipes_test.c | 61 ++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/pipes_test.c b/src/pipes_test.c index e3a3a30..7bb780d 100644 --- a/src/pipes_test.c +++ b/src/pipes_test.c @@ -13,7 +13,7 @@ #define INFILL_PLAIN_PAPER 0 #define INFILL_X_PIPE 1 #define INFILL_Y_PIPE 2 -#define FILLER "░" // ░ +#define FILLER " " // ░ // #define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid // #define GRID_GROESSE_Y 60 @@ -166,9 +166,13 @@ void print_grid(int x, int y, char **grid) { } } -void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int laenge) { +void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { if(laenge < 0){ for (int i = *x_start; i > *x_start + laenge; i--) { + if (i <= -laenge/2 -1) { + *x_start = GRID_GROESSE_X + laenge/2; + return; + } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -176,6 +180,10 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int } } else{ for (int i = *x_start; i < *x_start + laenge; i++) { + if (i >= GRID_GROESSE_X - laenge/2+1) { + *x_start = laenge/2; + return; + } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -186,10 +194,11 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int *x_start += laenge; } -void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge) { +void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { if(laenge < 0){ for (int i = *y_start; i > *y_start + laenge/2; i--) { - if (i <= 0) { + if (i <= -laenge/2) { + *y_start = GRID_GROESSE_Y + laenge/2; return; } grid[i][*x_start] = INFILL_Y_PIPE; @@ -199,7 +208,8 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int } } else{ for (int i = *y_start; i < *y_start + laenge/2; i++) { - if (i <= 0) { + if (i >= (GRID_GROESSE_Y / 2)*2 - 1) { + *y_start = laenge/2; return; } grid[i][*x_start] = INFILL_Y_PIPE; @@ -263,15 +273,16 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { char key_input = (char)getch_directions(); switch (key_input) { - case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - default: return 0; + case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'q': return 0; + default: continue; } @@ -285,17 +296,17 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { } - if (DEBUGGER_RANDOM) { - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - } +// if (DEBUGGER_RANDOM) { +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// } From 091e66c85dfc369c4fe1d5b8cad9f14b7451d2c5 Mon Sep 17 00:00:00 2001 From: Noah69420 Date: Fri, 13 Dec 2024 18:07:35 +0100 Subject: [PATCH 4/4] =?UTF-8?q?unn=C3=B6tiges=20zeugs=20l=C3=B6schen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pipes_test.c | 171 +++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 103 deletions(-) diff --git a/src/pipes_test.c b/src/pipes_test.c index 7bb780d..8037e48 100644 --- a/src/pipes_test.c +++ b/src/pipes_test.c @@ -1,22 +1,24 @@ #include #include #include -#include -#include -#include -#include +#ifdef __linux__ + #include + #include + #include +#endif #define DEBUGGER_PIPES_TO_NUMBERS 0 #define DEBUGGER_RANDOM 0 +#define AUTOMATISCH 0 #define INFILL_PLAIN_PAPER 0 #define INFILL_X_PIPE 1 #define INFILL_Y_PIPE 2 #define FILLER " " // ░ -// #define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid -// #define GRID_GROESSE_Y 60 +//#define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid +//#define GRID_GROESSE_Y 60 #define MIN_LAENGE_PIPE 6 #define MAX_LAENGE_PIPE 6 #define SLEEP_TIMER 5000 // in nano seconds @@ -38,7 +40,7 @@ void random_color() { color = colors[rand() % (sizeof(colors) / sizeof(colors[0]))]; } -int getch_directions(){ +int getch_pipes(){ int ch; struct termios oldattr, newattr; @@ -59,13 +61,6 @@ void print_grid(int x, int y, char **grid) { for (int i = 0; i < y; i++) { printf("\n"); for (int j = 0; j < x; j++) { - /* - switch (grid[i][j]) { - case 0: printf(" "); break; - case 1: printf("━"); break; - case 2: printf("┃"); break; - } - */ if (!DEBUGGER_PIPES_TO_NUMBERS){ if(grid[i][j] == 0){ printf(FILLER); @@ -166,7 +161,7 @@ void print_grid(int x, int y, char **grid) { } } -void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { +void generate_pipe_x(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge) { if(laenge < 0){ for (int i = *x_start; i > *x_start + laenge; i--) { if (i <= -laenge/2 -1) { @@ -175,7 +170,7 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); - print_grid(x, y, grid); + print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid); usleep(SLEEP_TIMER); } } else{ @@ -186,7 +181,7 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); - print_grid(x, y, grid); + print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid); usleep(SLEEP_TIMER); } } @@ -194,7 +189,7 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int *x_start += laenge; } -void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { +void generate_pipe_y(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge) { if(laenge < 0){ for (int i = *y_start; i > *y_start + laenge/2; i--) { if (i <= -laenge/2) { @@ -203,7 +198,7 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int } grid[i][*x_start] = INFILL_Y_PIPE; printf("\33[H\033[J"); - print_grid(x, y, grid); + print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid); usleep(SLEEP_TIMER); } } else{ @@ -214,24 +209,19 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int } grid[i][*x_start] = INFILL_Y_PIPE; printf("\33[H\033[J"); - print_grid(x, y, grid); + print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid); usleep(SLEEP_TIMER); } } - /* - for (int i = *y_start; i < *y_start + laenge/2; i++) { - grid[i][*x_start] = 2; - printf("\33[H\033[J"); - //fflush(stdout); - //usleep(100000); - print_grid(x, y, grid); - sleep_seconds(SLEEP_TIMER); - }*/ *y_start += laenge/2; } -int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { +int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) { +//int main() { +// system("chcp 65001 >null"); +// int GRID_GROESSE_X = 120; // x:y -> 2:1 for a square looking grid +// int GRID_GROESSE_Y = 60; int x_start = GRID_GROESSE_X / 2; int y_start = GRID_GROESSE_Y / 2; @@ -254,59 +244,65 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { } } - //int richtungswechsler = 1; - + int richtungswechsler = 1; + while (!DEBUGGER_RANDOM) { - if ((rand() %color_c_p) <= 1) { - random_color(); - } + while (!AUTOMATISCH) { + if ((rand() %color_c_p) <= 1) { + random_color(); + } - laenge = ((rand() %max_l)+min_l); - - //if ((rand() %2)-1) { - // laenge = ((rand() %max_l)+min_l); - //} else { - // laenge = ((rand() %max_l)+min_l)*-1; - //} + laenge = ((rand() %max_l)+min_l); - char key_input = (char)getch_directions(); + char key_input = (char)getch_pipes(); - switch (key_input) { - case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; - case 'q': return 0; - default: continue; + switch (key_input) { + case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; + case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; + case 'q': return 0; + default: continue; + } } - // if (richtungswechsler == 1) { - // generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - // richtungswechsler *= -1; - // } else { - // generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - // richtungswechsler *= -1; - // } + while (AUTOMATISCH) { + if ((rand() %color_c_p) <= 1) { + random_color(); + } + if ((rand() %2)-1) { + laenge = ((rand() %max_l)+min_l); + } else { + laenge = ((rand() %max_l)+min_l)*-1; + } + if (richtungswechsler == 1) { + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + richtungswechsler *= -1; + } else { + generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + richtungswechsler *= -1; + } + } } -// if (DEBUGGER_RANDOM) { -// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); -// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); -// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); -// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); -// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); -// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); -// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); -// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); -// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); -// } + if (DEBUGGER_RANDOM) { + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); + generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); + generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); + generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); + } @@ -318,34 +314,3 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { return 0; } - -int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) { -//int main() { - //int GRID_GROESSE_X = 100; - //int GRID_GROESSE_Y = 50; - pid_t pid; - int status; - - while (1) { - - pid = fork(); // Erzeuge einen neuen Prozess - if (pid == 0) { - // Kindprozess führt die Hauptlogik aus - main_program(GRID_GROESSE_X, GRID_GROESSE_Y); - exit(0); // Normales Beenden, falls kein Fehler - } else if (pid > 0) { - // Elternprozess wartet auf das Kind - wait(&status); - if (WIFEXITED(status)) { - break; // Beende die Schleife, falls alles ok ist - } else if (WIFSIGNALED(status)) { - } - } else { - perror("Fehler bei fork()"); - exit(1); - } - } - - return 0; -} -