HOMEWORK 07 - SMART BLACKJACK

Concepts

In this homework, we will use an array to create a standard deck of 52 playing cards. Our Blackjack game will become much more realistic now.

Overview

For this assignment, your job is to modify the simple Blackjack game from Homework 06. You may use your prior submission, or our provided solution to Homework06: hw07_startingpoint.cpp.

The Specifics

In Homework 06, every time we needed a card, we randomly generated one. With the power of arrays, we can do better than that!

Before gameplay starts, create an array of Cards that has a size of 52. Populate the array with all 52 card values (Ace of Hearts through King of Spades).

Modify (or create) your PrintCard() function so that it will print "Ace", "Jack", "Queen", or "King" in place of 1, 11, 12, and 13 respectively.

At this point, print all cards in your array to ensure you have all 52 cards represented. Once you are satisfied all 52 cards are there, comment out these print statements.

Now, for the most important part, create a function called ShuffleDeck that takes an array of cards and the size of the array as input. This function randomly selects two cards from the deck and swaps them. This operation should be performed enough times to ensure the entire deck is thoroughly shuffled. To verify the cards have been shuffled, again print all cards in your array. If you are happy with the randomness of the card order, comment out these print statements as well.

Ready to implement "real" Blackjack?? (or at least Blackjack simulated in Visual Studio?) First, remove the RandomCard() function. Second, create a function called GetNextCard that takes the array of cards, the size of the array, and a currentCardIndex (integer) as input. The function should return a Card as output. The currentCardIndex keeps track of our place in the deck and the card we should deal next. Naturally, it's initial value should correspond to the "top" of the deck, and the function should return the card at the current position in the deck (i.e., the "top" card in the deck). The function then needs to advance our current index; that is, since we've now "dealt" this card, we don't want to deal it again!

One issue you may have pondered ... what happens if you play several rounds and the deck runs out of cards? There are issues with re-shuffling the deck since we are not tracking the cards currently in play. Thus, instead, we sugget you add code to re-shuffle the deck if the deck is "low" on cards. Specifically, when a user requests another game of Blackjack, re-shuffle the deck if the currentCardIndex indicates there are less than 20 cards in the deck.

The final change is to replace every instance of RandomCard() with GetNextCard(). And then enjoy your better smarter Blackjack! Just remember, the house always wins. Also note that you know have the starting point to create any card based game (war, poker, go fish, etc.). Hmmm ... could be useful for your final project?

Extra Credit!

For the first extra credit part, allow an Ace to count as 1 or 11. That is, if the user has an Ace, then his/her total should show as 20. If the user chooses to hit and are dealt a 5, then his/her total should become 15. Implementing this correctly will earn you 3 extra points.

For the second extra credit part, if either player is dealt a Blackjack, then the hand should instantly end. Implementing this correctly will earn you 2 extra credit points.

Hints

Submission

You need to submit your solution of this homework (HW07) with four lab assignments: Lab07A, Lab07B, Lab07C, and Lab07D. Detailed generic instructions for submitting homework assignments are available. For homework due this Friday (Mar 11), follow these specific steps: