CS151 – Fall 2007: Programming Project 5

Due: Friday, November 9, 2007, 11:59:59:999 p.m. EST

 

In this project you will implement an interactive version of the Black Jack playing card game.  As I demonstrated in class, this version of the game will be text based and display and solicit input in the terminal window.  I will not provide any skeleton classes for this project, but I will make some general suggestions about design, and you should of course use the PlayingCard and BlackJack hand classes from Project 3.  Feel free to use your versions or my solutions as a starting point.  The PlayingCard class probably won't require any changes.  This project requires some design on your part, so it is very important that you start thinking about the design early on.

 

At a high level the Black Jack game consists of a number of hands played between the player who is running your program and the dealer who is played by your program.  The player should be able to play as many hands as desired until they indicate they want to quit playing.  Each hand consists of the following steps:

1.    Deal two cards to the player and two to the dealer (these are their hands).  Then display the contents of the two hands for the player to see.

 

2.    Give the player the chance to add cards to their hand ("hit") until the total of their hand exceeds 21 (known as "going bust"), they have 5 cards totaling less than or equal to 21 (known as a "five card Charlie"), or they want to stop adding cards (known as "stand").

 

3.    Assuming the player hasn't gone bust, add cards to the dealer's hand according to a deterministic rule.  Two popular rules are "Stand on 17" and "Hit on 16".  The first means the dealer keeps adding cards to its hand until the total for the hand is 17 or greater (or it goes bust).

 

4.    Display a message indicating whether the player or the dealer won and the reason, e.g. bust, twenty-one, etc.

 

5.    Play another hand with the remaining cards if the player wants to.

 

Additional Details

1.  Whenever the player or dealer adds cards to their hand, you should probably redisplay the contents of one or both of their hands.

 

2.  If the user gets 21 with their first two cards or they get a five card Charlie, they usually automatically win, so you should skip the part where the dealer draws cards and just declare the player the winner.

 

3.  Clearly document the rule(s) that determine how the dealer plays its hand.  You should document this both externally, i.e. in .html comments, and internally, i.e. displayed prominently for in the game for the player.

 

4.  Play each successive hand with the cards remaining in the deck.  When the number of cards gets below some minimum (determined by you and included as a constant, e.g. 10) create a new deck and add the new deck to the remaining cards.  Feel free to start the game with more than a single 52-card deck.  Casinos typically play with "shoes" of multiple decks to prevent players from counting cards.  Again, document these choices externally and internally.

 

Design Requirements

Please create a public class called BlackJackGame.  At minimum that class should have two public methods:

1.  Play() which takes no parameters and doesn't return anything.  This contains the high level logic and user interaction (similar to the solve() method in the last project)

 

2.  The standard static main() method that creates an object of the BlackJackGame class and calls that object's play() method.  This will allow someone to play your game by just running the main method (in or outside of BlueJ).

 

The descriptions of the hand should be nice English phrases.  If you just want to use the getDescription() method for each card in the hand, that's perfectly fine.  Of course you also want to indicate which hand (dealer or player's) you are describing!

 

Design Suggestions

I recommend that you use a total of 4 classes: BlackJackGame, BlackJackDeck, BlackJackHand, and PlayingCard.  Note that you will probably want to modify whatever BlackJackHand class you start with.  If BlackJackHand doesn't already have boolean methods isBust() and isFiveCardCharlie(), I recommend adding them.  You may also want to add a getDescription() method to the hand.

The exact functionality of the BlackJackDeck will be determined by how you design and execute the game.  However, you will certainly need to construct a standard deck of 52 cards with their values set for Black Jack. 

See my BlackJackHandTester from Project 3 for some ideas on how to do this cleanly.  Feel free to use that code, but if you do, please cite it in your program documentation!  You will also need a way to combine two decks of cards into a single deck, and a way to draw a random card from the deck.

As for the BlackJackGame class, I recommend dividing up the activities in a hand into a number of separate methods.  This will make your code easer to read, debug, and modify later.  How many methods and what those methods do is up to you.

 

For any other suggestions please ask me outside of class AFTER you have thought about it on your own for some time.  Please do not consult your friends about your project design except for very general questions.  I remind you that this is clearly spelled out in the collaboration policy.

 

Extra Credit

The sky is the limit on this project.  Feel free to add the capability for a user to bet including double down and split hand bets, play multiple hands, get hints about what to do with their hand, etc.  When betting the dealer's hand typically has one card face up and one face down until the player has finished their hand.  Be as creative as you like: the more the better.

Strategy and Hints

Start early and try to make a little progress each day.  Test early and often.  Sections 2.8, 3.6, 5.5, 6.6--6.7, and 7.8 of your book discuss different aspects of testing.  You can use BlueJ to test constructors and simple methods interactively.  Feel free to use the logging capabilities described in Advanced Topic 5.6, the BlueJ debugger (see Lab 7), etc. to help you find errors in your classes.  Make use of the online documentation, the Olin lab TAs, your fellow classmates (to the extent allowed by the Collaboration Policy), and me early and often.  Don't put off starting the project until a day or two before it's due and expect to produce a quality piece of work.

 

Style and Documentation

All constructors, methods, and public instance variables should be commented using @param and @return tags to facilitate the generation of .html documentation similar to the Java Class Libraries on the Web via the Javadoc utility.  BlueJ automatically generates this documentation for your class when you switch from "Implementation" to "Interface" in the class editor window.  We've discussed the use of these tags in class and additional information is in section 3.3 of your textbook. 

 

Your code should adhere to the stylistic guidelines we have been discussing and which are in Appendix A of your textbook as much as possible.  In particular group different constructors, instance variables, and similar methods together.  Use meaningful variable names and internally comment your code liberally (with // or /*   */ pairs).

 

The graders will be instructed to determine approximately 10-15% of your project grade based on style, readability, and documentation.  Please use indentation, white space, and other stylistic techniques to make your code easier to read (and grade).  Define and use public constants instead of using so-called "magic numbers" in your code.

 

Project Submission

You will again submit your projects electronically.  To do so

1.    Connect to the Academics volume of the server called fileserver1.  From a Mac choose "Connect to Server ..." from the "Go" menu in the Finder, type afp://fileserver1 in the dialog box, and select Academics from the volume list.  From Windows machine open Windows Explorer, select "Map Network Drive" from the tools menu, pick a free drive letter and type \\fileserver1\Academics or just type it directly into the address filed.  When prompted for your user name and password, type COLBY\username, where username is your Colby username and enter your password.  These instructions are adapted from http://www.colby.edu/administration_cs/its/support/fileserver1.cfm. 

2.    On the Academics volume inside of the COMP/CS151 folder/directory you will see a folder with your Colby e-mail/login name and within that a private folder.  Copy the BlueJ project folder containing your project 5 solution to your private folder.  Change its name to project5 and delete all .class files and any test classes you created during development. Include a brief readme.txt file that explains whatever you think is necessary (including any fancy functionality you added). DO NOT submit a class that doesn't compile!  If you can't get something working comment it out (/*  */) so the grader can possibly give you partial credit for your efforts.  DO NOT submit your project late!  You have two weeks to work on it, so plan accordingly.  As the syllabus states, late projects are graded at my discretion.

 

Acknowledgements