Project 5
Spring 2002
Due: Tue., Apr 30 @ Midnight
12 points
You figure that on-line gambling is the way to ensure your future in either the Bahamas or in some prison for white-collar criminals. Either way, it's a paid vacation. And since Black Jack is the only betting game you know, you figure it's a good place to start.
We're actually going to implement a slightly simplified version, but it will still capture the essence of the game. We'll assume there is a dealer and one player. The computer will be the dealer, and the person typing on the keyboard will be the player.
The objective is to get a hand of playing cards with a total value that's closest to 21 without going over. The numbered cards are simply counted as is (i.e., Five of diamonds equal five points). The face cards---Jack, Queen, and King---are worth 10 points. Aces are usually worth either one or eleven, but for simplicity, we'll assume they're worth eleven. For example, if a player were dealt the Queen of Hearts (QH) and the Jack of Diamonds (JD), then the value of his hand would be 10 + 10 = 20. On the other hand (no pun intended), if a player were dealt the Ace of Spades (AS), the Three of Hearts (3H), and the King of Diamonds (KD), then, using our scoring method, he would be over 21 with a score of 24, and is said to have ``busted.'' (No, not burst.)
After the deck is shuffled, the dealer deals two cards to the player and two cards to herself, which we'll assume she deals face down. The player computes his score and decides whether to ``stay'' or take a ``hit.'' No, from the deck, meaning that he will request another card from the dealer. The player can continue taking hits until he busts or until he is satisfied with his hand, in which case he stays. If he busts, he must declare it, and the game is over with the dealer winning.
When the player finally stays, then the dealer takes hits until she either busts or stays. Generally, in Vegas, the dealer always hits under 17, and stays when over. When the dealer finally stays, the game goes to person with the highest hand, although ties always go to the dealer.
As I said previously, don't worry about Aces counting 1. As implied by the rule that ties go to the dealer, if the dealer's hand totals 21, then she wins automatically, but don't worry about explicitly coding this logic. Also don't worry about splits, doubling down, and five-card Charlies.
Here are some sample runs, and here is the high-level design.
To deal cards, you'll have to select a card at random from the deck (i.e., the linked list of cards). To do this, we'll use functions from the C Standard Library that implement a pseudorandom number generator. You can include these using the directive:
#include <cstdlib>
To initialize the random number generator, you must ``seed'' it with an int using the function void srand(int). There are lots of ways to do this. For instance, a popular approach is to poll the computer's system clock and seed with that number, which is fine, unless you're writing crypto software. But for simplicity, just ask the user to enter an int from the console, and pass it into srand.
Once you've seeded the random number generator, successive calls to the function int rand() will return a sequence of pseudorandom numbers, which are ints between 0 and RAND_MAX, which is a system constant that we don't have to worry about for this project. We say the numbers are pseudorandom because they aren't really random. It's a function generating these numbers, and sometimes they aren't very random at all. Moreover, if you seed the random number generator with the same integer, it'll generate the same sequence of ``random'' numbers.
So, if you want to simulate a coin toss, you can use your old friend the modulus operator to help generate two possible values: cout << rand() % 2 << endl. That'll generate zeros and ones randomly. If you want to simulate a six-sided die, then rand() % 6 will generate random numbers in the range [0, 5]. Got it?
The main function should then seed the random number generator, declare an instance of the BlackJack class, and call the play method.
You have everything you need to implement the Card class. After Tuesday's lecture (4/16), you should have everything you need to complete the project. There are subtleties. Start now.
Instructions for Electronic Submission: At the top of the file containing your source code (i.e., the file containing the C++ instructions), place the following header comment, with the appropriate modifications:
// // Project 5 // Name: <your name> // E-mail: <e-mail address> // Instructor: Maloof // TA: <TA's name> // COSC 071 // // In accordance with the class policies and Georgetown's Honor Code, // I certify that, with the exceptions of the lecture notes and those // items noted below, I have neither given nor received any assistance // on this project. // // Description: <Describe your program> //
Although you may use any C++ compiler to develop your program, it must run under UNIX and must compile using GNU g++. When you are ready to submit your program for grading, if necessary, use ws-FTP to transfer your source and data file from your PC to gusun. Use SSH to logon to gusun, and use pine to e-mail it to your TA. Use your netid and the suffix ``.cc'' as the subject.
gusun% pine
When the menu appears, select the item for composing e-mail. Assume that your netid is ab123, the name of your source file is proj1.cpp, and your TA's e-mail address is ``imagoodtamaloof@cs''.
Type your TA's e-mail address in the To field, and type your netid with the .cc suffix in the Subject field (no spaces before or after). Move the cursor down into the MESSAGE TEXT screen, and type the ^R command. Pine will ask for a file name (e.g., proj1.cpp), which it will then load as your message text. At this point, your screen should look something like the following:
Finally, type ^X to send the e-mail to your TA.
IMPORTANT: Do not send your source code as an attachment. Do not use a mail client other than pine.
If you need to include a message to you TA about your submission, then type the message as a comment in the program.
Once you've submitted your project, it is important to keep an electronic copy on a university machine (e.g., gusun or cssun) that preserves the modification date and time. If we lose your project or the e-mail system breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.
The TAs who will be grading your projects this semester are listed on the main page. You must e-mail your project before midnight on the due date.