CSE 413 Spring 2011

Assignment 5 -- Go Fish!

Due: Electronically: 11 pm Tuesday, May 17.

Goals

For this project you will implement a computerized version of the card game Go Fish! The rules of the game are summarized below. The goals of this assignment are to gain experience with Ruby programming and with designing object-oriented programs. This writeup describes the basic constraints of the program you should produce, but many of the details are up to you.

The Game

Go Fish is played with a regular deck of 52 playing cards. Cards in a deck have one of four possible suits (Hearts, Diamonds, Spades, and Clubs), and face values of 2-10, Jack, Queen, King, and Ace. A game is played as follows.

(There are variations on the rules - for instance, in most versions, a player may only ask for cards that match the rank of one or more cards that they already hold. Also, in the real game, a player has a choice of whether to discard pairs or not. You can add these rules as extensions to your game, but they are not required.)

The Program

You should write a Ruby program that allows the user to play Go Fish with the computer. When the user runs the program, it should behave as follows:

The program should print additional messages to describe the progress of the game as needed.

Implementation

One of your jobs in this assignment is to decide what classes and objects you need, what messages those objects should respond to, and how the parts of your program should fit together. There are a few constraints that you must follow, given here. Beyond these specific requirements, your classes and objects should describe well thought-out individual concepts, and the parts of the program should interact with each other through small, simple interfaces.

Your implementation must include at least the following classes:

Beyond these bare specifications, you will need logic to do things like create a randomly shuffled deck of 52 cards to start a game, interact with the user, play the game on behalf of the computer, and so forth.

You should be prepared to let your design evolve as you implement the program. It is normal in designing object-oriented (or other) code to discover that decisions you made early in the process ought to be changed as the program evolves, to make things simpler and cleaner. Don't be afraid to change things as you go - don't get over-committed to your early decisions, and don't continue to hack at a design to get it to "work" when it would be better to change something.

Your code should use Ruby collections, iterators, and blocks where this makes sense. (for example, use the each method instead of writing something like a Java for-loop to iterate through the elements in a collection, etc.)

Your Ruby code can, if you wish, be stored in a single file, or you can split it up into separate files for individual classes or related classes. For this project, do whichever is simplest for you.

However, you should have at least one source file named fish.rb, and it should be possible to run your game with the command ruby fish.rb (or its equivalent on your system)

Extra Credit

A small amount of extra credit will be awarded for programs that include interesting extensions. A simple extension would enforce the restriction that players can only ask for cards that have the same rank as one they already hold in their hand. A more complex extension would be to make the computer smarter in its game play, for instance, instead of randomly asking for a particular card rank, keep track of the previous moves in the game and make smarter choices. A devious extension would be to add various "cheating" modes, where either the computer or the human user could peek at the other player's hand or do other evil things.

If you implement any extensions, include a file readme.txt with your submission that gives a brief explanation of your extensions. If you add any commands or options to the game, include instructions on how to use them.

What to Hand In

Electronic Submission

Turn in a copy of your Ruby source files and, if you have one, the readme.txt file using the regular online collection dropbox. Be sure that your name is included at the beginning of each of your files in a comment.