C programming question: Background Information: There is a popular children\'s c
ID: 3819215 • Letter: C
Question
C programming question:
Background Information: There is a popular children's card game known as Old Maid. The game is for two or more players. You can buy a special deck to play this game but you can also use a standard deck of 52 playing cards with a Joker card added to make it a deck of 53 cards 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. The cards of one player are called a player's hand. The players then look at their cards and "discard" all their pairs (cards with the same face value Examples of pairs would be The 9 of diamonds and the 9 of spades (4) The Jack of clubs and the Jack of hearts The Ace (1) of clubs and the Ace (1) of spades (4) After all matching pairs are discarded, the dealer begins by allowing the player on his/her left to choose one of his/her cards. The player selecting the card cannot see the card since he/she isExplanation / Answer
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.
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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.