Browse Source

refactoring: Variablen in calculateCardsTotal() umbennant + Kommentare

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
14262404e2
  1. 18
      src/main/c/Stefan/blackjack.c

18
src/main/c/Stefan/blackjack.c

@ -222,19 +222,21 @@ bool calculateIfYouWon(int userCardsTotal, int computerCardsTotal){
}
int calculateCardsTotal(int cardsArray[], int len){
int sum = 0;
bool aceFound = false;
int total = 0;
bool acesFound = false;
for(int i = 0; i < len; i++){
if(cardsArray[i] == 11){
aceFound = true;
acesFound = true;
}
if(aceFound && sum + cardsArray[i] > 21){
sum -= 10;
aceFound = false;
// 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){
total -= 10;
// Das gleiche Ass kann nicht mehrmals den total um 10 senken
acesFound = false;
}
sum += cardsArray[i];
total += cardsArray[i];
}
return sum;
return total;
}
int calculateWinnings(bool blackjack, int bet){

Loading…
Cancel
Save