|
@ -2,6 +2,7 @@ |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdbool.h> |
|
|
#include <stdbool.h> |
|
|
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
|
int blackjack(){ |
|
|
int blackjack(){ |
|
|
|
|
|
|
|
@ -65,7 +66,8 @@ int userInputBJ(){ |
|
|
// Liefert eine Zufallszahl zwischen 1 und 10 |
|
|
// Liefert eine Zufallszahl zwischen 1 und 10 |
|
|
// Chance für 10 ist 4 Mal höher als für den Rest |
|
|
// Chance für 10 ist 4 Mal höher als für den Rest |
|
|
// 1 = Ass |
|
|
// 1 = Ass |
|
|
int getRandCard(){ |
|
|
|
|
|
|
|
|
int getRandCard(int offset){ |
|
|
|
|
|
srand(time(NULL) + offset); |
|
|
|
|
|
|
|
|
int r = rand() % 13; |
|
|
int r = rand() % 13; |
|
|
r++; |
|
|
r++; |
|
@ -91,16 +93,16 @@ int playBJ(int bet, int balance){ |
|
|
int *dealerCardsArray = (int*) malloc(10 * sizeof(int)); |
|
|
int *dealerCardsArray = (int*) malloc(10 * sizeof(int)); |
|
|
|
|
|
|
|
|
if(dealerCardsArray){ |
|
|
if(dealerCardsArray){ |
|
|
dealerCardsArray[0] = getRandCard(); |
|
|
|
|
|
|
|
|
dealerCardsArray[0] = getRandCard(0); |
|
|
printf("computer rand card: %d\n", dealerCardsArray[0]); |
|
|
printf("computer rand card: %d\n", dealerCardsArray[0]); |
|
|
|
|
|
|
|
|
int *userCardsArray = (int*) malloc(10 * sizeof(int)); |
|
|
int *userCardsArray = (int*) malloc(10 * sizeof(int)); |
|
|
|
|
|
|
|
|
if(userCardsArray){ |
|
|
if(userCardsArray){ |
|
|
|
|
|
|
|
|
userCardsArray[0] = getRandCard(); |
|
|
|
|
|
|
|
|
userCardsArray[0] = getRandCard(1); |
|
|
printf("user rand card: %d\n", userCardsArray[0]); |
|
|
printf("user rand card: %d\n", userCardsArray[0]); |
|
|
userCardsArray[1] = getRandCard(); |
|
|
|
|
|
|
|
|
userCardsArray[1] = getRandCard(2); |
|
|
printf("user rand card: %d\n", userCardsArray[1]); |
|
|
printf("user rand card: %d\n", userCardsArray[1]); |
|
|
|
|
|
|
|
|
if(checkForBlackjack(userCardsArray)){ |
|
|
if(checkForBlackjack(userCardsArray)){ |
|
@ -125,7 +127,7 @@ int playBJ(int bet, int balance){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(hit()){ |
|
|
if(hit()){ |
|
|
userCardsArray[i] = getRandCard(); |
|
|
|
|
|
|
|
|
userCardsArray[i] = getRandCard(i); |
|
|
printf("new card: %d\n", userCardsArray[i]); |
|
|
printf("new card: %d\n", userCardsArray[i]); |
|
|
} else{ |
|
|
} else{ |
|
|
break; |
|
|
break; |
|
@ -138,7 +140,7 @@ int playBJ(int bet, int balance){ |
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); |
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i); |
|
|
|
|
|
|
|
|
if(dealerCardsTotal < 17){ |
|
|
if(dealerCardsTotal < 17){ |
|
|
dealerCardsArray[i] = getRandCard(); |
|
|
|
|
|
|
|
|
dealerCardsArray[i] = getRandCard(i); |
|
|
printf("Computer Card: %d\n", dealerCardsArray[i]); |
|
|
printf("Computer Card: %d\n", dealerCardsArray[i]); |
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i + 1); |
|
|
dealerCardsTotal = calculateCardsTotal(dealerCardsArray, i + 1); |
|
|
} |
|
|
} |
|
|