#include player will get printf(“One of computer’s cards: “);

#include #include #include int shuffle(int cards){ int s; int h; int desk52; for (h=0;h<52;h++) deskh = (h/13+3)*100 + h%13 + 1; srand(time(NULL)); for (h = 0; h < 52; h++) { do { s = rand() % 52; } while (desks == 0); cardsh = desks; desks = 0; } return 0;}int convert_jkq(int x){ if ((x%100==11) ||(x%100==12) ||(x%100==13)) return (x/100)*100+10; else return x;}void pic(int num){ char fl; int card_num; fl = num / 100; card_num = num % 100; switch (card_num) { case 1: { printf("------- "); printf("     | "); printf("| %c   | ", fl); printf("|   A | "); printf("|     | "); printf("------- "); break; } case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: { printf("------- "); printf("|     | "); printf("| %c   | ", fl); printf("|  %2d | ", card_num); printf("|     | "); printf("------- "); break; } case 11: { printf("------- "); printf("|     | "); printf("| %c   | ", fl); printf("|   J | "); printf("|     | "); printf("------- "); break; } case 12: { printf("------- "); printf("|     | "); printf("| %c   | ", fl); printf("|   Q | "); printf("|     | "); printf("------- "); break; } case 13: { printf("------- "); printf("|     | "); printf("| %c   | ", fl); printf("|   K | "); printf("|     | "); printf("------- "); break; } }}int play(void){ int k; int rtotal=0; int mtotal=0; int rcards5={0}; int mcards5={0}; int cards52; int betting(); char go_on; char v; printf("Welcome to BlackJack Game! " "You can press Ctrl+C if you want to exit this game. " "Good Luck! Press the Enter keypad to go on..... "); printf(" Enter Betting: $"); do{ go_on = getchar(); } while (go_on != ' '); printf(" "); //shuffle the cards shuffle(cards); //providing the cards rcards0=cards0; rcards1=cards1; mcards0=cards2; mcards1=cards3; //2 cards the player will get printf("One of computer's cards: "); pic(mcards0); printf(" "); printf("Cards of player: "); pic(rcards0); //printf(" "); pic(rcards1); //printf(" "); k=0; for (k=0; k<2; k++) { if (rcardsk%100 == 1) { printf("select A value of the card %d, input 'y' for 11 or 'n' for 1 : ", k+1); do{ v = getchar(); } while (v!='y' && v!='n'); if (v == 'y') { printf("You've selected value 11 for card A. "); rtotal = rtotal + 11; } else if(v == 'n') { printf("You've selected value 1 for card A. "); rtotal = rtotal +1; } } else if (convert_jkq(rcardsk) %100 ==10) rtotal= rtotal + 10; else rtotal = rtotal+ rcardsk%100; if (rtotal > 21) { printf(“Total of player’s cards now:%d

“,rtotal); printf(“Opss! The Computer won the game!
“); return 1; } else if (rtotal == 21) { printf(“Total of player’s cards now:%d

“,rtotal); printf(“Yahoo!! The Player won the game!
“); return 0; } } printf(“Total of player’s cards now:%d

“,rtotal); //whether player get different cards k=0; for (k=0; k<3; k++) { char m = 'n'; printf("Do you want more cards to display? Input y or n: "); do{ m = getchar(); } while (m!='y' &&m!='n'); if (m=='y') { printf("You've got different card now. "); rcardsk+2=cardsk+4; printf("and your card %d is: ", k+3); pic(rcardsk+2); if (rcardsk+2%100 == 1) { printf("Select A value of the card %d, input 'y' for 11 or 'n' for 1: ", k+3); do{ v = getchar(); } while (v!='y' && v!='n'); if (v == 'y') { printf("You've selected value 11 for the card A. "); rtotal = rtotal+ 11; } else if(v == 'n') { printf("You've chosen value 1 for card A. "); rtotal = rtotal+1; } } else if (convert_jkq(rcardsk+2) %100 ==10) rtotal = rtotal + 10; else rtotal = rtotal+ rcardsk+2%100; if (rtotal > 21) { printf(“Total of the player’s cards now:%d

“,rtotal); printf(“Opss! The Computer won the game!
“); return 1; } else if (rtotal == 21) { printf(“Total of player’s cards now:%d

“,rtotal); printf(“Yahoo!! The Player won the game!
“); return 0; } else printf(“Total of player’s cards now:%d

“,rtotal); } else { printf(“Total of player’s cards now:%d

“,rtotal); break; } } if (k == 3) { printf(“Player won the game ,Because the total of your 5 cards is no larger than 21! You’re So lucky!
“); return 0; } //the 2 cards of boss/computer //i=0; printf(“Computer’s cards:
“); pic(mcards0); pic(mcards1); if (mcards0%100 + mcards1%100 == 2) { mtotal=12; //two A cards printf(“Total of computer’s cards now:%d

“, mtotal); } else if ((convert_jkq(mcards0))%100 + (convert_jkq(mcards1))%100 ==1) { mtotal=21; printf(“Total of computer’s cards now:%d

“, mtotal); printf(“Opss! The Computer won the game!
“); return 1; } else if (mcards0%100==1 || mcards1%100==1) { mtotal=(mcards0+mcards1)%100+(rand()%2)*10; printf(“Total of computer’s cards now:%d

“, mtotal); } else { mtotal = (convert_jkq(mcards0))%100 + (convert_jkq(mcards1))%100; printf(“Total of computer’s cards now:%d

“, mtotal); } //whether computer get different cards until mtotal>16 //i=0; for (k=0; k<3 && mtotal<17; k++) { mcardsk+2=cardsk+7; printf("Computer's card %d is: ", k+3); pic(mcardsk+2); if (mcardsk+2%100 == 1) { if (mtotal+11 <= 21) { printf("Computer has selected A as 11 "); mtotal = mtotal+11; printf("Total of computer's cards now:%d ", mtotal); } else { printf("Computer has selected A as 1 "); mtotal = mtotal+1; printf("Total of computer's cards now:%d ", mtotal); } } else { mtotal = mtotal + convert_jkq(mcardsk+2)%100; printf("Total of computer's cards now:%d ", mtotal); } } if (k == 3) { printf("Computer won the game, Because the sum of its 5 cards is no larger than 21! So lucky! "); return 1; } //the last step if (mtotal>21 || rtotal>mtotal) { printf(“Yahoo!! The Player won the game!
“); return 0; } else if (rtotal == mtotal) { printf(“Oh no, player and the computer get the same result !
“); return 3; } else if (rtotal < mtotal) { printf("Opss! The Computer won the game! "); return 1; } return 3;}int main(void){ char again; play(); printf(" Do you want to play this game again? Input 'y' or 'n': "); do{ again = getchar(); } while (again!='y' && again!='n'); if (again == 'y') { printf(" OK, let's play this game again! "); main(); } return 0;}