The solution and proof to today's puzzle is here.
Tarrah's Casino & Resort has been contemplating a new reward system for the lucky players at their Blackjack tables. You have a reputation from the Stimsonian Institute of Physics as a talented scientific programmer. So, with financial backing from the Steven Dodd Foundation for Mathematics & Card Shuffling, you have been asked to help Tarrah's to write a Blackjack simulation that will help them evaluate the plausibility of their new reward plan.
To start with, each player is given two cards face up. Cards ranked 2 - 10 are worth their face value, face cards are worth 10, and Aces are worth either 1 or 11. The idea is to get the two cards to be as close to 21 as possible without exceeding 21. To get started with your program, we can start with a simple representation of a normal playing card:
struct card
{
int rank; // Let Ace = 1, Jack = 11, Queen = 12, and King = 13
char suit; // Let spades = 's', clubs = 'c', hearts, 'h', and diamonds = 'd'
};
Using this representation, we can construct a Blackjack hand:
struct blackjack
{
struct card first;
struct card second;
};
Write a program that will use the above two structs by randomly giving the user a Blackjack hand and printing it out. For now, don't worry if the same two cards are randomly assigned (e.g., if the user receives K♣ K♣ as his/her hand).
Extend your Part I to tell the user the value of the hand and see if they get a reward. Remember the idea is to get to 21 without going over. Add the value of the two cards (see rules above) and report their score. Tarrah's has assigned special rewards for certain card combinations. If they get any of these combinations, tell them what they've won:
| Hand | Reward |
| A♥ K♦ | Free meal at Clayton's Cafeteria |
| A♣ Q♦ | Bad luck hand! Must get up and leave the table. |
| A♠ J♠ | Jackpot hand! Win three times more than normal. |
HINT: For Part II, you can always assume the value of an ace is 11 when evaluating the score of the hand, except when you have two aces, in which case the score is 12.
Extent Part II to allow the user to “hit” (take another card) if they want to. Re-evaluate the score and report what it is using the third card. If the user gets a score greater than 21, make fun of him/her for going broke.
![[Dilbert]](dilbert.gif)