From 955e91509fe84719159e7579db4596dcb89c4b3a Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 12:06:47 +0100 Subject: [PATCH] add function to set BoardMarker --- src/main/c/Georg/tictactoe.c | 12 +++++++++--- src/main/c/Georg/tictactoe.h | 1 + src/test/c/Georg/test_tictactoe.c | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index 1c602df..6888e7e 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -156,12 +156,16 @@ int* getMarkerParameters( char* input ){ int firstArgument = input[index-1] - '0'; int secondArgument = input[index+1] - '0'; - array[0] = firstArgument; - array[1] = secondArgument; + array[0] = firstArgument-1; + array[1] = secondArgument-1; return array; } +void setBoardMarker( bool board[BORAD_SIZE][BORAD_SIZE], int* params ){ + board[params[0]][params[1]] = 1; +} + void handleGame(){ char* input = getUserInput(); int nextState = handleCommand( input ); @@ -182,7 +186,9 @@ void handleGame(){ // gameCommand processing if( gameCommand == 1 ) { // set marker in field - + int* params = getMarkerParameters( input ); + setBoardMarker( GAME.board, params ); + free(params); } } diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 7cf6b60..7adc058 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -33,6 +33,7 @@ int handleCommand( char* input ); void initializeBoard( bool board[3][3] ); int handleGameInput( char* input ); int* getMarkerParameters(); +void setBoardMarker( bool board[BORAD_SIZE][BORAD_SIZE], int* params ); /* commands */ commandFunction getCommandById(int id); diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 5194ece..ffadb35 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -143,7 +143,7 @@ void test_handleGameInput(void){ void test_getMarkerParameters(void){ // arrange char* teststring = "set 3,3"; - int expectedParams[2] = {3, 3}; + int expectedParams[2] = {2, 2}; // act int* actualParams = getMarkerParameters( teststring ); @@ -152,4 +152,21 @@ void test_getMarkerParameters(void){ for( int i = 0; i < 2; i++ ){ TEST_ASSERT_EQUAL_INT( expectedParams[i], actualParams[i] ); } +} + +void test_setBoardFields(){ + // arrange + // arrange + bool board[3][3]={ + {0,0,0}, + {0,0,0}, + {0,0,0} + }; + int params[2] = {2,2}; + + // act + setBoardMarker( board, params ); + + // assert + TEST_ASSERT_EQUAL_INT( 1, board[2][2] ); } \ No newline at end of file