From 887814e688bbe2494d23ef5e8ebc7eb1096c586b Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:18:29 +0000 Subject: [PATCH 01/27] Tictactoe angelegt --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 8b13789..46e2404 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -1 +1,3 @@ +#ifndef TICTACTOE_H +#define TICTACTOE_H From 3544322ef024caf13a7ddf2ae4d1058f6fea20f9 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:33:41 +0000 Subject: [PATCH 02/27] Test checkline case not identical --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 3 +-- src/main/c/GameTic_Tac_Toe/tictactoe.h | 4 ++++ src/main/c/main.c | 5 +++-- test/test_template.c | 2 +- test/test_tictactoe.c | 24 ++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index 443fe8d..be7be8a 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -119,7 +119,6 @@ void playGame() { printGameResult(winner); } -int main(){ +void start_tictactoe(){ playGame(); - return 0; } diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 46e2404..a972d36 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -1,3 +1,7 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +char checkLine(char a, char b, char c); +void start_tictactoe(); + +#endif diff --git a/src/main/c/main.c b/src/main/c/main.c index eaf0b17..aeb0490 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -3,6 +3,7 @@ #include #include "Template/game100.h" +#include "GameTic_Tac_Toe/tictactoe.h" int main(){ bool running = true; @@ -34,7 +35,7 @@ int main(){ //start_game3(); break; case 4: - //start_game4(); + start_tictactoe(); break; case 100: start_game100(); @@ -49,4 +50,4 @@ int main(){ } } return 0; -} \ No newline at end of file +} diff --git a/test/test_template.c b/test/test_template.c index a1b9ed4..4aba361 100644 --- a/test/test_template.c +++ b/test/test_template.c @@ -33,4 +33,4 @@ void test_ignore_rest_from_division(void){ TEST_ASSERT_EQUAL_INT(5, result);//5 / 6 + 5 = 5 } -#endif // TEST \ No newline at end of file +#endif // TEST diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 8b13789..8c03320 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -1 +1,25 @@ +#ifdef TEST +#include "unity.h" +#include "tictactoe.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} +void tearDown(void){ +} + + +void test_if_not_identical(void){ + /* arrange */ + char result; + char a = 'a', b = 'b', c = 'c'; + + result = checkLine(a, b, c); + + /* assert */ + TEST_ASSERT_EQUAL_CHAR(' ', result); +} + +#endif // TEST From 604c8f61ce81939c7224904e01981953b19509d0 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:41:47 +0000 Subject: [PATCH 03/27] Test checkline case identical --- test/test_tictactoe.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 8c03320..c98770d 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -22,4 +22,15 @@ void test_if_not_identical(void){ TEST_ASSERT_EQUAL_CHAR(' ', result); } + +void test_if_identical(void){ + /* arrange */ + char result; + char a = 'a', b = 'a', c = 'a'; + + result = checkLine(a, b, c); + + /* assert */ + TEST_ASSERT_EQUAL_CHAR(a, result); +} #endif // TEST From 0cc54a8fe53b871f83ad6bb7e84cb3617ae304a1 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:49:28 +0000 Subject: [PATCH 04/27] Test checkLine horizontaler Gewinner --- test/test_tictactoe.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index c98770d..0f76b25 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -33,4 +33,17 @@ void test_if_identical(void){ /* assert */ TEST_ASSERT_EQUAL_CHAR(a, result); } + +void test_checkLine_horizontalerGewinner(void) { + /* arrange */ + char result; + char a = 'X', b = 'X', c = 'X'; + + /* assert */ + result = checkLine(a, b, c); + + /* überprüfen */ + TEST_ASSERT_EQUAL_CHAR('X', result); +} +} #endif // TEST From 85d84d181eba483c5b40e19b9d56b64c66f63e7a Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:56:08 +0000 Subject: [PATCH 05/27] =?UTF-8?q?tic=5Ftac=5Ftoe=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/main.c | 2 +- test/test_tictactoe.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/c/main.c b/src/main/c/main.c index aeb0490..b88b924 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -17,7 +17,7 @@ int main(){ printf("\t1.Spiel1 starten\n"); printf("\t2.Spiel2 starten\n"); printf("\t3.Spiel3 starten\n"); - printf("\t4.Spiel4 starten\n"); + printf("\t4.tic_tac_toe starten\n"); printf("\t100.Template starten\n"); printf("\t6.Exit\n"); diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 0f76b25..324cac9 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -45,5 +45,5 @@ void test_checkLine_horizontalerGewinner(void) { /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('X', result); } -} + #endif // TEST From 8acc1734b8acdbc480ea8da904bf8e8072994cda Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 11:02:52 +0000 Subject: [PATCH 06/27] Test is Valid move --- test/test_tictactoe.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 324cac9..fb2e499 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -46,4 +46,15 @@ void test_checkLine_horizontalerGewinner(void) { TEST_ASSERT_EQUAL_CHAR('X', result); } +void test_isValidMove_gueltigerZug(void) { + /* arrangieren */ + int result; + int choice = 5; + + /* handeln */ + result = isValidMove(choice); + + /* überprüfen */ + TEST_ASSERT_EQUAL_INT(1, result); +} #endif // TEST From 48c322c7614fbfbbd86158c465f4d3096b0729ac Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 11:43:47 +0000 Subject: [PATCH 07/27] Test vertikal Gewinner --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 2 ++ test/test_tictactoe.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index a972d36..67f34cb 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -1,7 +1,9 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +int isValidMove(int choice); char checkLine(char a, char b, char c); void start_tictactoe(); +char checkWinner(); #endif diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index fb2e499..d7c864b 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -46,6 +46,7 @@ void test_checkLine_horizontalerGewinner(void) { TEST_ASSERT_EQUAL_CHAR('X', result); } + void test_isValidMove_gueltigerZug(void) { /* arrangieren */ int result; @@ -57,4 +58,29 @@ void test_isValidMove_gueltigerZug(void) { /* überprüfen */ TEST_ASSERT_EQUAL_INT(1, result); } + + +void test_checkWinner_vertikalerGewinner(void) { + /* arrangieren */ + char result; + + // Initialisiere das Spielfeld + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { + board[i][j] = (char)('1' + i * BOARD_SIZE + j); + } + } + + // Setze die Daten für einen vertikalen Gewinner + board[0][0] = 'O'; + board[1][0] = 'O'; + board[2][0] = 'O'; + + /* handeln */ + result = checkWinner(); + + /* überprüfen */ + TEST_ASSERT_EQUAL_CHAR('O', result); +} + #endif // TEST From 2f31d78df53cfd624ca39e98a00d7adb544a23ef Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 11:52:47 +0000 Subject: [PATCH 08/27] enable webide terminal --- .gitlab/.gitlab-webide.yml | 9 +++++++++ test/test_tictactoe.c | 1 + 2 files changed, 10 insertions(+) create mode 100644 .gitlab/.gitlab-webide.yml diff --git a/.gitlab/.gitlab-webide.yml b/.gitlab/.gitlab-webide.yml new file mode 100644 index 0000000..faf8c97 --- /dev/null +++ b/.gitlab/.gitlab-webide.yml @@ -0,0 +1,9 @@ +terminal: + # This can be any image that has the necessary runtime environment for your project. + image: node:10-alpine + before_script: + - apk update + script: sleep 60 + variables: + RAILS_ENV: "test" + NODE_ENV: "test" diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index d7c864b..0609053 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -63,6 +63,7 @@ void test_isValidMove_gueltigerZug(void) { void test_checkWinner_vertikalerGewinner(void) { /* arrangieren */ char result; + char board[3][3]; // Initialisiere das Spielfeld for (int i = 0; i < BOARD_SIZE; i++) { From b7347b1dc0ea2629fd57c9bf22ab963e303cd81a Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:08:42 +0000 Subject: [PATCH 09/27] Test horizontaler Gewinner --- test/test_tictactoe.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 0609053..fdca226 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -34,19 +34,6 @@ void test_if_identical(void){ TEST_ASSERT_EQUAL_CHAR(a, result); } -void test_checkLine_horizontalerGewinner(void) { - /* arrange */ - char result; - char a = 'X', b = 'X', c = 'X'; - - /* assert */ - result = checkLine(a, b, c); - - /* überprüfen */ - TEST_ASSERT_EQUAL_CHAR('X', result); -} - - void test_isValidMove_gueltigerZug(void) { /* arrangieren */ int result; @@ -84,4 +71,28 @@ void test_checkWinner_vertikalerGewinner(void) { TEST_ASSERT_EQUAL_CHAR('O', result); } +void test_checkWinner_horizontalerGewinner(void) { + /* arrangieren */ + char result; + char board[3][3]; + + // Initialisiere das Spielfeld + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { + board[i][j] = (char)('1' + i * BOARD_SIZE + j); + } + } + + // Setze die Daten für einen horizontalen Gewinner + board[0][0] = 'X'; + board[0][1] = 'X'; + board[0][2] = 'X'; + + /* handeln */ + result = checkWinner(); + + /* überprüfen */ + TEST_ASSERT_EQUAL_CHAR('X', result); +} + #endif // TEST From 734739bbccff81a9485a8cd8abae455fc900b4a4 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:13:27 +0000 Subject: [PATCH 10/27] defined BOARD SIZE --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 1 - src/main/c/GameTic_Tac_Toe/tictactoe.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index be7be8a..c6b9659 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -1,6 +1,5 @@ #include -const int BOARD_SIZE = 3; char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 67f34cb..759dbea 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -1,6 +1,8 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +#define BOARD_SIZE 3 + int isValidMove(int choice); char checkLine(char a, char b, char c); void start_tictactoe(); From 147c862ec0789f1f85f06c1e66597cd81174f25e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:18:15 +0000 Subject: [PATCH 11/27] fixed include --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index c6b9659..6cab3ec 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -1,4 +1,5 @@ #include +#include "tictactoe.h" char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, From d5ef26db7fce0686efd3f58ebe8d60c179b70f01 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:29:40 +0000 Subject: [PATCH 12/27] =?UTF-8?q?=C3=A4nderungen=20an=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_tictactoe.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index fdca226..31de0c1 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -50,19 +50,11 @@ void test_isValidMove_gueltigerZug(void) { void test_checkWinner_vertikalerGewinner(void) { /* arrangieren */ char result; - char board[3][3]; - - // Initialisiere das Spielfeld - for (int i = 0; i < BOARD_SIZE; i++) { - for (int j = 0; j < BOARD_SIZE; j++) { - board[i][j] = (char)('1' + i * BOARD_SIZE + j); - } - } - + // Setze die Daten für einen vertikalen Gewinner - board[0][0] = 'O'; - board[1][0] = 'O'; - board[2][0] = 'O'; + makeMove(1); + makeMove(4); + makeMove(7); /* handeln */ result = checkWinner(); @@ -74,19 +66,10 @@ void test_checkWinner_vertikalerGewinner(void) { void test_checkWinner_horizontalerGewinner(void) { /* arrangieren */ char result; - char board[3][3]; - - // Initialisiere das Spielfeld - for (int i = 0; i < BOARD_SIZE; i++) { - for (int j = 0; j < BOARD_SIZE; j++) { - board[i][j] = (char)('1' + i * BOARD_SIZE + j); - } - } - - // Setze die Daten für einen horizontalen Gewinner - board[0][0] = 'X'; - board[0][1] = 'X'; - board[0][2] = 'X'; + + makeMove(1); + makeMove(2); + makeMove(3); /* handeln */ result = checkWinner(); From 8e28644a1dfd524bdf6aa435c8f6e37740504f6a Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:32:02 +0000 Subject: [PATCH 13/27] =?UTF-8?q?makeMove=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 759dbea..b7b4e6f 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -7,5 +7,6 @@ int isValidMove(int choice); char checkLine(char a, char b, char c); void start_tictactoe(); char checkWinner(); +void makeMove(); #endif From e38696759767f2abca6d52699cd3d3dc30f892c4 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:45:27 +0000 Subject: [PATCH 14/27] refactoring: makeMove --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 32 +++++++++++++++----------- src/main/c/GameTic_Tac_Toe/tictactoe.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index 6cab3ec..e7eeee9 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -77,21 +77,18 @@ int isValidMove(int choice) { return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); } -void makeMove() { - int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); - scanf("%d", &choice); +void makeMove(int 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'; - currentPlayer = switchPlayer(currentPlayer); + // 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'; + currentPlayer = switchPlayer(currentPlayer); -} else { - printf("Ungueltiger Zug! Bitte waehle erneut.\n"); - makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } else { + printf("Ungueltiger Zug! Bitte waehle erneut.\n"); + makeMove(get_move()); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } @@ -100,6 +97,13 @@ int isGameOver() { return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); } +int get_move(){ + int choice; + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); + scanf("%d", &choice); + return choice; +} + void printGameResult(char winner) { if (winner == PLAYER_X || winner == PLAYER_O) { printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); @@ -111,7 +115,7 @@ void printGameResult(char winner) { void playGame() { while (!isGameOver()) { displayBoard(); - makeMove(); + makeMove(get_move()); } displayBoard(); diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index b7b4e6f..93c7d14 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -7,6 +7,6 @@ int isValidMove(int choice); char checkLine(char a, char b, char c); void start_tictactoe(); char checkWinner(); -void makeMove(); +void makeMove(int choice); #endif From c85e5a829710b4f9309cd9b6dedf1b162739c11c Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:46:38 +0000 Subject: [PATCH 15/27] Test checkWinner h/v --- test/test_tictactoe.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 31de0c1..5ece3e4 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -53,7 +53,9 @@ void test_checkWinner_vertikalerGewinner(void) { // Setze die Daten für einen vertikalen Gewinner makeMove(1); + makeMove(2); makeMove(4); + makeMove(3); makeMove(7); /* handeln */ @@ -68,7 +70,9 @@ void test_checkWinner_horizontalerGewinner(void) { char result; makeMove(1); + makeMove(4); makeMove(2); + makeMove(5); makeMove(3); /* handeln */ From 4a4f084441b5e57ac9dd015abbf1f40b7aada54e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:49:14 +0000 Subject: [PATCH 16/27] refactoring: get_Move --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index e7eeee9..e15cf80 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -26,6 +26,13 @@ void displayBoard() { } } +int get_move(){ + int choice; + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); + scanf("%d", &choice); + return choice; +} + char checkLine(char a, char b, char c) { if (a == b && b == c) return a; return ' '; @@ -97,12 +104,6 @@ int isGameOver() { return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); } -int get_move(){ - int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); - scanf("%d", &choice); - return choice; -} void printGameResult(char winner) { if (winner == PLAYER_X || winner == PLAYER_O) { From 6effaec97b6fbe3ff8cd60976eb536b6e34f3987 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:53:23 +0000 Subject: [PATCH 17/27] Test checkWinner --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 1 + test/test_tictactoe.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 93c7d14..89d5ab9 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -8,5 +8,6 @@ char checkLine(char a, char b, char c); void start_tictactoe(); char checkWinner(); void makeMove(int choice); +void displayBoard(); #endif diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 5ece3e4..7dafd2e 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -52,11 +52,13 @@ void test_checkWinner_vertikalerGewinner(void) { char result; // Setze die Daten für einen vertikalen Gewinner + displayBoard(); makeMove(1); makeMove(2); makeMove(4); makeMove(3); makeMove(7); + displayBoard(); /* handeln */ result = checkWinner(); @@ -69,11 +71,13 @@ void test_checkWinner_horizontalerGewinner(void) { /* arrangieren */ char result; + displayBoard(); makeMove(1); makeMove(4); makeMove(2); makeMove(5); makeMove(3); + displayBoard(); /* handeln */ result = checkWinner(); From 42579acfb49e37d54577ce3e162fbc52a0bc68bf Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 12:56:23 +0000 Subject: [PATCH 18/27] Test test --- test/test_tictactoe.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 7dafd2e..7cf7753 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -53,11 +53,11 @@ void test_checkWinner_vertikalerGewinner(void) { // Setze die Daten für einen vertikalen Gewinner displayBoard(); - makeMove(1); - makeMove(2); - makeMove(4); - makeMove(3); - makeMove(7); + //makeMove(1); + //makeMove(2); + //makeMove(4); + //makeMove(3); + //makeMove(7); displayBoard(); /* handeln */ @@ -72,11 +72,11 @@ void test_checkWinner_horizontalerGewinner(void) { char result; displayBoard(); - makeMove(1); - makeMove(4); - makeMove(2); - makeMove(5); - makeMove(3); + //makeMove(1); + //makeMove(4); + //makeMove(2); + //makeMove(5); + //makeMove(3); displayBoard(); /* handeln */ From b0499df2a8d7278a492dcba4c56a3e509a58c3cb Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:01:11 +0000 Subject: [PATCH 19/27] Test test --- test/test_tictactoe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 7cf7753..b72d780 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -53,11 +53,11 @@ void test_checkWinner_vertikalerGewinner(void) { // Setze die Daten für einen vertikalen Gewinner displayBoard(); - //makeMove(1); - //makeMove(2); - //makeMove(4); - //makeMove(3); - //makeMove(7); + makeMove(1); + makeMove(2); + makeMove(4); + makeMove(3); + makeMove(7); displayBoard(); /* handeln */ From 57dd871368486ae4333e60036932b81759b029e5 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:06:30 +0000 Subject: [PATCH 20/27] Test fixed test_checkWinner --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 6 ++++++ src/main/c/GameTic_Tac_Toe/tictactoe.h | 1 + test/test_tictactoe.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index e15cf80..84a2430 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -8,6 +8,12 @@ char currentPlayer = 'X'; const char PLAYER_X = 'X'; const char PLAYER_O = 'O'; +void reset_board(){ + board[3][3] = {{'1', '2', '3'}, + {'4', '5', '6'}, + {'7', '8', '9'}}; +} + // Funktionen zur Anzeige des Spielbretts void displayBoard() { printf("Tic-Tac-Toe\n"); diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h index 89d5ab9..d007eb4 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.h +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -9,5 +9,6 @@ void start_tictactoe(); char checkWinner(); void makeMove(int choice); void displayBoard(); +void reset_board(); #endif diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index b72d780..a74a3da 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -8,6 +8,7 @@ void setUp(void){ //Wenn Funktion Vorraussetzungen braucht } void tearDown(void){ + printf("1\n"); } @@ -65,6 +66,7 @@ void test_checkWinner_vertikalerGewinner(void) { /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('O', result); + reset_board(); } void test_checkWinner_horizontalerGewinner(void) { @@ -84,6 +86,7 @@ void test_checkWinner_horizontalerGewinner(void) { /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('X', result); + reset_board() } #endif // TEST From 92eed92b166240f37c4c0a60a2df4df361602fa3 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:08:05 +0000 Subject: [PATCH 21/27] Test fixed; --- test/test_tictactoe.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index a74a3da..bddd208 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -52,14 +52,12 @@ void test_checkWinner_vertikalerGewinner(void) { /* arrangieren */ char result; - // Setze die Daten für einen vertikalen Gewinner - displayBoard(); + // Setze die Daten für einen vertikalen Gewinne makeMove(1); makeMove(2); makeMove(4); makeMove(3); makeMove(7); - displayBoard(); /* handeln */ result = checkWinner(); @@ -73,20 +71,18 @@ void test_checkWinner_horizontalerGewinner(void) { /* arrangieren */ char result; - displayBoard(); - //makeMove(1); - //makeMove(4); - //makeMove(2); - //makeMove(5); - //makeMove(3); - displayBoard(); + makeMove(1); + makeMove(4); + makeMove(2); + makeMove(5); + makeMove(3); /* handeln */ result = checkWinner(); /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('X', result); - reset_board() + reset_board(); } #endif // TEST From be74b9b64ff712b14e135e1c363fb1e03a080c8f Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:11:16 +0000 Subject: [PATCH 22/27] refactoring: reset_board --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index 84a2430..e367101 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -9,9 +9,11 @@ const char PLAYER_X = 'X'; const char PLAYER_O = 'O'; void reset_board(){ - board[3][3] = {{'1', '2', '3'}, - {'4', '5', '6'}, - {'7', '8', '9'}}; + for(int i = 0; i < BOARD_SIZE; i++){ + for(int j = 0; j < BOARD_SIZE; y++){ + board[i][j] = j * BOARD_SIZE + i + 1; + } + } } // Funktionen zur Anzeige des Spielbretts From 7a4797e171a07a52209642cf42f505306631e4de Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:12:05 +0000 Subject: [PATCH 23/27] test --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index e367101..245af28 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -10,7 +10,7 @@ const char PLAYER_O = 'O'; void reset_board(){ for(int i = 0; i < BOARD_SIZE; i++){ - for(int j = 0; j < BOARD_SIZE; y++){ + for(int j = 0; j < BOARD_SIZE; j++){ board[i][j] = j * BOARD_SIZE + i + 1; } } From a669bdab52bd67e9dc6e31f7dec65380f127541e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:13:45 +0000 Subject: [PATCH 24/27] Test --- test/test_tictactoe.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index bddd208..5770e74 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -53,11 +53,13 @@ void test_checkWinner_vertikalerGewinner(void) { char result; // Setze die Daten für einen vertikalen Gewinne + displayBoard(); makeMove(1); makeMove(2); makeMove(4); makeMove(3); makeMove(7); + displayBoard(); /* handeln */ result = checkWinner(); @@ -65,17 +67,18 @@ void test_checkWinner_vertikalerGewinner(void) { /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('O', result); reset_board(); + displayBoard(); } void test_checkWinner_horizontalerGewinner(void) { /* arrangieren */ char result; - makeMove(1); - makeMove(4); - makeMove(2); - makeMove(5); - makeMove(3); + //makeMove(1); + //makeMove(4); + //makeMove(2); + //makeMove(5); + //makeMove(3); /* handeln */ result = checkWinner(); From f5d5943633d7f6f3d764240b3bf810b7776f1dfe Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:15:49 +0000 Subject: [PATCH 25/27] Test tear_down --- test/test_tictactoe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c index 5770e74..887aad7 100644 --- a/test/test_tictactoe.c +++ b/test/test_tictactoe.c @@ -8,7 +8,8 @@ void setUp(void){ //Wenn Funktion Vorraussetzungen braucht } void tearDown(void){ - printf("1\n"); + reset_board(); + displayBoard(); } @@ -53,21 +54,17 @@ void test_checkWinner_vertikalerGewinner(void) { char result; // Setze die Daten für einen vertikalen Gewinne - displayBoard(); makeMove(1); makeMove(2); makeMove(4); makeMove(3); makeMove(7); - displayBoard(); /* handeln */ result = checkWinner(); /* überprüfen */ TEST_ASSERT_EQUAL_CHAR('O', result); - reset_board(); - displayBoard(); } void test_checkWinner_horizontalerGewinner(void) { From fcc795f551df44f8730976286ad0861d4340240f Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:17:48 +0000 Subject: [PATCH 26/27] Test --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index 245af28..e67f075 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -11,7 +11,7 @@ const char PLAYER_O = 'O'; void reset_board(){ for(int i = 0; i < BOARD_SIZE; i++){ for(int j = 0; j < BOARD_SIZE; j++){ - board[i][j] = j * BOARD_SIZE + i + 1; + board[i][j] = j * BOARD_SIZE + i + 49; } } } From fba334758568305b99a0cf87f9f5a47b7a468750 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 13:19:33 +0000 Subject: [PATCH 27/27] Test --- src/main/c/GameTic_Tac_Toe/tictactoe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c index e67f075..ce8b8fc 100644 --- a/src/main/c/GameTic_Tac_Toe/tictactoe.c +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -11,7 +11,7 @@ const char PLAYER_O = 'O'; void reset_board(){ for(int i = 0; i < BOARD_SIZE; i++){ for(int j = 0; j < BOARD_SIZE; j++){ - board[i][j] = j * BOARD_SIZE + i + 49; + board[i][j] = i * BOARD_SIZE + j + 49; } } }