diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index a4208a8..f5ecc78 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -86,5 +86,35 @@ int wasGameWon(char field[3][3]){ winner = PLAYER; } } + if(field[0][0] == 'X'){ + if (field[0][0] == field[0][1] && field[0][2] == field[0][1]){ + winner = COMPUTER; + } + else if (field[0][0] == field[1][0] && field[1][0] == field[2][0]){ + winner = COMPUTER; + } + else if (field[0][0] == field[1][1] && field[1][1] == field[2][2]){ + winner = COMPUTER; + } + } + else if(field[2][2] == 'X'){ + if (field[2][2] == field[2][1] && field[2][2] == field[2][0]){ + winner = COMPUTER; + } + else if (field[2][2] == field[1][2] && field[1][2] == field[0][2]){ + winner = COMPUTER; + } + } + if(field[1][1] == 'X'){ + if (field[1][1] == field[0][1] && field[0][1] == field[2][1]){ + winner = COMPUTER; + } + else if (field[1][1] == field[1][0] && field[1][0] == field[1][2]){ + winner = COMPUTER; + } + else if (field[2][0] == field[1][1] && field[1][1] == field[0][2]){ + winner = COMPUTER; + } + } return winner; } \ No newline at end of file diff --git a/test/c/test_ticTacToe.c b/test/c/test_ticTacToe.c index f86583b..ae35d69 100644 --- a/test/c/test_ticTacToe.c +++ b/test/c/test_ticTacToe.c @@ -54,5 +54,21 @@ void test_ticTacToe_playerWins(void) TEST_ASSERT_EQUAL_INT(PLAYER, result); } +void test_ticTacToe_ComputerWins(void) +{ + /* arrange */ + int result; + char field[][3] = { + {'X', '-', '-'}, + {'X', '-', '-'}, + {'X', '-', '-'} + }; + + /* act */ + result = wasGameWon(field); + + /* assert */ + TEST_ASSERT_EQUAL_INT(COMPUTER, result); +} #endif // TEST \ No newline at end of file