From 7450135530b2079a2910e6b7a6aeba980f0fab11 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 11:42:09 +0100 Subject: [PATCH 01/58] minesweeper rough structure --- src/main/c/Minesweeper/minesweeper_start.c | 62 ++++++++++++++++++++++ src/main/c/Minesweeper/minesweeper_start.h | 16 ++++++ src/main/c/Snake/snake_start.c | 22 ++++---- src/main/c/Snake/snake_start.h | 8 +-- src/main/c/main.c | 12 ++--- 5 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 src/main/c/Minesweeper/minesweeper_start.c create mode 100644 src/main/c/Minesweeper/minesweeper_start.h diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c new file mode 100644 index 0000000..7b28bd1 --- /dev/null +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -0,0 +1,62 @@ +#include +#include +#define BLOCK 219 +#define FLAG '?' +#define EMPTY ' ' + + +#pragma region Funktion_heads +void main_menu_minesweeper(); +void game_minesweeper(); +void options_minesweeper(); +#pragma endregion + +#pragma region Global +#pragma endregion //Global + + +int minesweeper_start(){ + system("clear"); + main_menu_minesweeper(); +} + +void main_menu_minesweeper(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Start\n"); + printf("\t2.Options\n"); + printf("\t3.Exit\n"); + + scanf("%d", &option); + getchar(); + + system("clear"); + + switch (option){ + case 1: + game_minesweeper(); + break; + case 2: + options_minesweeper(); + break; + case 3: + running = false; + break; + + default: + break; + } + } +} + +void game_minesweeper(){ + +} + +void options_minesweeper(){ + +} \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h new file mode 100644 index 0000000..1bb6a7d --- /dev/null +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -0,0 +1,16 @@ +#ifndef MINESWEEPER_START_H +#define MINESWEEPER_START_H + +typedef struct Minesweeper_Board{ + unsigned int width; + unsigned int height; + char *tiles; + int num_bombs; + unsigned int bombs[]; +}Minesweeper_Board; + + +void minesweeper_start(); + + +#endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index f6b7996..f3ce799 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -5,15 +5,17 @@ #include #include "snake_start.h" #include "get_character.h" +#define WIDTH 15 +#define HEIGHT 15 #define TURN 0.5 #define START_LENGTH 3 #define START_DIRECTION 1 #define START_TILE 8 * 16 + 8 #pragma region Funktion_heads -void main_menu(); -void game(); -void options(); +void main_menu_snake(); +void game_snake(); +void options_snake(); Snake initialize_snake(); void get_next_move(double limit, Snake *snake, bool *running); void move_snake(Snake *snake); @@ -30,10 +32,10 @@ double TIME_TURN = 0.5; void snake_start(){ system("clear"); - main_menu(); + main_menu_snake(); } -void main_menu(){ +void main_menu_snake(){ bool running = true; while (running){ int option = 0; @@ -51,10 +53,10 @@ void main_menu(){ switch (option){ case 1: - game(); + game_snake(); break; case 2: - options(); + options_snake(); break; case 3: running = false; @@ -66,7 +68,7 @@ void main_menu(){ } } -void game(){ +void game_snake(){ Snake snake = initialize_snake(); bool running = true; clock_t t = clock(); @@ -84,12 +86,12 @@ void game(){ } } -void options(){ +void options_snake(){ int difficulty = 1; system("clear"); printf("Please select a difficulty(1 - 10): "); scanf("%d", &difficulty); - TIME_TURN = TURN / difficulty;//(11 - difficulty) * TURN / 10; + TIME_TURN = TURN / difficulty; } Snake initialize_snake(){ diff --git a/src/main/c/Snake/snake_start.h b/src/main/c/Snake/snake_start.h index 1634146..359f548 100644 --- a/src/main/c/Snake/snake_start.h +++ b/src/main/c/Snake/snake_start.h @@ -1,14 +1,10 @@ #ifndef SNAKE_START_H #define SNAKE_START_H -#define HEIGHT 15 -#define WIDTH 15 -#define AREA HEIGHT * WIDTH - -typedef struct{ +typedef struct Snake{ signed char direction; char length; - unsigned char segments[AREA]; + unsigned char segments[225]; }Snake; diff --git a/src/main/c/main.c b/src/main/c/main.c index 922c8d4..11be6b7 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -2,8 +2,8 @@ #include #include -#include "Template/game100.h" #include "Snake/snake_start.h" +#include "Minesweeper/minesweeper_start.h" int main(){ bool running = true; @@ -18,8 +18,8 @@ int main(){ printf("\t2.Spiel2 starten\n"); printf("\t3.Snake starten\n"); printf("\t4.Spiel4 starten\n"); - printf("\t100.Template starten\n"); - printf("\t6.Exit\n"); + printf("\t7.Minesweeper starten\n"); + printf("\t10.Exit\n"); scanf("%d", &option); getchar(); @@ -37,10 +37,10 @@ int main(){ case 4: //start_game4(); break; - case 100: - start_game100(); + case 7: + minesweeper_start(); break; - case 6: + case 10: system("clear"); running = false; break; From 7f81bd04dd2cccac2e941e44a5a8e1102681ca06 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 12:31:57 +0100 Subject: [PATCH 02/58] added game options --- src/main/c/Minesweeper/minesweeper_start.c | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 7b28bd1..2737d4d 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -1,8 +1,16 @@ #include #include +#pragma region defines #define BLOCK 219 #define FLAG '?' #define EMPTY ' ' +#define SMALL 10 +#define MIDDLE 15 +#define LARGE 20 +#define EASY 7 +#define NORMAL 5 +#define HARD 3 +#pragma endregion #pragma region Funktion_heads @@ -12,6 +20,9 @@ void options_minesweeper(); #pragma endregion #pragma region Global +unsigned int width = MIDDLE; +unsigned int height = MIDDLE; +int num_bombs = MIDDLE * MIDDLE / NORMAL; #pragma endregion //Global @@ -58,5 +69,54 @@ void game_minesweeper(){ } void options_minesweeper(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Schwierigkeit\t\t%s\n", num_bombs < 2 * width * height / (NORMAL + EASY) ? "Einfach" : num_bombs < 2 * width * height / (NORMAL + HARD) ? "Normal" : "Schwer"); + printf("\t2.Groesse\t\t%s\n", width * height < MIDDLE * SMALL ? "Klein" : width * height < MIDDLE * LARGE ? "Mittel" : "Gross"); + printf("\t3.Custom\n"); + printf("\t4.Exit\n"); + + scanf("%d", &option); + getchar(); + switch (option){ + case 1: + printf("Bitte neu Schwierigkeit eingeben (1 - 3):"); + scanf("%d", &num_bombs); + getchar(); + num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; + num_bombs = width * height / num_bombs; + break; + case 2: + num_bombs = num_bombs < width * height / NORMAL ? EASY : num_bombs == width * height / NORMAL ? NORMAL : HARD; + printf("Bitte neu Groesse eingeben (1 - 3):"); + scanf("%d", &width); + getchar(); + width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; + height = width; + num_bombs = width * height / num_bombs; + break; + case 3: + printf("Bitte Breite des Spielfeld eingeben:"); + scanf("%d", &width); + getchar(); + printf("Bitte Hoehe des Spielfeld eingeben:"); + scanf("%d", &height); + getchar(); + printf("Bitte Anzahl der Bomben eingeben:"); + scanf("%d", &num_bombs); + getchar(); + break; + case 4: + running = false; + break; + + default: + break; + } + } } \ No newline at end of file From c1e8a99e7a7b9a7895f0ea396466170a5d49947d Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 12:55:28 +0100 Subject: [PATCH 03/58] initialize minesweeper --- src/main/c/Minesweeper/minesweeper_start.c | 25 ++++++++++++++++++++-- src/main/c/Minesweeper/minesweeper_start.h | 2 +- src/main/c/Snake/snake_start.c | 6 +++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 2737d4d..3f46eec 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -1,5 +1,7 @@ #include +#include #include +#include "minesweeper_start.h" #pragma region defines #define BLOCK 219 #define FLAG '?' @@ -17,6 +19,8 @@ void main_menu_minesweeper(); void game_minesweeper(); void options_minesweeper(); +Minesweeper_Board initialize_minesweeper(); +void draw_minesweeper(); #pragma endregion #pragma region Global @@ -26,7 +30,7 @@ int num_bombs = MIDDLE * MIDDLE / NORMAL; #pragma endregion //Global -int minesweeper_start(){ +void minesweeper_start(){ system("clear"); main_menu_minesweeper(); } @@ -65,7 +69,8 @@ void main_menu_minesweeper(){ } void game_minesweeper(){ - + Minesweeper_Board board = initialize_minesweeper(); + draw_minesweeper(); } void options_minesweeper(){ @@ -119,4 +124,20 @@ void options_minesweeper(){ break; } } +} + +Minesweeper_Board initialize_minesweeper(){ + Minesweeper_Board board; + board.width = width; + board.height = height; + char *tiles = (char*) malloc(width * height * sizeof(char)); + for(int i = 0; i < width * height; i++){tiles[i] = FLAG;} + board.tiles = tiles; + board.num_bombs = num_bombs; + + return board; +} + +void draw_minesweeper(){ + } \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index 1bb6a7d..bf0f21a 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -6,7 +6,7 @@ typedef struct Minesweeper_Board{ unsigned int height; char *tiles; int num_bombs; - unsigned int bombs[]; + int *bombs; }Minesweeper_Board; diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index f3ce799..26c83c4 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -19,7 +19,7 @@ void options_snake(); Snake initialize_snake(); void get_next_move(double limit, Snake *snake, bool *running); void move_snake(Snake *snake); -void draw(Snake *snake, unsigned char fruit); +void draw_snake(Snake *snake, unsigned char fruit); int part_of_snake(Snake *snake, unsigned char tile); bool check_if_dead(Snake *snake); unsigned char spawn_fruit(Snake *snake); @@ -76,7 +76,7 @@ void game_snake(){ while (running){ system("clear"); - draw(&snake, fruit); + draw_snake(&snake, fruit); if(check_if_dead(&snake)){break;} t = clock() - t; get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); @@ -141,7 +141,7 @@ void move_snake(Snake *snake){ snake->segments[0] += snake->direction; } -void draw(Snake *snake, unsigned char fruit){ +void draw_snake(Snake *snake, unsigned char fruit){ printf("Score:%d Speed:%f\n", snake->length - START_LENGTH, TIME_TURN); printf("+"); for(int i = 0; i < WIDTH; i++){printf("-");} From e1afeb3974b1a2fc4b4a8a254bf091d36e6621f4 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 13:23:22 +0100 Subject: [PATCH 04/58] draw minesweeper --- src/main/c/Minesweeper/minesweeper_start.c | 46 ++++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 3f46eec..8dcc78f 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -3,7 +3,7 @@ #include #include "minesweeper_start.h" #pragma region defines -#define BLOCK 219 +#define BLOCK '#' #define FLAG '?' #define EMPTY ' ' #define SMALL 10 @@ -20,7 +20,7 @@ void main_menu_minesweeper(); void game_minesweeper(); void options_minesweeper(); Minesweeper_Board initialize_minesweeper(); -void draw_minesweeper(); +void draw_minesweeper(Minesweeper_Board board); #pragma endregion #pragma region Global @@ -69,8 +69,15 @@ void main_menu_minesweeper(){ } void game_minesweeper(){ - Minesweeper_Board board = initialize_minesweeper(); - draw_minesweeper(); + bool running = true; + int q = 0; + while (running){ + Minesweeper_Board board = initialize_minesweeper(); + draw_minesweeper(board); + + scanf("%d", &q); + if (q == 1){break;} + } } void options_minesweeper(){ @@ -90,7 +97,7 @@ void options_minesweeper(){ switch (option){ case 1: - printf("Bitte neu Schwierigkeit eingeben (1 - 3):"); + printf("Bitte neu Schwierigkeit eingeben (1 - 3): "); scanf("%d", &num_bombs); getchar(); num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; @@ -98,7 +105,7 @@ void options_minesweeper(){ break; case 2: num_bombs = num_bombs < width * height / NORMAL ? EASY : num_bombs == width * height / NORMAL ? NORMAL : HARD; - printf("Bitte neu Groesse eingeben (1 - 3):"); + printf("Bitte neu Groesse eingeben (1 - 3): "); scanf("%d", &width); getchar(); width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; @@ -106,13 +113,13 @@ void options_minesweeper(){ num_bombs = width * height / num_bombs; break; case 3: - printf("Bitte Breite des Spielfeld eingeben:"); + printf("Bitte Breite des Spielfeld eingeben: "); scanf("%d", &width); getchar(); - printf("Bitte Hoehe des Spielfeld eingeben:"); + printf("Bitte Hoehe des Spielfeld eingeben: "); scanf("%d", &height); getchar(); - printf("Bitte Anzahl der Bomben eingeben:"); + printf("Bitte Anzahl der Bomben eingeben: "); scanf("%d", &num_bombs); getchar(); break; @@ -131,13 +138,28 @@ Minesweeper_Board initialize_minesweeper(){ board.width = width; board.height = height; char *tiles = (char*) malloc(width * height * sizeof(char)); - for(int i = 0; i < width * height; i++){tiles[i] = FLAG;} + for(int i = 0; i < width * height; i++){tiles[i] = BLOCK;} board.tiles = tiles; board.num_bombs = num_bombs; return board; } -void draw_minesweeper(){ - +void draw_minesweeper(Minesweeper_Board board){ + printf(" "); + for(int i = 0; i < board.width; i++){printf("%d", i / 10);} + printf("\n "); + for(int i = 0; i < board.width; i++){printf("%d", i % 10);} + printf("\n +"); + for(int i = 0; i < board.width; i++){printf("-");} + printf("+\n"); + for(int i = 0; i < board.height; i++){ + printf("%d", i / 10); + printf("%d|", i % 10); + for(int j = 0; j < board.width; j++){printf("%c", board.tiles[i * width + j]);} + printf("|\n"); + } + printf(" +"); + for(int i = 0; i < board.width; i++){printf("-");} + printf("+\n"); } \ No newline at end of file From 50608d06187f4d860ba282586443197adcafcfa6 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 14:00:13 +0100 Subject: [PATCH 05/58] placing bombs --- src/main/c/Minesweeper/minesweeper_start.c | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 8dcc78f..298f61d 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "minesweeper_start.h" #pragma region defines #define BLOCK '#' @@ -20,6 +21,8 @@ void main_menu_minesweeper(); void game_minesweeper(); void options_minesweeper(); Minesweeper_Board initialize_minesweeper(); +void place_bombs(Minesweeper_Board *board); +bool bomb_in_array(int array[], int bomb, int length); void draw_minesweeper(Minesweeper_Board board); #pragma endregion @@ -70,13 +73,15 @@ void main_menu_minesweeper(){ void game_minesweeper(){ bool running = true; - int q = 0; + int x, y, t; while (running){ Minesweeper_Board board = initialize_minesweeper(); draw_minesweeper(board); - scanf("%d", &q); - if (q == 1){break;} + printf("Next turn (x, y, t(0 = open, 1 = flag)): "); + scanf("%d %d %d", &x, &y, &t); + getchar(); + if (t == 2){break;} } } @@ -137,14 +142,33 @@ Minesweeper_Board initialize_minesweeper(){ Minesweeper_Board board; board.width = width; board.height = height; - char *tiles = (char*) malloc(width * height * sizeof(char)); - for(int i = 0; i < width * height; i++){tiles[i] = BLOCK;} - board.tiles = tiles; + board.tiles = (char*) malloc(width * height * sizeof(char)); + for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} board.num_bombs = num_bombs; - + place_bombs(&board); return board; } +void place_bombs(Minesweeper_Board *board){ + board->bombs = (int*) malloc(board->num_bombs * sizeof(int)); + srand(time(NULL)); + int r; + for(int i = 0; i < board->num_bombs; i++){ + while (1){ + r = rand() % (board->width * board->height); + if(!bomb_in_array(board->bombs, r, board->num_bombs)){break;} + } + board->bombs[i] = r; + } +} + +bool bomb_in_array(int array[], int bomb, int length){ + for(int i = 0; i < length; i++){ + if(array[i] == bomb){return true;} + } + return false; +} + void draw_minesweeper(Minesweeper_Board board){ printf(" "); for(int i = 0; i < board.width; i++){printf("%d", i / 10);} From a910d7d7098296cac7b1db991be35a40942d672f Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 14:16:10 +0100 Subject: [PATCH 06/58] marking and unmarking flags --- src/main/c/Minesweeper/minesweeper_start.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 298f61d..fd58cfe 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -74,13 +74,17 @@ void main_menu_minesweeper(){ void game_minesweeper(){ bool running = true; int x, y, t; + Minesweeper_Board board = initialize_minesweeper(); while (running){ - Minesweeper_Board board = initialize_minesweeper(); + system("clear"); draw_minesweeper(board); printf("Next turn (x, y, t(0 = open, 1 = flag)): "); scanf("%d %d %d", &x, &y, &t); getchar(); + if(t == 1){board.tiles[x + y * board.width] = board.tiles[x + y * board.width] == EMPTY ? EMPTY : board.tiles[x + y * board.width] == FLAG ? BLOCK : FLAG;} + + if (t == 2){break;} } } From c49cdc2e37aa5551297c61fae1ba8919ed51692c Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 14:26:04 +0100 Subject: [PATCH 07/58] refactoring: placing bombs calculating marking tile --- src/main/c/Minesweeper/minesweeper_start.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index fd58cfe..85dc9d1 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -75,6 +75,8 @@ void game_minesweeper(){ bool running = true; int x, y, t; Minesweeper_Board board = initialize_minesweeper(); + place_bombs(&board); + while (running){ system("clear"); draw_minesweeper(board); @@ -82,9 +84,10 @@ void game_minesweeper(){ printf("Next turn (x, y, t(0 = open, 1 = flag)): "); scanf("%d %d %d", &x, &y, &t); getchar(); - if(t == 1){board.tiles[x + y * board.width] = board.tiles[x + y * board.width] == EMPTY ? EMPTY : board.tiles[x + y * board.width] == FLAG ? BLOCK : FLAG;} - - + if(x < board.width && y < board.height){ + x = x + y * board.width; + if(t == 1){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} + } if (t == 2){break;} } } @@ -149,12 +152,12 @@ Minesweeper_Board initialize_minesweeper(){ board.tiles = (char*) malloc(width * height * sizeof(char)); for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} board.num_bombs = num_bombs; - place_bombs(&board); + board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); + for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;} return board; } void place_bombs(Minesweeper_Board *board){ - board->bombs = (int*) malloc(board->num_bombs * sizeof(int)); srand(time(NULL)); int r; for(int i = 0; i < board->num_bombs; i++){ From 063eb9ebe040e53d5f170ffd62089f2e847ec2a6 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 14:39:53 +0100 Subject: [PATCH 08/58] Test test if tile has a bomb --- src/main/c/Minesweeper/minesweeper_start.h | 1 + test/Minesweeper/test_bomb_in_array.c | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/Minesweeper/test_bomb_in_array.c diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index bf0f21a..a73d944 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -11,6 +11,7 @@ typedef struct Minesweeper_Board{ void minesweeper_start(); +bool bomb_in_array(int array[], int bomb, int length); #endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/test/Minesweeper/test_bomb_in_array.c b/test/Minesweeper/test_bomb_in_array.c new file mode 100644 index 0000000..710791b --- /dev/null +++ b/test/Minesweeper/test_bomb_in_array.c @@ -0,0 +1,25 @@ +#ifdef TEST +#include "unity.h" +#include +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_bomb_in_array(void){ + /* arrange */ + bool result; + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + int bomb = 42; + int length = 10; + + /* act */ + result = bomb_in_array(array, bomb, length); + + /* assert */ + TEST_ASSERT_TRUE(result);//head collides with body +} + +#endif // TEST \ No newline at end of file From 72f8a44cc1d2c5ab3cefe1fa2ab0f679abc44671 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 15:59:03 +0100 Subject: [PATCH 09/58] Test if tile has no bomb --- src/main/c/Minesweeper/minesweeper_start.c | 9 ++++++++- test/Minesweeper/test_bomb_in_array.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 85dc9d1..50bb461 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -24,6 +24,7 @@ Minesweeper_Board initialize_minesweeper(); void place_bombs(Minesweeper_Board *board); bool bomb_in_array(int array[], int bomb, int length); void draw_minesweeper(Minesweeper_Board board); +int open_tile(Minesweeper_Board *board, int tile); #pragma endregion #pragma region Global @@ -84,8 +85,9 @@ void game_minesweeper(){ printf("Next turn (x, y, t(0 = open, 1 = flag)): "); scanf("%d %d %d", &x, &y, &t); getchar(); - if(x < board.width && y < board.height){ + if(x < board.width && x > -1 && y < board.height && y > -1){ x = x + y * board.width; + if(t == 0){running = open_tile(&board, x);} if(t == 1){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} } if (t == 2){break;} @@ -193,4 +195,9 @@ void draw_minesweeper(Minesweeper_Board board){ printf(" +"); for(int i = 0; i < board.width; i++){printf("-");} printf("+\n"); +} + +int open_tile(Minesweeper_Board *board, int tile){ + if(bomb_in_array(board->bombs, tile, board->num_bombs)){return -1;} + } \ No newline at end of file diff --git a/test/Minesweeper/test_bomb_in_array.c b/test/Minesweeper/test_bomb_in_array.c index 710791b..2e97c56 100644 --- a/test/Minesweeper/test_bomb_in_array.c +++ b/test/Minesweeper/test_bomb_in_array.c @@ -22,4 +22,19 @@ void test_bomb_in_array(void){ TEST_ASSERT_TRUE(result);//head collides with body } + +void test_bomb_not_in_array(void){ + /* arrange */ + bool result; + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + int bomb = 0; + int length = 10; + + /* act */ + result = bomb_in_array(array, bomb, length); + + /* assert */ + TEST_ASSERT_FALSE(result);//head collides with body +} + #endif // TEST \ No newline at end of file From 2a8cefa322d5359746f4591563a20c269b933c66 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 17:30:10 +0100 Subject: [PATCH 10/58] Test no bombs araound tile --- src/main/c/Minesweeper/minesweeper_start.c | 19 +++++++++++++++++ src/main/c/Minesweeper/minesweeper_start.h | 2 ++ test/Minesweeper/test_number_of_bombs.c | 24 ++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 test/Minesweeper/test_number_of_bombs.c diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 50bb461..43a1eed 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -25,6 +25,7 @@ void place_bombs(Minesweeper_Board *board); bool bomb_in_array(int array[], int bomb, int length); void draw_minesweeper(Minesweeper_Board board); int open_tile(Minesweeper_Board *board, int tile); +int number_of_bombs(Minesweeper_Board *board, int tile); #pragma endregion #pragma region Global @@ -199,5 +200,23 @@ void draw_minesweeper(Minesweeper_Board board){ int open_tile(Minesweeper_Board *board, int tile){ if(bomb_in_array(board->bombs, tile, board->num_bombs)){return -1;} + int num = number_of_bombs(board, tile); +} + +int number_of_bombs(Minesweeper_Board *board, int tile){ + int sum = 0; + for(int i = 0; i < 8; i++){ + int check_tile = tile; + if(i < 3 && tile % board->width == 0){continue;} + else{check_tile - 1;} + if(i > 4 && tile % board->width + 1 == board->width){continue;} + else{check_tile + 1;} + if(i % 3 == 0 && i != 0 && tile / board->width == 0){continue;} + else{check_tile - board->width;} + if(i % 3 == 1 && tile / board->width + 1 == height){continue;} + else{check_tile + board->width;} + if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;} + } + return sum; } \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index a73d944..c62977b 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -11,7 +11,9 @@ typedef struct Minesweeper_Board{ void minesweeper_start(); +Minesweeper_Board initialize_minesweeper(); bool bomb_in_array(int array[], int bomb, int length); +int number_of_bombs(Minesweeper_Board *board, int tile); #endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c new file mode 100644 index 0000000..3f899f7 --- /dev/null +++ b/test/Minesweeper/test_number_of_bombs.c @@ -0,0 +1,24 @@ +#ifdef TEST +#include "unity.h" +#include +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_no_bombs_placed_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 1 + board.width * 1; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed +} + +#endif // TEST \ No newline at end of file From 6e0233c784d56d4cdfe10d3120ee0159d572a3c0 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 17:39:25 +0100 Subject: [PATCH 11/58] Test bombs near but not around tile --- test/Minesweeper/test_bomb_in_array.c | 4 ++-- test/Minesweeper/test_number_of_bombs.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/test/Minesweeper/test_bomb_in_array.c b/test/Minesweeper/test_bomb_in_array.c index 2e97c56..8aae16d 100644 --- a/test/Minesweeper/test_bomb_in_array.c +++ b/test/Minesweeper/test_bomb_in_array.c @@ -19,7 +19,7 @@ void test_bomb_in_array(void){ result = bomb_in_array(array, bomb, length); /* assert */ - TEST_ASSERT_TRUE(result);//head collides with body + TEST_ASSERT_TRUE(result); } @@ -34,7 +34,7 @@ void test_bomb_not_in_array(void){ result = bomb_in_array(array, bomb, length); /* assert */ - TEST_ASSERT_FALSE(result);//head collides with body + TEST_ASSERT_FALSE(result); } #endif // TEST \ No newline at end of file diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c index 3f899f7..e449f33 100644 --- a/test/Minesweeper/test_number_of_bombs.c +++ b/test/Minesweeper/test_number_of_bombs.c @@ -21,4 +21,21 @@ void test_no_bombs_placed_around_tile(void){ TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed } +void test_searching_for_bombs_on_correct_tiles(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0 + board.width * 1; + board.bombs[0] = 0 + board.width * 2; + board.bombs[0] = 2 + board.width * 1; + board.bombs[0] = board.width - 1 + board.width * 1; + board.bombs[0] = 0 + board.width * (board.height - 1); + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed around tile +} + #endif // TEST \ No newline at end of file From 79c871c7ff3ead2265e8f9a390d8f829e5924bb1 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 18:13:20 +0100 Subject: [PATCH 12/58] Test 2 bombs around tile --- src/main/c/Minesweeper/minesweeper_start.c | 16 ++++++------- test/Minesweeper/test_number_of_bombs.c | 27 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 43a1eed..98eb0eb 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -208,14 +208,14 @@ int number_of_bombs(Minesweeper_Board *board, int tile){ int sum = 0; for(int i = 0; i < 8; i++){ int check_tile = tile; - if(i < 3 && tile % board->width == 0){continue;} - else{check_tile - 1;} - if(i > 4 && tile % board->width + 1 == board->width){continue;} - else{check_tile + 1;} - if(i % 3 == 0 && i != 0 && tile / board->width == 0){continue;} - else{check_tile - board->width;} - if(i % 3 == 1 && tile / board->width + 1 == height){continue;} - else{check_tile + board->width;} + if(i < 3){if(tile % board->width == 0){continue;} + else{check_tile -= 1;}} + if(i > 4){if(tile % board->width + 1 == board->width){continue;} + else{check_tile += 1;}} + if(i % 3 == 0){if(i != 0 && tile / board->width == 0){continue;} + else{check_tile -= board->width;}} + if(i % 3 == 1){if(tile / board->width + 1 == height){continue;} + else{check_tile += board->width;}} if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;} } return sum; diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c index e449f33..047c475 100644 --- a/test/Minesweeper/test_number_of_bombs.c +++ b/test/Minesweeper/test_number_of_bombs.c @@ -12,7 +12,7 @@ void test_no_bombs_placed_around_tile(void){ /* arrange */ int result; Minesweeper_Board board = initialize_minesweeper(); - int tile = 1 + board.width * 1; + int tile = 0 + board.width * 1; /* act */ result = number_of_bombs(&board, tile); @@ -26,10 +26,10 @@ void test_searching_for_bombs_on_correct_tiles(void){ int result; Minesweeper_Board board = initialize_minesweeper(); int tile = 0 + board.width * 1; - board.bombs[0] = 0 + board.width * 2; - board.bombs[0] = 2 + board.width * 1; - board.bombs[0] = board.width - 1 + board.width * 1; - board.bombs[0] = 0 + board.width * (board.height - 1); + board.bombs[0] = 0 + board.width * 3; + board.bombs[1] = 2 + board.width * 1; + board.bombs[2] = board.width - 1 + board.width * 1; + board.bombs[3] = 0 + board.width * (board.height - 1); /* act */ result = number_of_bombs(&board, tile); @@ -38,4 +38,21 @@ void test_searching_for_bombs_on_correct_tiles(void){ TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed around tile } +void test_2_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0 + board.width * 1; + board.bombs[0] = 0 + board.width * 2; + board.bombs[1] = 1 + board.width * 1; + board.bombs[2] = board.width - 1 + board.width * 1; + board.bombs[3] = 0 + board.width * (board.height - 1); + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(2, result);//2 bombs placed around tile +} + #endif // TEST \ No newline at end of file From 616ffae6b48f45dc917d61e4962d6a54fc43594a Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 18:21:30 +0100 Subject: [PATCH 13/58] Test 5 or 8 bombs around tile --- test/Minesweeper/test_number_of_bombs.c | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c index 047c475..6a0dd4f 100644 --- a/test/Minesweeper/test_number_of_bombs.c +++ b/test/Minesweeper/test_number_of_bombs.c @@ -55,4 +55,43 @@ void test_2_bombs_around_tile(void){ TEST_ASSERT_EQUAL_INT(2, result);//2 bombs placed around tile } +void test_5_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 1 + board.width * 0; + board.bombs[0] = 0 + board.width * 0; + board.bombs[1] = 2 + board.width * 0; + board.bombs[2] = 0 + board.width * 1; + board.bombs[3] = 1 + board.width * 1; + board.bombs[4] = 2 + board.width * 1; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(5, result);//5 bombs placed around tile +} + +void test_8_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 7 + board.width * 7; + board.bombs[0] = 6 + board.width * 6; + board.bombs[1] = 7 + board.width * 6; + board.bombs[2] = 8 + board.width * 6; + board.bombs[3] = 6 + board.width * 7; + board.bombs[4] = 8 + board.width * 7; + board.bombs[5] = 6 + board.width * 8; + board.bombs[6] = 7 + board.width * 8; + board.bombs[7] = 8 + board.width * 8; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(8, result);//2 bombs placed around tile +} + #endif // TEST \ No newline at end of file From a004b66a33412dcc9e49ea169d08116a428374e3 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 20:22:53 +0100 Subject: [PATCH 14/58] Minesweeper is playable --- src/main/c/Minesweeper/minesweeper_start.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 98eb0eb..48bf4d9 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -88,7 +88,12 @@ void game_minesweeper(){ getchar(); if(x < board.width && x > -1 && y < board.height && y > -1){ x = x + y * board.width; - if(t == 0){running = open_tile(&board, x);} + if(t == 0){ + int bombs = open_tile(&board, x); + if(bombs == -1){running = false;} + else if(bombs == 0){board.tiles[x] = EMPTY;} + else{board.tiles[x] = bombs + 48;} + } if(t == 1){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} } if (t == 2){break;} @@ -201,7 +206,7 @@ void draw_minesweeper(Minesweeper_Board board){ int open_tile(Minesweeper_Board *board, int tile){ if(bomb_in_array(board->bombs, tile, board->num_bombs)){return -1;} int num = number_of_bombs(board, tile); - + if(1){return num;} } int number_of_bombs(Minesweeper_Board *board, int tile){ From 2367550137e9c3c30e57e53bb00d4d36e6bba6b8 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 21:03:38 +0100 Subject: [PATCH 15/58] wip batch opening --- src/main/c/Minesweeper/minesweeper_start.c | 54 ++++++++++++++++------ src/main/c/Minesweeper/minesweeper_start.h | 5 +- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 48bf4d9..a16a24b 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -22,10 +22,12 @@ void game_minesweeper(); void options_minesweeper(); Minesweeper_Board initialize_minesweeper(); void place_bombs(Minesweeper_Board *board); -bool bomb_in_array(int array[], int bomb, int length); -void draw_minesweeper(Minesweeper_Board board); +bool bomb_in_array(int *array, int bomb, int length); +bool array_contains_value(int *array, int value, int length); +void draw_minesweeper(Minesweeper_Board *board); int open_tile(Minesweeper_Board *board, int tile); int number_of_bombs(Minesweeper_Board *board, int tile); +void open_empty_space(Minesweeper_Board *board, int tile, int index); #pragma endregion #pragma region Global @@ -77,11 +79,12 @@ void game_minesweeper(){ bool running = true; int x, y, t; Minesweeper_Board board = initialize_minesweeper(); + place_bombs(&board); while (running){ system("clear"); - draw_minesweeper(board); + draw_minesweeper(&board); printf("Next turn (x, y, t(0 = open, 1 = flag)): "); scanf("%d %d %d", &x, &y, &t); @@ -91,7 +94,7 @@ void game_minesweeper(){ if(t == 0){ int bombs = open_tile(&board, x); if(bombs == -1){running = false;} - else if(bombs == 0){board.tiles[x] = EMPTY;} + else if(bombs == 0){open_empty_space(&board, x, 0);} else{board.tiles[x] = bombs + 48;} } if(t == 1){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} @@ -157,8 +160,10 @@ Minesweeper_Board initialize_minesweeper(){ Minesweeper_Board board; board.width = width; board.height = height; - board.tiles = (char*) malloc(width * height * sizeof(char)); + board.tiles = (int*) malloc(width * height * sizeof(int)); for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} + board.marked = (int*) malloc(width * height * sizeof(int)); + for(int i = 0; i < width * height; i++){board.tiles[i] = 0;} board.num_bombs = num_bombs; board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;} @@ -177,29 +182,33 @@ void place_bombs(Minesweeper_Board *board){ } } -bool bomb_in_array(int array[], int bomb, int length){ +bool bomb_in_array(int *array, int bomb, int length){ for(int i = 0; i < length; i++){ if(array[i] == bomb){return true;} } return false; } -void draw_minesweeper(Minesweeper_Board board){ +bool array_contains_value(int *array, int value, int length){ + +} + +void draw_minesweeper(Minesweeper_Board *board){ printf(" "); - for(int i = 0; i < board.width; i++){printf("%d", i / 10);} + for(int i = 0; i < board->width; i++){printf("%d", i / 10);} printf("\n "); - for(int i = 0; i < board.width; i++){printf("%d", i % 10);} + for(int i = 0; i < board->width; i++){printf("%d", i % 10);} printf("\n +"); - for(int i = 0; i < board.width; i++){printf("-");} + for(int i = 0; i < board->width; i++){printf("-");} printf("+\n"); - for(int i = 0; i < board.height; i++){ + for(int i = 0; i < board->height; i++){ printf("%d", i / 10); printf("%d|", i % 10); - for(int j = 0; j < board.width; j++){printf("%c", board.tiles[i * width + j]);} + for(int j = 0; j < board->width; j++){printf("%c", board->tiles[i * width + j]);} printf("|\n"); } printf(" +"); - for(int i = 0; i < board.width; i++){printf("-");} + for(int i = 0; i < board->width; i++){printf("-");} printf("+\n"); } @@ -224,4 +233,23 @@ int number_of_bombs(Minesweeper_Board *board, int tile){ if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;} } return sum; +} + +void open_empty_space(Minesweeper_Board *board, int tile, int index){ + board->tiles[tile] = EMPTY; + board->marked[index++] = tile; + for(int i = 0; i < 8; i++){ + int check_tile = tile; + if(i < 3){if(tile % board->width == 0){continue;} + else{check_tile -= 1;}} + if(i > 4){if(tile % board->width + 1 == board->width){continue;} + else{check_tile += 1;}} + if(i % 3 == 0){if(i != 0 && tile / board->width == 0){continue;} + else{check_tile -= board->width;}} + if(i % 3 == 1){if(tile / board->width + 1 == height){continue;} + else{check_tile += board->width;}} + int sum = open_tile(board, check_tile); + if(sum != 0){board->tiles[check_tile] = sum + 48;} + else if(!array_contains_value(board->marked, check_tile, index)){open_empty_space(board, check_tile, index);} + } } \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index c62977b..b577233 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -4,7 +4,8 @@ typedef struct Minesweeper_Board{ unsigned int width; unsigned int height; - char *tiles; + int *tiles; + int *marked; int num_bombs; int *bombs; }Minesweeper_Board; @@ -12,7 +13,7 @@ typedef struct Minesweeper_Board{ void minesweeper_start(); Minesweeper_Board initialize_minesweeper(); -bool bomb_in_array(int array[], int bomb, int length); +bool bomb_in_array(int *array, int bomb, int length); int number_of_bombs(Minesweeper_Board *board, int tile); From 3203609f1abeef01468d8d5cf5ab837158156a5b Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 26 Jan 2024 21:27:55 +0100 Subject: [PATCH 16/58] refactoring: Minesweeper_Board and bomb_in_array to array_contains_value --- src/main/c/Minesweeper/minesweeper_start.c | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index a16a24b..3025597 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -5,7 +5,7 @@ #include "minesweeper_start.h" #pragma region defines #define BLOCK '#' -#define FLAG '?' +#define FLAG 'x' #define EMPTY ' ' #define SMALL 10 #define MIDDLE 15 @@ -163,7 +163,7 @@ Minesweeper_Board initialize_minesweeper(){ board.tiles = (int*) malloc(width * height * sizeof(int)); for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} board.marked = (int*) malloc(width * height * sizeof(int)); - for(int i = 0; i < width * height; i++){board.tiles[i] = 0;} + for(int i = 0; i < width * height; i++){board.marked[i] = 0;} board.num_bombs = num_bombs; board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;} @@ -176,21 +176,24 @@ void place_bombs(Minesweeper_Board *board){ for(int i = 0; i < board->num_bombs; i++){ while (1){ r = rand() % (board->width * board->height); - if(!bomb_in_array(board->bombs, r, board->num_bombs)){break;} + if(!array_contains_value(board->bombs, r, board->num_bombs)){break;} } board->bombs[i] = r; } } -bool bomb_in_array(int *array, int bomb, int length){ +bool bomb_in_array(int *array, int value, int length){ for(int i = 0; i < length; i++){ - if(array[i] == bomb){return true;} + if(array[i] == value){return true;} } return false; } bool array_contains_value(int *array, int value, int length){ - + for(int i = 0; i < length; i++){ + if(array[i] == value){return true;} + } + return false; } void draw_minesweeper(Minesweeper_Board *board){ @@ -205,15 +208,20 @@ void draw_minesweeper(Minesweeper_Board *board){ printf("%d", i / 10); printf("%d|", i % 10); for(int j = 0; j < board->width; j++){printf("%c", board->tiles[i * width + j]);} - printf("|\n"); + printf("|%d", i / 10); + printf("%d\n", i % 10); } printf(" +"); for(int i = 0; i < board->width; i++){printf("-");} - printf("+\n"); + printf("+\n "); + for(int i = 0; i < board->width; i++){printf("%d", i / 10);} + printf("\n "); + for(int i = 0; i < board->width; i++){printf("%d", i % 10);} + printf("\n"); } int open_tile(Minesweeper_Board *board, int tile){ - if(bomb_in_array(board->bombs, tile, board->num_bombs)){return -1;} + if(array_contains_value(board->bombs, tile, board->num_bombs)){return -1;} int num = number_of_bombs(board, tile); if(1){return num;} } @@ -230,7 +238,7 @@ int number_of_bombs(Minesweeper_Board *board, int tile){ else{check_tile -= board->width;}} if(i % 3 == 1){if(tile / board->width + 1 == height){continue;} else{check_tile += board->width;}} - if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;} + if(array_contains_value(board->bombs, check_tile, board->num_bombs)){sum++;} } return sum; } From ad8fc5d7bcb1279df272e1ed3d33f2a4d9d6f5d8 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Sat, 27 Jan 2024 16:05:11 +0100 Subject: [PATCH 17/58] minor fixes --- src/main/c/Minesweeper/minesweeper_start.c | 8 -------- src/main/c/Minesweeper/minesweeper_start.h | 2 +- test/Minesweeper/test_bomb_in_array.c | 4 ++-- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 3025597..fae882a 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -22,7 +22,6 @@ void game_minesweeper(); void options_minesweeper(); Minesweeper_Board initialize_minesweeper(); void place_bombs(Minesweeper_Board *board); -bool bomb_in_array(int *array, int bomb, int length); bool array_contains_value(int *array, int value, int length); void draw_minesweeper(Minesweeper_Board *board); int open_tile(Minesweeper_Board *board, int tile); @@ -182,13 +181,6 @@ void place_bombs(Minesweeper_Board *board){ } } -bool bomb_in_array(int *array, int value, int length){ - for(int i = 0; i < length; i++){ - if(array[i] == value){return true;} - } - return false; -} - bool array_contains_value(int *array, int value, int length){ for(int i = 0; i < length; i++){ if(array[i] == value){return true;} diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index b577233..c37d731 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -13,7 +13,7 @@ typedef struct Minesweeper_Board{ void minesweeper_start(); Minesweeper_Board initialize_minesweeper(); -bool bomb_in_array(int *array, int bomb, int length); +bool array_contains_value(int *array, int bomb, int length); int number_of_bombs(Minesweeper_Board *board, int tile); diff --git a/test/Minesweeper/test_bomb_in_array.c b/test/Minesweeper/test_bomb_in_array.c index 8aae16d..7073857 100644 --- a/test/Minesweeper/test_bomb_in_array.c +++ b/test/Minesweeper/test_bomb_in_array.c @@ -16,7 +16,7 @@ void test_bomb_in_array(void){ int length = 10; /* act */ - result = bomb_in_array(array, bomb, length); + result = array_contains_value(array, bomb, length); /* assert */ TEST_ASSERT_TRUE(result); @@ -31,7 +31,7 @@ void test_bomb_not_in_array(void){ int length = 10; /* act */ - result = bomb_in_array(array, bomb, length); + result = array_contains_value(array, bomb, length); /* assert */ TEST_ASSERT_FALSE(result); From 8b88c2fbc974b4564ca0977ee294a7979f941a2b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 12:36:32 +0000 Subject: [PATCH 18/58] Add new directory Author: Ariana Ginju --- src/main/c/GameTic_Tac_Toe/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/c/GameTic_Tac_Toe/.gitkeep diff --git a/src/main/c/GameTic_Tac_Toe/.gitkeep b/src/main/c/GameTic_Tac_Toe/.gitkeep new file mode 100644 index 0000000..e69de29 From 2c08c49fdf287f7dcb61a0f36b8d25a2472da8a7 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 12:45:27 +0000 Subject: [PATCH 19/58] Add new file --- src/main/c/GameTic_Tac_Toe/temp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/temp @@ -0,0 +1 @@ + From eca9fef7a13af1ef19f0765d5feeebc03878c48b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 13:04:28 +0000 Subject: [PATCH 20/58] Delete temp --- src/main/c/GameTic_Tac_Toe/temp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp deleted file mode 100644 index 8b13789..0000000 --- a/src/main/c/GameTic_Tac_Toe/temp +++ /dev/null @@ -1 +0,0 @@ - From a8c427c5b2c361bb6739f9188bfc24184eb4802d Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 14:21:33 +0100 Subject: [PATCH 21/58] added global board --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/c/GameTic_Tac_Toe/game.c diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c new file mode 100644 index 0000000..7d5c061 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -0,0 +1,6 @@ +#include + +char board[3][3] = {{'1', '2', '3'}, + {'4', '5', '6'}, + {'7', '8', '9'}}; +char currentPlayer = 'X'; From 794f052fa746757d14dba5d6de325061cb229aca Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:44:47 +0000 Subject: [PATCH 22/58] display the game board --- src/main/c/GameTic_Tac_Toe/game.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 7d5c061..aeec7e0 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -4,3 +4,16 @@ char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; char currentPlayer = 'X'; + +// Funktionen zur Anzeige des Spielbretts +void displayBoard() { + printf("Tic-Tac-Toe\n"); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + printf("%c", board[i][j]); + if (j < 2) printf(" | "); + } + printf("\n"); + if (i < 2) printf("---------\n"); + } +} From 7999eb79fe7155da4fc5b3b8d94f54fdd2d395c4 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:45:48 +0000 Subject: [PATCH 23/58] Verification of the winner --- src/main/c/GameTic_Tac_Toe/game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index aeec7e0..2937166 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -17,3 +17,6 @@ void displayBoard() { if (i < 2) printf("---------\n"); } } + +// Funktion zur Überprüfung des Gewinners +char checkWinner() { From a9fb21881e83ecb0337d2e60b5ff9bca5bb78e33 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:46:46 +0000 Subject: [PATCH 24/58] Check horizontal and vertical lines --- src/main/c/GameTic_Tac_Toe/game.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 2937166..a08e501 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -20,3 +20,8 @@ void displayBoard() { // Funktion zur Überprüfung des Gewinners char checkWinner() { + // Überprüfe horizontale und vertikale Linien + for (int i = 0; i < 3; i++) { + if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) return board[i][0]; + if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) return board[0][i]; + } From 30f7147c18b85d24caa91288a8d7e6cd7f45f4d5 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:47:58 +0000 Subject: [PATCH 25/58] Check diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a08e501..3f1dc5a 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -25,3 +25,7 @@ char checkWinner() { if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) return board[i][0]; if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) return board[0][i]; } + // Überprüfe diagonale Linien + if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; + if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + From 970382ae3c968897fb7925f33e52b2f3ca643152 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:52:41 +0000 Subject: [PATCH 26/58] No winner --- src/main/c/GameTic_Tac_Toe/game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 3f1dc5a..a91ba51 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -29,3 +29,6 @@ char checkWinner() { if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + // Kein Gewinner + return ' '; +} From 7f8de3f06bb9fa26aca2ef129c4b6041b24dc4f1 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:58:28 +0000 Subject: [PATCH 27/58] Verification function --- src/main/c/GameTic_Tac_Toe/game.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a91ba51..6432f7f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,3 +32,15 @@ char checkWinner() { // Kein Gewinner return ' '; } + +// Funktion zur Überprüfung, ob das Spiel unentschieden ist +int isBoardFull() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (board[i][j] != 'X' && board[i][j] != 'O') { + return 0; + } + } + } + return 1; +} From 1ec3169a5b6edffa9c36a7a30e3d2df7a3943381 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:59:42 +0000 Subject: [PATCH 28/58] Function: A player's turn --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 6432f7f..089012b 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -44,3 +44,11 @@ int isBoardFull() { } return 1; } + + +// Funktion zum Zug eines Spielers +void makeMove() { + int choice; + printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + scanf("%d", &choice); + From 22d08f9a4b27e6ed72339a872ad860226106cd85 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:00:33 +0000 Subject: [PATCH 29/58] Convert the number --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 089012b..48035ae 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -52,3 +52,7 @@ void makeMove() { printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); +// Konvertiere die Zahl in Zeilen- und Spaltenindex + int row = (choice - 1) / 3; + int col = (choice - 1) % 3; + From f1b61336a5a5beb5d08874fb901e9657932f9b1e Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:01:52 +0000 Subject: [PATCH 30/58] Check whether the selected field is valid --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 48035ae..f0ddb37 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,3 +56,7 @@ void makeMove() { int row = (choice - 1) / 3; int col = (choice - 1) % 3; + // Überprüfe, ob das gewählte Feld gültig ist + if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { + + From 9ef4f2f96690b5e7cdf6af931d9ffcbac1abaec5 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:02:18 +0000 Subject: [PATCH 31/58] Update game.c --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f0ddb37..5129548 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -58,5 +58,6 @@ void makeMove() { // Überprüfe, ob das gewählte Feld gültig ist if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - + board[row][col] = currentPlayer; + } else { From d47cb68db8380e185c9556709a41c366ccd0a30d Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:03:21 +0000 Subject: [PATCH 32/58] Invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 5129548..51f5c7c 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,4 +60,7 @@ void makeMove() { if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { board[row][col] = currentPlayer; } else { - + printf("Ungültiger Zug! Bitte wähle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } +} From 87f5a6c5d8267494d57cd5302e9e5517ef909f61 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:04:05 +0000 Subject: [PATCH 33/58] Update main --- src/main/c/GameTic_Tac_Toe/game.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 51f5c7c..85a08a2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -64,3 +64,8 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } + +int main() { + while (1) { + displayBoard(); + makeMove(); From bd7b0a63c647e259a8fb7ab9255d3a7d289996a8 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:05:23 +0000 Subject: [PATCH 34/58] check winner --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 85a08a2..215af00 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -69,3 +69,10 @@ int main() { while (1) { displayBoard(); makeMove(); + + char winner = checkWinner(); + if (winner == 'X' || winner == 'O') { + displayBoard(); + printf("Spieler %c gewinnt!\n", winner); + break; + } From b02a1f7f6cf0cc7727c125ff136099760d521075 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:20:45 +0000 Subject: [PATCH 35/58] possibility: draw --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 215af00..0f0d6f8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,3 +76,9 @@ int main() { printf("Spieler %c gewinnt!\n", winner); break; } + + if (isBoardFull()) { + displayBoard(); + printf("Unentschieden!\n"); + break; + } From 421db299f35517a88096b718f0af89ab65693137 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:22:57 +0000 Subject: [PATCH 36/58] Change player --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0f0d6f8..b20f125 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -82,3 +82,10 @@ int main() { printf("Unentschieden!\n"); break; } + + // Wechsle den Spieler + currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } + + return 0; +} From 04b9365a8ac416738f3555c3f6eb17ea18a4ae2f Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 16:57:40 +0000 Subject: [PATCH 37/58] refactoring: lear condition for an invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index b20f125..11d2a79 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -57,11 +57,11 @@ void makeMove() { int col = (choice - 1) % 3; // Überprüfe, ob das gewählte Feld gültig ist - if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - board[row][col] = currentPlayer; - } else { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); + if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { + printf("Ungültiger Zug! Bitte wähle erneut.\n"); makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } else { + board[row][col] = currentPlayer; } } From a0ecdb63f1cbbe0fc19f296d86830176e43793b3 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:05:35 +0000 Subject: [PATCH 38/58] refactoring: using else and if --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 11d2a79..278b1e5 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -27,7 +27,7 @@ char checkWinner() { } // Überprüfe diagonale Linien if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; - if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; // Kein Gewinner return ' '; From 990b115c96fed40a214baed9d0fe6d5dc5c63ec9 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:15:30 +0000 Subject: [PATCH 39/58] refactoring: using an auxiliary feature for win conditions --- src/main/c/GameTic_Tac_Toe/game.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 278b1e5..0765c17 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -17,13 +17,19 @@ void displayBoard() { if (i < 2) printf("---------\n"); } } - +char checkLine(char a, char b, char c) { + if (a == b && b == c) return a; + return ' '; +} // Funktion zur Überprüfung des Gewinners char checkWinner() { // Überprüfe horizontale und vertikale Linien - for (int i = 0; i < 3; i++) { - if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) return board[i][0]; - if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) return board[0][i]; + for (int i = 0; i < 3; i++) { + char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); + char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); + + if (horizontalWinner != ' ') return horizontalWinner; + if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; From fec03368ca2cd1c5a0c2648c81f7709e179c9dd6 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:18:52 +0000 Subject: [PATCH 40/58] refactoring: using an auxiliary function for diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0765c17..215f890 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,8 +32,11 @@ char checkWinner() { if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien - if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; - else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + char diagonal1Winner = checkLine(board[0][0], board[1][1], board[2][2]); + char diagonal2Winner = checkLine(board[0][2], board[1][1], board[2][0]); + + if (diagonal1Winner != ' ') return diagonal1Winner; + if (diagonal2Winner != ' ') return diagonal2Winner; // Kein Gewinner return ' '; From 483f2b54800761f661f66ec9e4f931386e707620 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:43:49 +0000 Subject: [PATCH 41/58] refactoring: logic functions for player exchange Author: Ariana Ginju --- src/main/c/GameTic_Tac_Toe/game.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 215f890..a3f3ae2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,6 +56,10 @@ int isBoardFull() { // Funktion zum Zug eines Spielers +char switchPlayer(char currentPlayer) { + return (currentPlayer == 'X') ? 'O' : 'X'; +} + void makeMove() { int choice; printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); @@ -71,6 +75,7 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } else { board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); } } From 29759098ad1f386a32dc74eb2b89f87d99ff4196 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:53:55 +0000 Subject: [PATCH 42/58] refactoring: separation of the game loop into functions Author: Ariana Ginju --- src/main/c/GameTic_Tac_Toe/game.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a3f3ae2..f193efa 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -79,7 +79,7 @@ void makeMove() { } } -int main() { +void playGame() { while (1) { displayBoard(); makeMove(); @@ -95,11 +95,10 @@ int main() { displayBoard(); printf("Unentschieden!\n"); break; - } - - // Wechsle den Spieler - currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } } - +} +int main(){ + playGame(); return 0; } From 0d188261b2ad94bb5efa2a48e553496662ef42b1 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:56:28 +0000 Subject: [PATCH 43/58] refactoring: using const --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f193efa..f20e298 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -43,9 +43,11 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist +const int BOARD_SIZE = 3; + int isBoardFull() { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { if (board[i][j] != 'X' && board[i][j] != 'O') { return 0; } From f0480af37136c2200c5e0486ef55e54a1336f045 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:04:27 +0000 Subject: [PATCH 44/58] refactoring: Clear condition in makeMove --- src/main/c/GameTic_Tac_Toe/game.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f20e298..ece4bb7 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -62,22 +62,28 @@ char switchPlayer(char currentPlayer) { return (currentPlayer == 'X') ? 'O' : 'X'; } +int isValidMove(int choice) { + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; + + return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); +} + void makeMove() { int choice; - printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex - int row = (choice - 1) / 3; - int col = (choice - 1) % 3; - - // Überprüfe, ob das gewählte Feld gültig ist - if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); - makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird - } else { - board[row][col] = currentPlayer; - currentPlayer = switchPlayer(currentPlayer); +if (isValidMove(choice)) { + int row = (choice - 1) / / BOARD_SIZE; + int col = (choice - 1) % % BOARD_SIZE; + board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); + +} else { + printf("Ungueltiger Zug! Bitte waehle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } From 0221526e8e45ec1686d295f40d8660626af09bac Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:07:39 +0000 Subject: [PATCH 45/58] Update: corrected errors --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ece4bb7..e56e55f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,8 +76,8 @@ void makeMove() { // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { - int row = (choice - 1) / / BOARD_SIZE; - int col = (choice - 1) % % BOARD_SIZE; + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; board[row][col] = currentPlayer; currentPlayer = switchPlayer(currentPlayer); From b690c7e673ae766b2cdc4f5f639fae28436f7e53 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:14:59 +0000 Subject: [PATCH 46/58] refactoring: Using const for game symbol constants --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index e56e55f..ec98aec 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -4,7 +4,8 @@ char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; char currentPlayer = 'X'; - +const char PLAYER_X = 'X'; +const char PLAYER_O = 'O'; // Funktionen zur Anzeige des Spielbretts void displayBoard() { printf("Tic-Tac-Toe\n"); From 0721be55c82ee5cbbfe631cf08501bd091df9d6b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:16:46 +0000 Subject: [PATCH 47/58] refactoring: Removing the currentPlayer global variable --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ec98aec..8615cb8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,7 +60,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers char switchPlayer(char currentPlayer) { - return (currentPlayer == 'X') ? 'O' : 'X'; + return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } int isValidMove(int choice) { From dff9fd6ec9fdcd792ff6f2628a11a7e213fcd57a Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:20:35 +0000 Subject: [PATCH 48/58] refactoring: Using a loop --- src/main/c/GameTic_Tac_Toe/game.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 8615cb8..177acc8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -6,16 +6,22 @@ char board[3][3] = {{'1', '2', '3'}, char currentPlayer = 'X'; const char PLAYER_X = 'X'; const char PLAYER_O = 'O'; + // Funktionen zur Anzeige des Spielbretts void displayBoard() { printf("Tic-Tac-Toe\n"); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { printf("%c", board[i][j]); - if (j < 2) printf(" | "); - } + if (j < BOARD_SIZE - 1) printf(" | "); + } printf("\n"); - if (i < 2) printf("---------\n"); + if (i < BOARD_SIZE - 1) { + for (int k = 0; k < BOARD_SIZE * 4 - 1; k++) { + printf("-"); + } + printf("\n"); + } } } char checkLine(char a, char b, char c) { From 6d1d96c4d9732867d1f69a2ebca2af38fe51cd3c Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:35:42 +0000 Subject: [PATCH 49/58] refactoring: char replaced with enum --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 177acc8..ea95618 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -24,14 +24,16 @@ void displayBoard() { } } } + char checkLine(char a, char b, char c) { if (a == b && b == c) return a; return ' '; } + // Funktion zur Überprüfung des Gewinners char checkWinner() { // Überprüfe horizontale und vertikale Linien - for (int i = 0; i < 3; i++) { + for (int i = 0; i < BOARD_SIZE; i++) { char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); @@ -65,7 +67,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -char switchPlayer(char currentPlayer) { +enum switchPlayer(enum currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } From 51aff089d80018462a17f45565432ff16bf07f76 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:44:21 +0000 Subject: [PATCH 50/58] refactoring: replacing larger parts --- src/main/c/GameTic_Tac_Toe/game.c | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ea95618..3b7f017 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -80,14 +80,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer; + board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { @@ -96,25 +96,26 @@ if (isValidMove(choice)) { } } +int isGameOver() { + char winner = checkWinner(); + return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); +} + +void printGameResult(char winner) { + if (winner == PLAYER_X || winner == PLAYER_O) { + printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); + } else { + printf("Unentschieden!\n"); + } +} + void playGame() { - while (1) { + while (!isGameOver()) { displayBoard(); makeMove(); - - char winner = checkWinner(); - if (winner == 'X' || winner == 'O') { - displayBoard(); - printf("Spieler %c gewinnt!\n", winner); - break; - } - - if (isBoardFull()) { - displayBoard(); - printf("Unentschieden!\n"); - break; - } } -} + + //Fehlt etwas, änderung folgt; int main(){ playGame(); return 0; From 3989ecb68131b39183b56acdd5f9ba06e24f0cef Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:45:51 +0000 Subject: [PATCH 51/58] refactoring: added missing part --- src/main/c/GameTic_Tac_Toe/game.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 3b7f017..f72b814 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -115,7 +115,11 @@ void playGame() { makeMove(); } - //Fehlt etwas, änderung folgt; + displayBoard(); + char winner = checkWinner(); + printGameResult(winner); +} + int main(){ playGame(); return 0; From 4cdef01b3a4c00d51b701701ed1780c878177253 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 19:14:53 +0000 Subject: [PATCH 52/58] refactoring: correct the errors --- src/main/c/GameTic_Tac_Toe/game.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f72b814..443fe8d 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -1,5 +1,6 @@ #include +const int BOARD_SIZE = 3; char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; @@ -52,8 +53,6 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist -const int BOARD_SIZE = 3; - int isBoardFull() { for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { @@ -67,7 +66,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -enum switchPlayer(enum currentPlayer) { +char switchPlayer(char currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } @@ -80,14 +79,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; + board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { From 20e5561526c78d54b721eef846afba80e411298e Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:23:59 +0000 Subject: [PATCH 53/58] Add new directory --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep new file mode 100644 index 0000000..e69de29 From a1de4d4bb84dbd5a60038e1bbf0948729656be0c Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:27:00 +0000 Subject: [PATCH 54/58] Delete .gitkeep --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep deleted file mode 100644 index e69de29..0000000 From f756c806111db52ec747236f56681fff766dec18 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:28:08 +0000 Subject: [PATCH 55/58] Add new file --- test/test_tictactoe.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/test_tictactoe.c diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/test_tictactoe.c @@ -0,0 +1 @@ + From fc3efd1fec3871fba2a9a39ef41c5a0aa1314cb1 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:12:17 +0000 Subject: [PATCH 56/58] Add new file tictactoe.h --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/tictactoe.h diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -0,0 +1 @@ + From 83ca5781232e1dfd702390a1dda2e51ac1ec3a2e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:14:46 +0000 Subject: [PATCH 57/58] Update name game.c --- src/main/c/GameTic_Tac_Toe/{game.c => tictactoe.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/c/GameTic_Tac_Toe/{game.c => tictactoe.c} (100%) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c similarity index 100% rename from src/main/c/GameTic_Tac_Toe/game.c rename to src/main/c/GameTic_Tac_Toe/tictactoe.c From adce56939d6c6b61595291714fa9c4a836a90a63 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Fri, 2 Feb 2024 11:49:17 +0100 Subject: [PATCH 58/58] Minor Fixes --- src/main/c/Snake/snake_start.h | 2 ++ test/Snake/test_collision.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/Snake/snake_start.h b/src/main/c/Snake/snake_start.h index 359f548..b985421 100644 --- a/src/main/c/Snake/snake_start.h +++ b/src/main/c/Snake/snake_start.h @@ -1,6 +1,8 @@ #ifndef SNAKE_START_H #define SNAKE_START_H +#include + typedef struct Snake{ signed char direction; char length; diff --git a/test/Snake/test_collision.c b/test/Snake/test_collision.c index e5d5a63..df400b0 100644 --- a/test/Snake/test_collision.c +++ b/test/Snake/test_collision.c @@ -1,8 +1,8 @@ #ifdef TEST #include "unity.h" #include -#include "../../src/main/c/Snake/snake_start.h" -#include "../../src/main/c/Snake/get_character.h" +#include "snake_start.h" +#include "get_character.h" void setUp(void){}