Browse Source

mehrere Asse koennen jetzt den Wert 1 haben + Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
ec637ee097
  1. 8
      src/main/c/Stefan/blackjack.c
  2. 14
      src/test/c/Stefan/test_blackjack.c

8
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];
}

14
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

Loading…
Cancel
Save