Next: About this document ...
Up: Assignment 11: Arrays of
Previous: Shuffling and sorting
Let's say that you are given a small array of cards. Say
it contains five cards. Say it's called hand.
- 1.
- Write a method called drawHand that takes an
array of Cards as a parameter and that returns a new
array of Cards that contains (references to) just the
first five cards in the deck. Here is what the state
diagram for this method should look like:
figure=subdeck2.eps,height=1.5in
- 2.
- Use shuffleDeck and drawHand to generate
and print four random poker hands. Did you get anything
good?
- 3.
- Now imagine that you want to generate random hands
and check, automatically, if you have a good hand. In case
you don't play poker, here is what I mean by a good hand
(in increasing order of value):
- 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
Write a method called isFlush that takes a hand (array
of cards) and that returns a boolean indicating whether the
hand contains a flush.
- 4.
- Write a method called isThreeKind that takes a hand
and returns a boolean indicating whether the hand contains
Three of a Kind.
The following part of the assignment is optional, but fun:
- 5.
- Write a loop that generates a few thousand hands and
checks whether they contain a flush or three of a kind.
Estimate the probability of getting one of those hands.
Next: About this document ...
Up: Assignment 11: Arrays of
Previous: Shuffling and sorting
Allen Downey
1999-11-16