473,583 Members | 3,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Poker Hand Probability

2 New Member
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.

52! / 5! 47!

52 represents the deck, 5 represents the hand, and 47 represent the Deck-Hand. The total amount of poker hands are 2,598960.

The problem is that I cant seem to implement this into my program. I cannot simply pull a random number such as 2,598960 out of thin air. I must prove it within the confines of my program with the use of combinations. Thus far, I have attempted to use a recursion for the numerator and denominator. This is not successful as 50! well exceeds the any type of data type.

In real life, there is a cancellation for simplicity which results to 52x51x50x49x48/5x4x3x2x1. This would be much easier for the program to calculate. However I doubt there is a way for the program to perform cancellations.

In general, I am having a hard time initializing this program simply because I dont know how to force the program to perform such calculations. Any help is appreciated.
Oct 26 '08 #1
7 5658
boxfish
469 Recognized Expert Contributor
In my opinion, it's possible to make a computer program do anything. That's probably not very reassuring. But if you can think of an algorithm for it, you can code it. Your program should be able to preform cancellations. I can think of one way to do this now, although it would not be very efficient. Every time you multiply the result by one of the huge numbers, loop through all the numbers you're dividing it by to see if it's divisible by any of them yet If it is, divide, and then scratch that number from the list. Oh wait... You don't have a list. Has your class covered arrays or vectors yet?
Good luck.
Oct 26 '08 #2
curiously enough
79 New Member
You don't need arrays or anything like that. Cancellations can be done much more easily than you think.

First, I think you already have the recursive function that calculates the factorial of an integer. So you will use this function for the small denominator(whi ch is 5 in your example).

You will have to write another function too, call it cancellation. It should take two parameters. The first one is the large numerator(which is 52 in you example), and the second one is the larger denomenator(whi ch is 47 in your example). This function will be very similar to the factorial function, except for the if statement that is used in the factorial function to stop the recursivity(whi ch is something like: if(n>1)). Instead the if statement should be: if(n>q) (or if(52>47) in your example) and that should stop the recursive multiplication at n-q (at 48 in your example). And remember to change the first parameter only, as the second parameter stays constant throughout the recursivity( meaning you should write:
if(n>q) return(n*cancel lation(n-1,q)) );

And in main all you have to do is divide the return value of cancellation by the return value of factorial(where factorial takes the small denominator as parameter ofcourse).
Oct 26 '08 #3
donbock
2,426 Recognized Expert Top Contributor
The combination is the denominator for the probability. Don't stall out while you're waiting to figure out how to compute that denominator value -- try to compute the numerator values for various poker hands. That is, the number of distinct combinations of cards in your hand that all amount to a particular poker hand. You can manually verify a few of these to see your calculations are correct.
Oct 26 '08 #4
Extremity
2 New Member
Instead of recursion, does anyone know how to implement a factorial/permutation/combination for looping instead?

Such as 52! / 5! 47!

The algorithm seems to be n * (n - 1) * (n - 2) * (n - 3).....and so forth
Oct 26 '08 #5
Laharl
849 Recognized Expert Contributor
Recursion may be the way to go, however, keep in mind that a!/b! = (a*a-1*a-2*...*b+1) if a > b, since a! = a*a-1*a-2*...*1 and b = b*b-1*b-2*...*1.

For example, 5!/3!: (5*4*3*2*1)/(3*2*1) cancels to 5*4.

Implementing this in code is up to you, however.
Oct 26 '08 #6
arnaudk
424 Contributor
As mentioned above, you'll need a function which computes the factorial down to a certain number, perm(n,r) = n!/(n-r)! = n(n-1)(n-2)...(n-(r-1)). This can be achieved with a recursive function call, for example:

< spoonfeeding code deleted >

In this way, a permutation nPr is simply perm(n,r), and a combination or binomial coefficient nCr is perm(n,r)/perm(r,1).
Oct 27 '08 #7
JosAH
11,448 Recognized Expert MVP
You can even go a bit further if you note that a sequence of n adjacent numbers
contains one number that can be divided by n itself. So, e.g. 52C5 = 52!/5!/(52-5)!
== 52*51*50*49*48/1*2*3*4*5 == 48/1*49/2*50/3*51/4*52/5. Note that divisions
are always exact and the intermediate results are always as small as possible.
One single loop can do the job here.

kind regards,

Jos

ps. I ostensibly removed the spoonfeeding code in previous replies; I personally
don't agree with this but I'll continue the discussion about this matter in the
ongoing thread somewhere else. There should be a 'modus operandi' for answering
a question by using a code fragment.
Oct 27 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2068
by: Andreas Schmitt | last post by:
Hi, Sorry for posting in German before, totally forgot about that when I was pasting this in here from another German newsgroup I was writing to, trying to get help I am programming a simple version of a soccer simulation The logic works like this so far: = constant value goals/game
7
13260
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...
1
4470
by: Martin Olsen | last post by:
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...
27
5590
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...
4
8897
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
6457
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...
13
2542
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
7050
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...
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...
0
7815
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...
0
8168
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. ...
0
8187
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...
0
6573
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...
1
5691
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3812
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3837
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1418
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.