Reference no: EM132263653
Programming Tasks
You should begin by reading the example code carefully. It contains some hints and comments on where to fill in the blanks.
The first step will be writing a function that displays the card. You can use the various bit fields as an index to an array of strings once extracted. The arrays are:
static char *suits[] = {"Hearts","Diamonds",
"Clubs","Spades"};
static char *values[]= {"Ace","Two","Three","Four",
"Five","Six","Seven","Eight",
"Nine","Ten","Jack","Queen", "King"};
static char *colour[]= {"Black","Red"};
You should print the card as "Ace of Hearts, is Red", with one card per line.
Test your function by creating cards individually and displaying them.
Once you can display cards you should then write a function that populates a deck (array of 52) with cards. The deck should be sorted in order by suit, that is Ace to King of hearts, then diamonds etc. With some clever arithmetic you can accomplish this in one pass of the deck. Print the deck once you have populated it.
Once you have a deck, develop a method for shuffling it. As a hint investigate the C standard library functions rand() and srand(). Shuffling involves mixing the cards up so that the order is random. Print the deck a second time and check that you have actually mixed up the deck.
Now that we have a working shuffling algorithm we are ready to play cards. To keep things reasonably simple we are going to simulate a simplified version of poker. In this game 5 hands of five cards are dealt. There is no swapping of cards and the winner is determined by who has the highest pair. A pair of cards are cards that have the same value e.g. the Ace of Hearts and the Ace of Spades are a pair. The number of pairs contained in a hand, three or four of a kinds have no bearing on the result. If none of the five hands contains a pair, or two hands contain the same highest pair, the game is considered drawn.
Although traditional poker has the Ace card being a turning point, that is it can be the low card or the high card, the cards in this game have a fixed order, as described in Table 2. This means that Aces are low and can be beaten by any other pair.
You should develop a program that implements this game. Additionally you should print each of the hands sorted in order of value, print the number of pairs in each hand and if there is at least 1 pair print the value of the highest pair. Once all five hands have been printed you should indicate if there was a winner and the value of the pair that won. If there was no winner you should indicate that the game was drawn.
Your hands should be stored in an array for ease of use and when sorting the hand you should investigate the C standard library function qsort(), which might make things easier for you.
Attachment:- Instructions.rar