Browse Source

add function to set BoardMarker

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
955e91509f
  1. 12
      src/main/c/Georg/tictactoe.c
  2. 1
      src/main/c/Georg/tictactoe.h
  3. 19
      src/test/c/Georg/test_tictactoe.c

12
src/main/c/Georg/tictactoe.c

@ -156,12 +156,16 @@ int* getMarkerParameters( char* input ){
int firstArgument = input[index-1] - '0'; int firstArgument = input[index-1] - '0';
int secondArgument = 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; return array;
} }
void setBoardMarker( bool board[BORAD_SIZE][BORAD_SIZE], int* params ){
board[params[0]][params[1]] = 1;
}
void handleGame(){ void handleGame(){
char* input = getUserInput(); char* input = getUserInput();
int nextState = handleCommand( input ); int nextState = handleCommand( input );
@ -182,7 +186,9 @@ void handleGame(){
// gameCommand processing // gameCommand processing
if( gameCommand == 1 ) { // set marker in field if( gameCommand == 1 ) { // set marker in field
int* params = getMarkerParameters( input );
setBoardMarker( GAME.board, params );
free(params);
} }
} }

1
src/main/c/Georg/tictactoe.h

@ -33,6 +33,7 @@ int handleCommand( char* input );
void initializeBoard( bool board[3][3] ); void initializeBoard( bool board[3][3] );
int handleGameInput( char* input ); int handleGameInput( char* input );
int* getMarkerParameters(); int* getMarkerParameters();
void setBoardMarker( bool board[BORAD_SIZE][BORAD_SIZE], int* params );
/* commands */ /* commands */
commandFunction getCommandById(int id); commandFunction getCommandById(int id);

19
src/test/c/Georg/test_tictactoe.c

@ -143,7 +143,7 @@ void test_handleGameInput(void){
void test_getMarkerParameters(void){ void test_getMarkerParameters(void){
// arrange // arrange
char* teststring = "set 3,3"; char* teststring = "set 3,3";
int expectedParams[2] = {3, 3};
int expectedParams[2] = {2, 2};
// act // act
int* actualParams = getMarkerParameters( teststring ); int* actualParams = getMarkerParameters( teststring );
@ -152,4 +152,21 @@ void test_getMarkerParameters(void){
for( int i = 0; i < 2; i++ ){ for( int i = 0; i < 2; i++ ){
TEST_ASSERT_EQUAL_INT( expectedParams[i], actualParams[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] );
} }
Loading…
Cancel
Save