From 04cd20a87fc91ef7365aece6cab4d1fe8751c59e Mon Sep 17 00:00:00 2001 From: Viktor Varoutis <92715836+Jimvar@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:58:42 +0200 Subject: [PATCH] Add files via upload --- blackjackfolder/blackjack.c | 57 +++++++- blackjackfolder/cardsystem.c | 253 ++++++++++------------------------- blackjackfolder/cardsystem.h | 2 +- 3 files changed, 123 insertions(+), 189 deletions(-) diff --git a/blackjackfolder/blackjack.c b/blackjackfolder/blackjack.c index 14d84fa..592c422 100644 --- a/blackjackfolder/blackjack.c +++ b/blackjackfolder/blackjack.c @@ -58,12 +58,63 @@ int main(){ long long bet; //houses the bet, made long long since money is also long long int double_down, flagdoubling = 0; //Flag for if the can double down or not, and flag for if they did double down or not - int win, loss, tie; + while(again==1){ + + do{ + printf("%sChoose bet(You have %s%lld%s money, and multiplier %sx%.1f%s):%s ", PLAYER, YELLOW , money, PLAYER, RED, multiplier, PLAYER, YELLOW); + bet = read_number(); + } while(bet>money || bet<=0); //Waits for input of player, and makes sure he doesn't give a false bet + money -=bet; //The bet gets withdrawn from the balance + + if(money == 0){ + all_in = 1; + printf("Brave for you to go all in, good luck!\n"); + } + else{ + all_in = 0; + } - win = loss = tie = 0; + if(money>=bet){ + double_down = 1; //They can double_down + } + else{ + double_down = 0; //They can't double_down + } - game(name, deck, &played_cards, packs, limitcards, &win, &loss, &tie, &money, &multiplier, &overallplayed, &totalwins, &totallost, &totalties, &moneygained, &moneylost, &biggestmult, &mult_increase, &mult_double, &all_in_mult); //Game is played + won = game(name, deck, &played_cards, double_down, &flagdoubling, packs, limitcards); //Game is played + overallplayed++; //Stat counter + if(flagdoubling){ //They doubled + money -=bet; //The extra bet gets withdrawn from the balance + bet *= 2; //Doubles reward + } + + if(won==0){ + printf("%sYou lost %s%lld%s money and your x%.1f multiplier!%s\n", RED , YELLOW, bet, RED, multiplier, RESET); + multiplier = 1.0; //Resets multiplier + totallost++; //Stat counter + moneylost += bet; //Stat counter + } + else if(won==1){ + printf("%sYou won %s%lld%s money and a boost to your multiplier!%s\n", GREEN , YELLOW, (long long)(bet*multiplier), GREEN, RESET); + money += 2*bet*multiplier; //Awards player with the amount withdrawn, the bet, plus what the multiplier gives + flagdoubling ? (multiplier += mult_double) : (multiplier += mult_increase); //If they doubled down, they get extra multiplier; else standard + if(all_in){ + printf(YELLOW "Since you went all in, you get an extra boost to your multiplier as a treat!\n" RESET); + multiplier += all_in_mult; + } + totalwins++; //Stat counter + moneygained += bet; //Stat counter + } + else if(won==2){ + printf(GREEN "You tied!\n" RESET); + money += bet; //Gives back the money withdrawn + totalties++; //Stat counter + } + + if(multiplier > biggestmult){ + biggestmult = multiplier; + } savegame(name, &money, &seed, &multiplier, &buffed_mult, deck, &packs, &limitcards, &played_cards); //Saves the current state of the game save_stats(&overallplayed, &totalwins, &totallost, &totalties, &moneygained, &moneylost, &biggestmult); //Saves the stats diff --git a/blackjackfolder/cardsystem.c b/blackjackfolder/cardsystem.c index 45e5f1f..f195872 100644 --- a/blackjackfolder/cardsystem.c +++ b/blackjackfolder/cardsystem.c @@ -120,60 +120,26 @@ void carddraw(int deck[][4][14], int hand[][20], int *limit, int *sum, int *play } } -int game(char name[], int deck[][4][14], int *played_cards, int packs, int limitcards, int *win, int *loss, int *tie, long long *money, float *multiplier, long long *overallplayed, long long *totalwins, long long *totallost, long long *totalties, long long *moneygained, long long *moneylost, float *biggestmult, float *mult_increase, float *mult_double, float *all_in_mult){ - +int game(char name[], int deck[][4][14], int *played_cards, int double_down, int *flagdoubling, int packs, int limitcards){ int dealerhand[2][20] = {0}; //Stores cards drawn by dealer int playerhand[2][20] = {0}; //Stores cards drawn by player - int dealersnapshot[3][10] = {0}; - int playersnapshot[3][10] = {0}; - int can_split = 0, snapshotplacedealer = -1, snapshotplaceplayer = -1; - int dealerlimit = 0, playerlimit = 0; //How many cards we need to draw int dealersum = 0, playersum = 0, softflagdealer = 0, softflagplayer = 0; //Value of cards for each entity, and a flag for if they have soft mode + *flagdoubling = 0; //Haven't yet doubled - int player_turn = 0; //Initialize flag for when we quit from the player mode - int choice = 0, cap; //Choice is for the menu later on, cap is initialized to the current cards the player has, to stop a loop later on - long long bet; - int all_in, double_down, flagdoubling = 0, split; - - - do{ - printf("%sChoose bet(You have %s%lld%s money, and multiplier %sx%.1f%s):%s ", PLAYER, YELLOW , *money, PLAYER, RED, *multiplier, PLAYER, YELLOW); - bet = read_number(); - } while(bet>*money || bet<=0); //Waits for input of player, and makes sure he doesn't give a false bet - *money -= bet; //The bet gets withdrawn from the balance + do{ //Dealer + carddraw(deck, dealerhand, &dealerlimit, &dealersum, played_cards, &softflagdealer, limitcards, packs); + } while(dealerlimit<=1); //Draws two cards + + do{ //Player + carddraw(deck, playerhand, &playerlimit, &playersum, played_cards, &softflagplayer, limitcards, packs); + } while(playerlimit<=1); //Draws two cards - if(*money == 0){ - all_in = 1; - printf("Brave for you to go all in, good luck!\n"); - } - else{ - all_in = 0; - } - if(*money>=bet){ - double_down = 1; //They can double_down - split = 1; - } - else{ - double_down = 0; //They can't double_down - split = 0; - } + int player_turn = 0; //Initialize flag for when we quit from the player mode + int choice, cap = playerlimit; //Choice is for the menu later on, cap is initialized to the current cards the player has, to stop a loop later on while(player_turn==0){ //Check the flag - - choice = 0; - - while(dealerlimit<=1){ //Dealer - carddraw(deck, dealerhand, &dealerlimit, &dealersum, played_cards, &softflagdealer, limitcards, packs); - }//Draws two cards - - while(playerlimit<=1){ //Player - carddraw(deck, playerhand, &playerlimit, &playersum, played_cards, &softflagplayer, limitcards, packs); - } - - cap = playerlimit; - printf(BORE "-------------------------------------\n"); printf(DEALER "Dealer\n"); draw_cards(dealerlimit, dealerhand); //Prints the two cards the dealer has @@ -184,168 +150,85 @@ int game(char name[], int deck[][4][14], int *played_cards, int packs, int limit printf(PLAYER "Sum: %d\n", playersum); printf(BORE "-------------------------------------\n"); - if(playersum>=21 || flagdoubling==1){ //If the player gets burned or draws a blackjack or has doubled down, break and go to the dealer - player_turn++; + if(playersum>=21 || *flagdoubling==1){ //If the player gets burned or draws a blackjack or has doubled down, break and go to the dealer + break; } - - if(playerhand[1][0] == playerhand[1][1] && playerlimit == 2 && split) can_split = 1; - else can_split = 0; - while(player_turn == 0 && choice <= 0 || choice >= 6 || (choice == 4 && double_down == 0) || (choice == 5 && can_split == 0)){ - printf(PLAYER "Choose action: 1. Draw 2. Stand 3. View Deck %s4. Double Down %s5. Split:%s ", double_down ? GREEN : RED, can_split ? GREEN : RED, PLAYER); - scanf("%d", &choice); - } //Include doubling - - if(choice==4){ - choice = 1; //To draw card - flagdoubling = 1; //Notify main() of doubling - } - - if(choice == 5){ - snapshotplacedealer = 0; - dealersnapshot[0][snapshotplacedealer] = dealerhand[0][0]; - dealersnapshot[1][snapshotplacedealer] = dealerhand[1][0]; - snapshotplacedealer++; - dealersnapshot[0][snapshotplacedealer] = dealerhand[0][1]; - dealersnapshot[1][snapshotplacedealer] = dealerhand[1][1]; - dealersnapshot[2][snapshotplacedealer] = dealersum; - snapshotplacedealer++; - dealerlimit = 0; - dealersum = 0; - - snapshotplaceplayer = 0; - playersnapshot[0][snapshotplaceplayer] = playerhand[0][1]; - playersnapshot[1][snapshotplaceplayer] = playerhand[1][1]; - playersnapshot[2][snapshotplaceplayer] = playersum; - snapshotplaceplayer++; - playerlimit = 1; - playersum = playersum / 2; - - *money -= bet; - if(*money>=bet){ - double_down = 1; //They can double_down - split = 1; - } - else{ - double_down = 0; //They can't double_down - split = 0; + if(double_down){ + do{ + printf(PLAYER "Choose action: 1. Draw 2. Stand 3. View Deck %s4. Double Down:%s ", GREEN, PLAYER); + scanf("%d", &choice); + } while(choice<=0 || choice>=5); //Include doubling + if(choice==4){ + choice = 1; //To draw card + *flagdoubling = 1; //Notify main() of doubling } - - continue; } - + else{ + do{ + printf(PLAYER "Choose action: 1. Draw 2. Stand 3. View Deck %s4. Double Down:%s ", RED, PLAYER); + scanf("%d", &choice); + } while(choice<=0 || choice>=4); //Exclude doubling + } + if(choice==1){ do{ //Player carddraw(deck, playerhand, &playerlimit, &playersum, played_cards, &softflagplayer, limitcards, packs); - } while(playerlimit<=cap); //Stops the loop when a card is drawn//Raise the cap if the player wants to search again + } while(playerlimit<=cap); //Stops the loop when a card is drawn + cap++; //Raise the cap if the player wants to search again } else if(choice==2){ player_turn++; //Stand and go to dealer } - else if(choice==3){ + else{ print_deck(deck, packs); //Prints deck } + } - if(player_turn){ - if(playersum>21){ - (*loss)++;//If they burned, automatic win for dealer + if(playersum>21){ + return 0; //If they burned, automatic win for dealer + } + else{ + if(dealersum>=17){ + if(playersum>dealersum){ + return 1; //Lost since he can't draw above than 17 } - else{ - if(dealersum>=17){ - if(playersum>dealersum){ - (*win)++; //Lost since he can't draw above than 17 - } - else if(playersum==dealersum){ - (*tie)++;//Tie - } - else{ - (*loss)++;//Dealer has won - } - } - else{ - do{ //Dealer - carddraw(deck, dealerhand, &dealerlimit, &dealersum, played_cards, &softflagdealer, limitcards, packs); - } while(dealersum<17); //Draw until limit - - printf(BORE "-------------------------------------\n"); - printf(DEALER "Dealer\n"); - draw_cards(dealerlimit, dealerhand); //Draws the dealer's cards - printf(DEALER "Sum: %d\n", dealersum); - printf(BORE "-------------------------------------\n"); - printf(PLAYER "%s\n", name); - draw_cards(playerlimit, playerhand); //Draws the player's cards - printf(PLAYER "Sum: %d\n", playersum); - printf(BORE "-------------------------------------\n"); - - if(dealersum>21){ - (*win)++;//Dealer burned, player wins - } - else if(playersum>dealersum){ - (*win)++;//Player won - } - else if(playersum==dealersum){ - (*tie)++;//Tie - } - else{ - (*loss)++; //Player lost - } - } + else if(playersum==dealersum){ + return 2; //Tie } - - overallplayed++; //Stat counter - if(flagdoubling){ //They doubled - money -=bet; //The extra bet gets withdrawn from the balance - bet *= 2; //Doubles reward + else{ + return 0; //Dealer has won } - - if(*loss){ - printf("%sYou lost %s%lld%s money and your x%.1f multiplier!%s\n", RED , YELLOW, bet, RED, *multiplier, RESET); - *multiplier = 1.0; //Resets multiplier - *totallost++; //Stat counter - *moneylost += bet; //Stat counter - *loss = 0; + } + else{ + do{ //Dealer + carddraw(deck, dealerhand, &dealerlimit, &dealersum, played_cards, &softflagdealer, limitcards, packs); + } while(dealersum<17); //Draw until limit + + printf(BORE "-------------------------------------\n"); + printf(DEALER "Dealer\n"); + draw_cards(dealerlimit, dealerhand); //Draws the dealer's cards + printf(DEALER "Sum: %d\n", dealersum); + printf(BORE "-------------------------------------\n"); + printf(PLAYER "%s\n", name); + draw_cards(playerlimit, playerhand); //Draws the player's cards + printf(PLAYER "Sum: %d\n", playersum); + printf(BORE "-------------------------------------\n"); + + if(dealersum>21){ + return 1; //Dealer burned, player wins } - else if(*win){ - printf("%sYou won %s%lld%s money and a boost to your multiplier!%s\n", GREEN , YELLOW, (long long)(bet*(*multiplier)), GREEN, RESET); - *money += 2*bet*(*multiplier); //Awards player with the amount withdrawn, the bet, plus what the multiplier gives - flagdoubling ? (*multiplier += *mult_double) : (*multiplier += *mult_increase); //If they doubled down, they get extra multiplier; else standard - if(all_in){ - printf(YELLOW "Since you went all in, you get an extra boost to your multiplier as a treat!\n" RESET); - *multiplier += *all_in_mult; - } - *totalwins++; //Stat counter - *moneygained += bet; //Stat counter - *win = 0; + else if(playersum>dealersum){ + return 1; //Player won } - else if(*tie){ - printf(GREEN "You tied!\n" RESET); - *money += bet; //Gives back the money withdrawn - *totalties++; //Stat counter - *tie = 0; + else if(playersum==dealersum){ + return 2; //Tie } - - if(*multiplier > *biggestmult){ - *biggestmult = *multiplier; + else{ + return 0; //Player lost } - if(snapshotplaceplayer>0){ - player_turn = 0; - snapshotplacedealer--; - dealersum = dealersnapshot[2][snapshotplacedealer]; - dealerhand[1][1] = dealersnapshot[1][snapshotplacedealer]; - dealerhand[0][1] = dealersnapshot[0][snapshotplacedealer]; - snapshotplacedealer--; - dealerhand[1][0] = dealersnapshot[1][snapshotplacedealer]; - dealerhand[0][0] = dealersnapshot[0][snapshotplacedealer]; - snapshotplacedealer--; - dealerlimit = 2; - - snapshotplaceplayer--; - playersum = playersnapshot[2][snapshotplaceplayer] / 2; - playerhand[0][0] = playersnapshot[0][snapshotplaceplayer]; - playerhand[1][0] = playersnapshot[1][snapshotplaceplayer]; - playerlimit = 1; - } } } + } \ No newline at end of file diff --git a/blackjackfolder/cardsystem.h b/blackjackfolder/cardsystem.h index 3ba7195..89fe2b3 100644 --- a/blackjackfolder/cardsystem.h +++ b/blackjackfolder/cardsystem.h @@ -6,6 +6,6 @@ int card_check(int played_cards, int deck[][4][14], int limitcards); char symbolmatcher(int symbol); int sumcheck(int symbol, int sum, int *flag); void carddraw(int deck[][4][14], int hand[][20], int *limit, int *sum, int *played_cards, int *softflag, int limitcards, int packs); -int game(char name[], int deck[][4][14], int *played_cards, int packs, int limitcards, int *win, int *loss, int *tie, long long *money, float *multiplier, long long *overallplayed, long long *totalwins, long long *totallost, long long *totalties, long long *moneygained, long long *moneylost, float *biggestmult, float *mult_increase, float *mult_double, float *all_in_mult); +int game(char name[], int deck[][4][14], int *played_cards, int double_down, int *flagdoubling, int packs, int limitcards); #endif \ No newline at end of file