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.
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.)
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:
a. You can optionally allow
Ato be used.
The program should print additional messages to describe the progress of the game as needed.
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:
Card: a single playing card. A card has a suit and a rank. This class should be very simple, with an
initializemethod to construct a new
Cardgiven a suit and a rank, a
to_smethod to return a string representation of the card, and any accessor methods needed to access the suit and rank of the card.
Hand: one player's
Cards. This is a collection of
Cardobjects representing the cards held by a single player. It is not necessarily ordered. It should include appropriate methods to add and remove cards, produce a string representation of a hand, search for
Cards in the hand, etc.
Cards remaining in the original deck. This is an ordered list of
Cardobjects with methods to deal a
Cardobject from the
Deckand so forth.
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 appropriate. (for example, use the
each method instead of writing something like a Java for-loop to iterate through the elements in a collection.)
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
and it should be possible to run your game with the command
(or its equivalent
on your system)
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.
Turn in a copy of your Ruby source files and, if you have one, the
using the regular online collection dropbox. Be sure that your name is included
each of your files in