Starting from:

$30

Lab08. Poker Hands

EE231002 Introduction to Programming
Lab08. Poker Hands

Poker is a popular card game. In this game, each player can receive five cards and then the
hand of these five cards are ranked by the following categories, from high to low.
• Straight flush: The hand is both a straight and a flush, see below for the definition of
straight and flush.
• Four of a kind: The hand has four cards of the same rank.
• Full house: The hand consists of a three-of-a-kind and a pair.
• Flush: All five cards of the hand are of the same suit.
• Straight: The five cards are in sequence.
• Three of a kind: There are three cards in the hand of the same rank.
• Two pair: There are two pairs of different ranks in the hand.
• One pair: There are two cards of the same rank in the hand.
• High card: None of the above in the hand.
The rank of the cards, from high to low, are A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, and 2; And
there are four suits in a deck of cards: Spade, Heart, Diamond and Club. Totally, there are
52 cards in a deck.
Your assignment is to write a program that uses random number function, rand(), to find
the probability of the hands of poker game. The number of experiments should be 10,000,000 and
each experiment is dealt by a well shuffled 52 cards with the same probability for each card. To select an integer randomly in a range [1, N] can be done using the rand() function as the following:
k=rand() % N + 1;
Note that the rand() function generates a random number in the range from 0 to RAND_MAX.
And to use this function, one should include the stdlib.h header file as the following.
#include <stdlib.h>
The program output should look like the following.
1
$ ./a.out
Categories Probability
Straight flush 0.xxxx%
Four of a kind xxxxxx%
Full house xxxxxx%
Flush xxxxxx%
Straight xxxxxx%
Three of a kind xxxxxx%
Two pair xxxxxx%
One pair xxxxxx%
High card xxxxxx%
Notes.
1. Create a directory lab08 and use it as the working directory.
2. Name your program source file as lab08.c.
3. The first few lines of your program should be comments as the following.
/* EE231002 Lab08. Poker Hands
ID, Name
Date:
*/
4. To get more uniform random number between 0 and 51, the following statement is recommended.
k = (rand() / 1000) % 52;
5. After you finish verifying your program, you can submit your source code by
$ ∼ee2310/bin/submit lab08 lab08.c
If you see a ”submitted successfully” message, then you are done. In case you want to
check which file and at what time you submitted your labs, you can type in the following
command:
$ ∼ee2310/bin/subrec lab08
It will show the submission records of lab08.
6. You should try to write the program as efficient as possible. The format of your program
should be compact and easy to understand. These are part of the grading criteria.
2

More products