CMSC 201
Programming Project Three

The Card Game - Old Maid

Out: Friday 10/25/02
Due: before Midnight, Sunday 11/10/02

The design document for this project, design3.txt ,
is due: Before Midnight, Sunday 11/03/02

The Objective

This project will give you practice using good design techniques, separate compilation, random numbers, structures, arrays of structures, pointers and call by reference.

The Background

There is a popular children's card game known as Old Maid. It is so simple that children can play it at a very early age.

Image from www.ahs.uwaterloo.ca/~museum/vexhibit/cardgames/table3/omaid.html

The game is for two or more players. You can buy a special deck to play this game (as shown above), but you can also use a standard deck of 52 playing cards with one of the Queens removed leaving a deck of 51.

The dealer deals one card at a time to each player proceeding clockwise until all the cards are dealt. Usually some players will have more cards than others. This doesn't matter. The players then all look at their cards and discard all their pairs. A pair is two cards that have the same pip value.

Examples of pairs would be:
The 7 of diamonds and the 7 of spades
The King of clubs and the King of hearts

The dealer begins by allowing the player on his left to choose one of his cards. The player selecting the card cannot see the card since he is only shown the backs of the cards. That player will take a card from the dealer and add it to his hand. If that card makes a pair, the player can discard the pair. That is the end of that player's turn. Now that player offers his cards to the player on his left and the play continues.

If you get rid of all your cards, you are safe and turn passes to the next player. Eventually all of the cards will have been discarded except one queen (the old maid) and the player that holds this card loses the game.

Background information taken from www.pagat.com/passing/oldmaid.html

The Task

For this project you will be writing a modified version of the Old Maid, for which you'll be using a standard deck of 52 cards with one of the queens removed, leaving 51 cards.

There will be only 2 players, the computer and the user. The computer will always be the dealer, therefor the play will always begin with the user choosing a card from the computer's hand. Play will continue with the computer and the user taking turns until one of the players is left with a single queen in their hand. This player is the loser, the Old Maid.

More details

Sample Output

linux1[101] a.out Let's Play Old Maid ! Your instructions go here . . . You were dealt : 9 of diamonds 6 of clubs 2 of clubs 6 of diamonds 7 of hearts Ace of spades 4 of hearts 7 of spades 5 of hearts 4 of spades Ace of clubs Ace of diamonds 7 of clubs 5 of clubs 4 of diamonds Queen of diamonds Queen of spades 2 of hearts 8 of diamonds King of clubs Jack of diamonds Ace of hearts 3 of hearts 4 of clubs 10 of diamonds 3 of spades Discarding your pairs : Removing a pair: the 6 of clubs and the 6 of diamonds Removing a pair: the 2 of clubs and the 2 of hearts Removing a pair: the 7 of hearts and the 7 of spades Removing a pair: the Ace of spades and the Ace of clubs Removing a pair: the 4 of hearts and the 4 of spades Removing a pair: the 5 of hearts and the 5 of clubs Removing a pair: the Ace of diamonds and the Ace of hearts Removing a pair: the 4 of diamonds and the 4 of clubs Removing a pair: the Queen of diamonds and the Queen of spades Removing a pair: the 3 of hearts and the 3 of spades Here is your hand : 9 of diamonds 7 of clubs 8 of diamonds King of clubs Jack of diamonds 10 of diamonds I'm discarding my pairs : Removing a pair: the 9 of hearts and the 9 of spades Removing a pair: the 10 of spades and the 10 of clubs Removing a pair: the 2 of diamonds and the 2 of spades Removing a pair: the 6 of hearts and the 6 of spades Removing a pair: the Jack of spades and the Jack of hearts Removing a pair: the 5 of diamonds and the 5 of spades Removing a pair: the King of diamonds and the King of hearts Removing a pair: the 3 of diamonds and the 3 of clubs Removing a pair: the 8 of clubs and the 8 of spades I have 7 cards. Which one do you choose ? Enter a number between 1 and 7 : 1 Removing a pair: the King of clubs and the King of spades You have : Jack of diamonds 10 of diamonds 8 of diamonds 9 of diamonds 7 of clubs I'll take card #5 Removing a pair: the 7 of diamonds and the 7 of clubs I have 5 cards. Which one do you choose ? Enter a number between 1 and 5 : 3 Removing a pair: the Jack of clubs and the Jack of diamonds You have : 9 of diamonds 8 of diamonds 10 of diamonds I'll take card #1 Removing a pair: the 9 of diamonds and the 9 of clubs I have 3 cards. Which one do you choose ? Enter a number between 1 and 3 : 1 You have : Queen of hearts 10 of diamonds 8 of diamonds I'll take card #1 I have 3 cards. Which one do you choose ? Enter a number between 1 and 3 : 1 You have : 8 of diamonds Queen of hearts 10 of diamonds I'll take card #2 I have 3 cards. Which one do you choose ? Enter a number between 1 and 3 : 1 Removing a pair: the 8 of diamonds and the 8 of hearts You have : 10 of diamonds I'll take card #1 Removing a pair: the 10 of hearts and the 10 of diamonds Results : I'M THE OLD MAID - YOU WON !!! linux1[102] a.out Let's Play Old Maid ! Your instructions go here . . . You were dealt : 6 of clubs 3 of diamonds 3 of hearts 3 of spades Ace of spades 10 of diamonds Jack of spades 3 of clubs 7 of hearts Queen of diamonds 10 of spades 10 of hearts 9 of clubs 7 of clubs King of spades Queen of spades 8 of spades Jack of diamonds 6 of diamonds 2 of diamonds 2 of spades King of diamonds Queen of hearts 9 of hearts 4 of hearts 10 of clubs Discarding your pairs : Removing a pair: the 6 of clubs and the 6 of diamonds Removing a pair: the 3 of diamonds and the 3 of hearts Removing a pair: the 3 of spades and the 3 of clubs Removing a pair: the 10 of diamonds and the 10 of spades Removing a pair: the Jack of spades and the Jack of diamonds Removing a pair: the 7 of hearts and the 7 of clubs Removing a pair: the Queen of diamonds and the Queen of spades Removing a pair: the 10 of hearts and the 10 of clubs Removing a pair: the 9 of clubs and the 9 of hearts Removing a pair: the King of spades and the King of diamonds Removing a pair: the 2 of diamonds and the 2 of spades Here is your hand : Ace of spades 8 of spades Queen of hearts 4 of hearts I'm discarding my pairs : Removing a pair: the Jack of clubs and the Jack of hearts Removing a pair: the 5 of spades and the 5 of clubs Removing a pair: the King of clubs and the King of hearts Removing a pair: the 2 of hearts and the 2 of clubs Removing a pair: the 8 of diamonds and the 8 of hearts Removing a pair: the 7 of spades and the 7 of diamonds Removing a pair: the 9 of diamonds and the 9 of spades Removing a pair: the 4 of diamonds and the 4 of clubs Removing a pair: the 6 of hearts and the 6 of spades Removing a pair: the 5 of diamonds and the 5 of hearts Removing a pair: the Ace of hearts and the Ace of clubs I have 3 cards. Which one do you choose ? Enter a number between 1 and 3 : 3 Removing a pair: the 8 of spades and the 8 of clubs You have : 4 of hearts Ace of spades Queen of hearts I'll take card #2 Removing a pair: the Ace of diamonds and the Ace of spades I have 1 cards. Which one do you choose ? Enter a number between 1 and 1 : 1 Removing a pair: the 4 of spades and the 4 of hearts Results : YOU'RE THE OLD MAID -- YOU LOSE !!! linux1[103] Although your output may look different than mine, you should print out the same information.

What to Turn In

You must use separate compilation for this project and should have a file, called proj3.c, that contains only the function main(). You should also have oldmaid.c and oldmaid.h, that contain functions related to the game of Old Maid and the prototypes for those functions, respectively. You may, of course, have other .c and .h files, as you see fit. You should realize that some functions you will be writing for this project could be used for any card game and should be in their own .c file, perhaps called cards.c with their prototypes in a file called cards.h.

Submit as follows:

submit cs201 Proj3 proj3.c oldmaid.c oldmaid.h (followed by any other .c & .h files you have)

The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.