From c29eff6aa44618348cd1b266e4aa9b99cd80debd Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 12:02:31 +0100 Subject: [PATCH] add defenition for the board size --- src/main/c/Georg/tictactoe.c | 4 +++- src/main/c/Georg/tictactoe.h | 2 ++ src/test/c/Georg/test_tictactoe.c | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 3f2bfdc..85a0fec 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -86,7 +86,7 @@ char* getUserInput(){ return userInput; } -void initializeBoard( bool board[3][3] ){ +void initializeBoard( bool board[BORAD_SIZE][BORAD_SIZE] ){ for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { board[i][j] = 0; @@ -120,6 +120,8 @@ int startGame( int code ){ } printf("Welcome to the game!\n"); + bool board[BORAD_SIZE][BORAD_SIZE]; + initializeBoard( board ); while( GAME.currentState == 1 ){ int nextState = handleCommand( getUserInput() ); diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index fb29d59..a73cb5e 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -5,9 +5,11 @@ #define MAX_INPUT_LENGTH 20 #define MAX_COMMANDS 3 +#define BORAD_SIZE 3 struct ticTacToe{ int currentState; + bool board[BORAD_SIZE][BORAD_SIZE]; }; // Typdefinition für einen Funktionszeiger diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index dcc71be..4413a8a 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -110,19 +110,19 @@ void test_callCommandById_startGame(void){ void test_initializeBoard(void){ // arrange - bool expectedBoard[3][3]={ + bool expectedBoard[BORAD_SIZE][BORAD_SIZE]={ {0,0,0}, {0,0,0}, {0,0,0} }; // act - bool actualBoard[3][3]; + bool actualBoard[BORAD_SIZE][BORAD_SIZE]; initializeBoard(actualBoard); // assert - for (size_t i = 0; i < 3; i++) { - for (size_t ii = 0; ii < 3; ii++) { + for (size_t i = 0; i < BORAD_SIZE; i++) { + for (size_t ii = 0; ii < BORAD_SIZE; ii++) { TEST_ASSERT_EQUAL_INT(expectedBoard[i][ii], actualBoard[i][ii]); } }