CMSC 341 Fall 2007
Project 2

Assigned Wednesday, Sept 26, 2007
Due 11:59pm, Friday Oct 12, 2007
Intermediate deadline Wed Oct 3, 2007
Updates Minor changes to Proj2.java (fixed bug with merged hands, Sept 27) and DeckInterface.java (added deal method required by Proj2.java, Oct 1).

Objectives

Overview

In this project, you will build an interactive version of the Rummy card game. We will give you basic UI code and a Card class, as well as specify an interface that you must implement for the Hand, Deck, and Pile clases. Other class design choices are yours. There are many variations of rummy, you are required to follow the rules listed below.


Rules of Play

These rules are a slight adaptation of standard Rummy rules. The objective of this game is to make melds (sets and runs) of similar cards and lay them on the table until all cards in your hand have been disposed of. A set is three or more cards of the same rank, such as three aces or four sevens. A run is three or more sequential cards of the same suit, such as the three-four-five of clubs or the jack-queen-king of diamonds. The ace is always low.

Each player is dealt nine cards from the deck (stock). The next card is turned face-up to initiate the discard pile. The stock is placed face-down on the table. In each turn, a player draws one card from either the stock or discard pile. They may optionally lay sets or runs on the table. They may also optionally lay cards that fit in sets or runs already on the table. The turn ends with a discard. If a player is able to lay all remaining cards on the table at the end of a turn, the discard is optional.

The game is over when one player is out of cards or the stock is exhausted. At this point, players count the points remaining in their hands. Aces are worth one, face cards are worth ten, and all other cards are worth their face value. Lowest value hand wins.


Project Specification

In this project you will be implementing a stack class, named MyStack, from scratch. It should provide the standard stack operations of push, pop, top, and isEmpty. You should use generics for this class.

You are also expected to write the Hand, Deck, and Pile clases that implement the HandInterface, DeckInterface, and PileInterface interfaces. You may not change the methods given in these interfaces, but may add methods to these classes. Hand and Deck may be derived from other Java classes, such as those in the Collection framework. Pile should be derived from your MyStack class.

Your Deck class should provide a constructor which creates a 52 card deck of shuffled cards.

Your Hand class should maintain the cards in sorted order. Your Hand class should provide a play() function to implement a computer opponent. This automated player can be really stupid, but must follow the rules. Specifically, for each choice the automated player must make (for example, whether to draw from stock or discards), a random choice is fine. A more intelligient play routine would be extra credit. The base project need look only for sets in the hand. Runs are left as extra credit. We will be providing you with the code for the UI, interactive game control, and the Card class. The program takes two kinds of command line arguments (processed in the provided code). The -h switch enables logging of actions (by default there is no logging). The player number switch (-0, -1, or -2) gives the number of interactive players in the game (by default this is 0, indicating two automated players).

Dr. Rheingans' public directory for this project is

/afs/umbc.edu/users/r/h/rheingan/pub/341/Proj2 and it contains the Proj2.java, Card.java, and interface code mentioned above.

Sample Results

Initial Player 0: 7C, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 
Initial Player 1: AD, 7D, JD, 5H, 8H, 4S, 7S, TS, JS, 
Player 0
    Added: 9C
    Discarded: 7C
    Hand now: 9C, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 
Player 1
    Added: QC
    Discarded: QC
    Hand now: AD, 7D, JD, 5H, 8H, 4S, 7S, TS, JS, 
Player 0
    Added: QC
    Discarded: 9C
    Hand now: QC, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 
Player 1
    Added: 9C
    Discarded: 9C
    Hand now: AD, 7D, JD, 5H, 8H, 4S, 7S, TS, JS, 
Player 0
    Added: 9C
    Discarded: 9C
    Hand now: QC, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 
Player 1
    Added: 7H
    Discarded: AD
    Hand now: 7D, JD, 5H, 7H, 8H, 4S, 7S, TS, JS, 
Player 0
    Added: AD
    Discarded: QC
    Hand now: AD, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 
Player 1
    Added: 5C
    Discarded: 5C
    Hand now: 7D, JD, 5H, 7H, 8H, 4S, 7S, TS, JS, 
Player 0
    Added: 5C
    Discarded: 5C
    Hand now: AD, 4D, 9D, QD, 2H, 4H, 9H, JH, AS, 

(and so on)

Player 1
    Added: TH
    Discarded: 7H
    Hand now: 8H, TH, JH, QH, 5S, 8S, JS, QS, KS, 
Player 0
    Added: 7C
    Discarded: 7C
    Hand now: KH, AS, 2S, 3S, 4S, 6S, 7S, 9S, TS, 
Points: 52 to 81
Player 0 Wins!

Project Notes, Hints, and Requirements

  1. This project will be developed using the Eclipse Integrated Development Environment (IDE). Eclipse is designed to assist you when writing Java applications. Eclipse is available on the PCs located in the OIT labs. If you prefer to work on your own PC, the "Eclipse IDE for Java Developers" may be downloaded free of charge from www.eclipse.org. Note that Eclipse requires that you have installed the Java Runtime Environment (JRE) on your PC. Java 5 JRE is recommended and can be downloaded from Sun Microsystems. Self-paced tutorials are available from Sun. We are discussing also offering a supervised tutorial session on Eclipse. If you would be interested in that, contact your instructor.
  2. By the intermediate deadline, hand in a description of the classes you intend to create, along with a specification of their data items and methods. You may change these choices later, but you must submit the initial design by the intermediate deadline.
  3. You must implement your Stack class from scratch, with nothing but Object or primitive types as a superclass of Stack or any data elements of Stack.
  4. The Deck and Hand classes may be subclasses of standard Java classes, such as those in the Collections framework. The Pile class should be a subclass of your MyStack class, which is implemented from scratch.
  5. You may not change the HandInterface, PileInterface, or DeckInterface.
  6. As in Project 1, you should submit your project as a package (proj2).
  7. To create the file containing your output, use unix redirection on the command line to redirect standard output to a file. Thus, once you have the output on the screen as shown in the sample results above, then you can redirect your output to file by using the command java proj2.Proj2 > p2-output.txt.
  8. This project is an OPEN assignment (as was Project 1). You are still expected to write your own code, but you may continue to help each other debug. Specifically, you: You MAY NOT: Any help you receive must be documented, including discussion, books, papers, and web resources. With each assignment, you will turn in a README text file indicating the sources you used while working on it and the type of help you received from each. If you received no help, say so. If you helped someone else, say so. Failure to include this README file will result in your program being returned ungraded.

Extra Credit

There are MANY interesting ways to extend your base project. Be sure you finish all requirements of the base project before you begin working on extra credit. Indicate any items of extra credit that you did in your README file. This will allow the TA to look for that additional functionality when grading your project.
  1. The card display in the UI is very minimalist. There are card images available through the GNU General Public License. Use these images (properly credited) to spruce up the appearance of your game. Worth five points.
  2. The base project requires only sets be discovered and laid. Extend your program to include runs. Worth five points.
  3. The random decisions in automated play make for a really dumb player. Add some heuristics to improve performance in automated play. Discuss each rule you add and why you expect it to improve performance in your README file. Worth two points for each rule (for a max of four rules).
  4. Programming effective game playing has drawn the attention of many computer scientists, mainly in the area of Artificial Intelligence. Read "A Gamut of Games" by Jonathan Schaeffer and "Game Playing: The Next Moves" by Susan Epstein (email Dr. Rheingans, rheingan AT cs.umbc.edu to get copies). Write a two-page paper very briefly summarizing the research challenges of intelligient game play and discussing how AI research might be used to improve your Rummy program. Your paper should be grammatically correct, include appropriate bibliographic references, and be submitted in pdf format. This item is MANDATORY for those in the H section, but is worth ten points for those in other sections.

Files To Be Submitted

Submit the following files:
  1. *.java (including Proj2.java and Card.java),
  2. p2-output.txt,
  3. README,
  4. any items required for extra credit options

Project grading is described in the Project Policy handout.
Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.

Remember, the due date is firm. Submittals made after midnight of the due date will not be accepted. Do not submit any files after that time.