diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 465a57f..838b676 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -223,16 +223,16 @@ bool calculateIfYouWon(int userCardsTotal, int computerCardsTotal){ int calculateCardsTotal(int cardsArray[], int len){ int total = 0; - bool acesFound = false; + int acesFound = 0; for(int i = 0; i < len; i++){ if(cardsArray[i] == 11){ - acesFound = true; + acesFound++; } // Wenn der total > 21, aber man hat ein Ass, dann zählt hat das Ass den Wert 1, nicht 11 - if(acesFound && total + cardsArray[i] > 21){ + if(acesFound > 0 && total + cardsArray[i] > 21){ total -= 10; // Das gleiche Ass kann nicht mehrmals den total um 10 senken - acesFound = false; + acesFound--; } total += cardsArray[i]; } diff --git a/src/test/c/Stefan/test_blackjack.c b/src/test/c/Stefan/test_blackjack.c index 9497d5e..bd10d9e 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -130,6 +130,20 @@ void test_cards_10_10_ace_total_equals_21() { } +void test_cards_ace_ace_10_8_total_equals_20() { + + //arrange + int userCards[] = { 11, 11, 10, 8}; + int expected_result = 20; + + //act + int actual_result = calculateCardsTotal(userCards, 4); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + +} + void test_blackjack_bet_equals_10() { //arrange