From bdfdea9f467b3ae6ec1d7a1ce5ef3d17346c4aa7 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Tue, 6 Feb 2024 13:04:07 +0100 Subject: [PATCH] getRandomCard mehr random gemacht + bugfix: dealer zieht bei 21 keine neue Karte --- src/main/c/Stefan/blackjack.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index ff54699..b648de5 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -66,10 +66,13 @@ int userInputBJ(){ // Chance für 10 ist 4 Mal höher als für den Rest // 1 = Ass int getRandCard(int offset){ - srand(time(NULL) + offset); + int randomCard; + srand(time(NULL)); - int randomCard = rand() % ANZ_MOEGLICHE_KARTEN; - randomCard++; + for(int i = 0; i < offset; i++){ + + randomCard = (rand() % ANZ_MOEGLICHE_KARTEN) + 1; + } // 11, 12, 13 = Bube, Dame, König haben den Wert 10 if(randomCard > 10){ @@ -147,7 +150,7 @@ int playBJ(int bet, int balance){ } printf("Dealer Cards Total: %d\n", dealerCardsTotal); - if(dealerCardsTotal >= 17 && dealerCardsTotal < 21){ + if(dealerCardsTotal >= 17 && dealerCardsTotal <= 21){ if(calculateIfYouWon(userCardsTotal, dealerCardsTotal)){ winnings = calculateWinnings(false, bet); } @@ -215,6 +218,7 @@ int calculateCardsTotal(int cardsArray[], int len){ } if(aceFound && sum + cardsArray[i] > 21){ sum -= 10; + aceFound = false; } sum += cardsArray[i]; }