Project 1
That's odd


In this project, you will write a program to help someone figure out how likely certain kinds of hands are in (a simplified version of) the game of poker.



You might have played a version of Poker, a card game in which players bet on whether their hands are better than their opponents' hands, without knowing for certain what cards their opponents hold. There are many variations of Poker, but in all of them players have or make 5-card hands, and depending on the cards in the hand, the hand can be worth more or less (or the same) as another 5-card hand. See for a list of possible hand kinds and their relative rankings.

Part of the game is understanding the odds that your hand is of higher value than your opponents' hands. A royal flush, for example, is worth more than a hand with four of a kind because it is more rare. But a four of a kind is worth more than a hand with a pair because the four of a kind is more rare. So, if you have a high value hand, there are fewer hands that can beat it and therefore if you have a four of a kind, it's a pretty good bet (but not a sure thing) that your opponent's hand is not worth more.

A simplification

In this project, we will deal with just a small subset of the possible Poker hands. We'll only deal with hands of the following kinds:

Project Requirements

Your program's goal is to determine how likely hands of the different kinds are. It should:

  1. model a deck of cards that can be shuffled and from which cards can be dealt.
  2. shuffle the deck.
  3. repeatedly create poker hands by dealing cards from that deck.
  4. count the number of such hands that are of the different kinds (pair, two pair, flush).

Your program should produce output like the following (with the x's replaced with real values you compute):

# of hands     pairs    %      2 pairs    %      flushes    %      high card    %  
    10,000        xx  xx.xx         xx  xx.xx         xx  xx.xx           xx  xx.xx
    20,000        xx  xx.xx         xx  xx.xx         xx  xx.xx           xx  xx.xx
    30,000       xxx  xx.xx        xxx  xx.xx        xxx  xx.xx          xxx  xx.xx
    40,000       xxx  xx.xx        xxx  xx.xx        xxx  xx.xx          xxx  xx.xx
    50,000      xxxx  xx.xx       xxxx  xx.xx       xxxx  xx.xx         xxxx  xx.xx
    60,000     xxxxx  xx.xx      xxxxx  xx.xx      xxxxx  xx.xx        xxxxx  xx.xx
    70,000     xxxxx  xx.xx      xxxxx  xx.xx      xxxxx  xx.xx        xxxxx  xx.xx
    80,000     xxxxx  xx.xx      xxxxx  xx.xx      xxxxx  xx.xx        xxxxx  xx.xx
    90,000     xxxxx  xx.xx      xxxxx  xx.xx      xxxxx  xx.xx        xxxxx  xx.xx
   100,000     xxxxx  xx.xx      xxxxx  xx.xx      xxxxx  xx.xx        xxxxx  xx.xx

Each row in the output represents a summary of analysis of a large group of hands. The first row summarizes 10,000 hands, while the last row summarizes 100,000 hands. Within each row, for each of the kinds of poker hands (pair, 2 pair, flush, high card), there are two columns in the output. The first column is the raw count of the number of the hands that matched that kind of hand; the second column is the percentage of the hands that match. For example, if 25,000 of 50,000 hands dealt are pair hands, the pairs columns would be 25000 and 50.00.

Some notes on the output format:

You must have a I can run to start your program. You can (and should) have other python files, but is what I'll run.

Let's look in a bit more detail at the requirements:

Model a deck of cards

You can model a deck of cards with a list of strings, where each string represents a single card. One possible representation is to use the first part of the string to represent the rank of the card, and the last part of the string to represent the suit of the card. You can use a single character for the suit, so it's easy to determine which part of the string represents the rank and which the suit.

You should have functions that create a deck of cards, shuffle a deck of cards, and deal from a deck of cards. A deck of cards is 52 cards, with ranks Ace through King and four suits: Clubs, Diamonds, Hearts, Spades. Note: Aces are more valuable than all other ranks.

Create poker hands

A poker hand can be a list of cards (i.e. a list of the same kinds of strings your deck list has).

You should have functions to add cards to a hand.

Count the hand kinds

You'll need to repeatedly use the above-mentioned functions to create a deck, shuffle it, and deal hands. Once you have hands, you'll need to determine if they match the different hand kinds.

Some guidance

Turn it in

Turn in the project by compressing the project folder and emailing it to me. Be sure you have the honor code pledge written at the top of each python source file.

Please remember to name your project folder using your last name (like CassProject1) when you create it. This will make it easier for me to grade your project.