473,614 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Poker hand evaluation

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
1 4471
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
13261
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in any order; it’s not necessarily the case that the highest card will appear first, for example. Your program will then determine whether the hand is valid, and...
27
5594
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample Python program is given in the discussion page for doing it that way. I wanted to take a different approach and actually generate all the possible hands, counting the number of each type. It's quite do-able on today's hardware, with 5-card...
4
8901
by: hardieca | last post by:
Has anyone heard of an open-source .NET engine that calculates the winning and losing percentages of hands? Regards, Chris
15
6465
by: sandy123456 | last post by:
At the moment im trying to write a hand class for a game poker patientnce But when i get to the part having to catergorise the difference of full house straight flush flush four of a kind and straight i got stuck.I need to write boolean methods to return these (stright flush , four of a kind..etc) I can only do a pair and 2 pairs and three of a kind. The following is my code please someone if possible help me thanks import java.util.*; ...
54
3909
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of parentheses. 1) "The order of evaluation of subexpressions is determined by the precedence and grouping of operators."
13
2543
by: kinghippo423 | last post by:
Hello Everyone, I did a poker program in Java that essencially finds the strenght of a poker hand created Randomly. My program is doing OK...but I'm pretty sure it can be optimised. This is my results with 1 million hands: Number of hands generated : 1000000 Straight Flush : 0.0012 % In theory : 0.0012%
24
7056
by: bnashenas1984 | last post by:
Hi every one I'm trying to make a little poker game but I don't know how to evaluate the strength of a 7 card hand.. It's not that hard with 5 cards. Actually I found some program to do that with 5 cards but the problem is that there is 5 flop cards and 2 cards that the player has in hand. I don't even know how to start that .... (identify cards by numbers? 1 to 52) or (identify them by both numbers and suits) Any suggestion will be...
9
4682
by: teejayem | last post by:
I am looking for some help! I am currently developing a new game for an online community. The game is called Pokino which ishalf bingo and half poker. Wierd eh?! Anyway... The final part of the program needs to evaluate two 5 card poker hands and determine which one out of the two hands wins. I thought rather than create a new class of my own I would see if there was anything
7
5663
by: Extremity | last post by:
Hi, I am taking a intro to C++ course so my knowledge base only limits to areas such as if/else, functions, and recursions. We are creating a program which will determine the probability of Poker Hands, such as Royal Flush, Straight Flush, Four of a Kind and such. However in order to complete this, I need to determine how many different poker hands there are. On pencil and paper, this is relatively easy as its a simple combination problem. ...
0
8197
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.