Next: What to turn in
Up: Assignment 2: Object Methods
Previous: Object methods
The following are the possible hands in poker in increasing order
of rank (and decreasing order of probability):
- pair:
- two cards with the same rank
- two pair:
- two pairs of cards with the same rank
- three of a kind:
- three cards with the same rank
- straight:
- five cards with ranks in sequence
- flush:
- five cards with the same suit
- full house:
- three cards with one rank, two cards with another
- four of a kind:
- four cards with the same rank
- straight flush:
- five cards in sequence and with the same suit
Chapter 3 of the book
explains the notion of a histogram. You
might want to review that material before continuing.
- Write methods named isPair, isTwoPair, etc. that
take a Deck as an argument and that return a boolean indicating
whether or not the hand meets the relevant criteria. Your code
should work correctly for ``hands'' that contain any number of cards
(although 5 and 7 are by far the most common sizes).
Something to think about is whether a hand that contains three of a
kind should be considered to contain a pair as well.
- Write a loop that shuffles a deck of cards, divides it into
hands, classifies the hands, and counts the number of times various
classifications appear.
- Print a table of the classifications and their probabilities.
Run your program with larger and larger numbers of hands until the
output values converge to a reasonable degree of accuracy. You
might want to express the results in a form like ``A straight
flush occurs 1 time out of 123456789 hands.''
Allen Downey
Mon Sep 18 10:06:29 EDT 2000