CS 223 Assignment due at class time, 4/23/01

You may work with a partner on this assignment.

For this assignment, you will write a computer program to generate and count various kinds of 5-card poker hands. In the process, you will learn algorithms for generating all permutations of a set and for generating random permutations. You will also be able to compare the frequency of various types of poker hands in theory (by generating and counting all possible hands) and practice (by using a pseudo-random number generator).

Poker background

I will assume that you know the structure of a standard 52-card deck of playing cards. For all of this discussion, Aces will be considered high (that is, an Ace has greater value than a King, and may not play the role of the number 1).

A 5-card poker hand has a type determined by the cards it contains. For this assignment, we will work with three types:

Note: for this assignment, we will consider a straight flush (that is, a straight, all of whose cards are the same suit) to count both as a straight and as a flush.

To write computer programs involving playing cards, you need to have some mechanism for storing the cards. You can certainly use a struct or class to represent a card. A very simple version of such a struct might contain two integers, one for the suit and the other for the value of the card.

I would like to recommend a simpler strategy. Let a suit be represented by an integer between 0 and 3 (e.g. 0 = clubs, 1 = diamonds, 2 = hearts, and 3 = spades), and a card's value by an integer between 0 and 12 (0 = deuce, 1 = 3,..., 11 = K, 12 = A). You can then represent an individual card as a single integer between 0 and 51. If you do that, then (cardNumber / 13) will be the card's suit, and (cardNumber % 13) will be the card's value. For example, card number 33 would have 33 % 13 = 7 and 33 / 13 = 2. That is, 33 represents the 9 of hearts.

What the program should do

Phase I: Generate all C(52,5) distinct 5-card hands, and count how many of them are flushes, how many are straights, and how many are full houses. Print out these counts.

Phase II: Generate C(52,5) random 5-card hands, and count how many of them are flushes, how many are straights, and how many are full houses. Print out these counts. The function Shuffle() in sorts.cpp shows how to generate a random permutation of the integers between 0 and N-1.

Phase III: Compare your results in the first two phases to the counts you get when you do a paper-and-pencil combinatorial analysis. Write a few sentences on the comparisons between the three sets of counts, and put your analysis in a file called pokerReadMe.txt. Submit your source code and your pokerReadMe.txt via the Homework Submission Program.

Start early, have fun, and keep in touch.



Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, (507) 646-4364, jondich@carleton.edu