In this project our goal will be to determine the odds that a given two-card hand is the best at the table, given a particular five cards on the table and some specified number of opponents. Because the complexity of the problem will increase with the number of opponents, we will take different approaches for different numbers.
But we first need to build some infrastructure. Each two-card hand combines
with the two cards on the table to make a seven-card hand, from which we pick
the best available five-card poker hand. The basic compareTo()
method used in our simulations will thus compare two seven-card sets to see
which yields the better five-card hand.
We need to fix the definitions of some basic objects. Following some of
the drafts this week, we'll let a card be an int
from 0 through
51, with the suit of card c given by c%4
and the rank given by
c/4
(this requires A=0, 2=1, 3=2,..., and K=12, but we can write
the toString()
method to describe hands in the familiar way.
We'll make a Hand5
a five-card hand, so that its main data
element will be an int[5]
array. Similarly a Hand7
will be a seven-card hand. We need compareTo()
methods for both.
A good first task is to write these methods, and test them by cycling
through all seven-card hands and counting the ones of each poker rank -- this
is essentially Problem 6.6.4 (f) in the text. Use the code from Project 1
to generate all Set
objects with n=52 and k=7, then use your new
methods to classify the resulting Hand7
based on the best
Hand5
it contains. The Set
objects will always have
their cards in order, but your methods should work to evaluate and compare
hands whether or not they are in order. (You may assume, though, that a hand
does not contain more than one copy of the same card -- it must be in effect
a Perm
.)
Remember the rules for comparing two five-card hands of the same poker rank, which are outlined here at Wikipedia. Two five-card hands are tied if they contain the same set of five cards, and so two seven-card hands are tied if their best five-card subsets are identical.
Once we get this working, we'll move on to the more general simulation.
Last modified 19 February 2008