By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Poker hand evaluation

P: n/a
Hi all.

I am creating a program which calculates poker odds. The program should
look at the visible cards (those on your hand and those on the table)
then count the cards needed to improve the hand(eg. how many cards do I
need to get a Flush) and then calculate the odds based on those
numbers. My problem is that I do not know how I should find the missing
cards.

One way I could do it is to use programming logic like this
(pseudo-code):

/* Find cards needed for a pair */
for x in "each visible card":
for y in "each non-visible card":
if(x.rank == y.rank):
/* We can use y to make a pair, count it */
cardsNeeded << y

But this can get very complicated and error prone (test cases is most
certainly needed) in the longrun.

Another way to do it would be to create a list of all possible hands
and then search through that. But a quick calculation tells me there
are 133 million (just above 1 trillion, if placement counts) different
combinations in a game of Hold 'Em, thats a fairly large list to carry
around.

Which one would you suggest? Have i missed other possibilities?

Dec 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Martin Olsen wrote:
Hi all.

I am creating a program which calculates poker odds. The program should
look at the visible cards (those on your hand and those on the table)
then count the cards needed to improve the hand(eg. how many cards do I
need to get a Flush) and then calculate the odds based on those
numbers. My problem is that I do not know how I should find the missing
cards.

One way I could do it is to use programming logic like this
(pseudo-code):

/* Find cards needed for a pair */
for x in "each visible card":
for y in "each non-visible card":
if(x.rank == y.rank):
/* We can use y to make a pair, count it */
cardsNeeded << y

But this can get very complicated and error prone (test cases is most
certainly needed) in the longrun.

Another way to do it would be to create a list of all possible hands
and then search through that. But a quick calculation tells me there
are 133 million (just above 1 trillion, if placement counts) different
combinations in a game of Hold 'Em, thats a fairly large list to carry
around.
Perhaps there is further symmetry in this list that you could
exploit to reduce the its size? For example does permuting card
suits around make any difference? I don't know the rules to
"Hold 'Em", just guessing. If you can permute suits, then I
believe this list could shrink 4!=24 times. 5.5 million is
not much then.

Also, with a list you are paying extra memory cost for the
links between list elements. Perhaps a vector or deque would
be better here, or perhaps you don't literally mean a (std::)list?

HTH,
- J.
Dec 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.