UMBC CS 201, Fall 02
 UMBC CMSC 201 Fall '02 CSEE | 201 | 201 F'02 | lectures | news | help

 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

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

• You must use the following structure definition for your cards: typedef struct card { int suit; int pip; } CARD;
• You must use arrays of CARDs to simulate the deck, and each of the players' hands.

• Create a full deck of 52 cards that are in order. In other words, for each of the four suits, the cards should be in order from Ace (1) through King (13).

• After the full deck has been created, you must remove one of the queens from it, leaving 51 cards.

• You must then shuffle the deck, using the following algorithm:
For each card in the deck, get a random number in the range of 0 to 50 to be used as the index of the element to swap that card with, i.e. if deck[0] holds the Ace of clubs and the random number drawn was 16, and deck[16] holds the 4 of diamonds, then after the first swap, deck[0] would hold the 4 of diamonds and deck[16] would hold the Ace of clubs. You would then proceed to deck[1], find a random index of a card to swap with, and swap those cards, etc.

• You must seed the random number generator with a call to time().

• After shuffling the deck, you must deal the cards by giving one card to the user, followed by one card to the computer, followed by one card to the user, etc. until all of the cards have been dealt.

• Next your program should remove all pairs from each of the players' hands and identify those pairs as the cards are being removed.

• Next play will begin. Remember that the user gets to choose a card from the computer's hand first.

• You must have a CreateDeck() function that creates a standard deck of 52 cards, that could be used for any card playing game.

• Your ShuffleDeck() should use the algorithm explained above and should work with any size deck of cards.

• You must have a function called PlayersTurn(), which has the following prototype: void PlayersTurn (CARD player[], int* playerSizePtr, CARD computer[], int* computerSizePtr); and a function called ComputersTurn(), which has the following prototype: void ComputersTurn (CARD player[], int* playerSizePtr, CARD computer[], int* computerSizePtr); You may not alter these prototypes in any way.

• After a player draws a card from the opponent's hand and places it into his hand, whether the player is the computer or the user, the hand must be shuffled. This shuffling is necessary to keep the human player from knowing where the old maid is, if the computer has just drawn it from the user's hand.

• At the end of the game, you must announce who the loser is.

## 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.