473,806 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to get more precise number (Poker Hands Generator)

7 New Member
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%
Four Of A Kind : 0.017 % In theory : 0.0240%
Full House : 0.1535 % In theory : 0.1441%
Flush : 0.2285 % In theory : 0.1967%
Straight : 0.3104 % In theory : 0.3532%
Three Of A Kind : 2.2372 % In theory : 2.1128%
Deux Pairs : 4.6104 % In theory : 4.759%
Pair : 41.777 % In theory : 42.2569%
Nothing : 50.6648 % In theory : 50.157%

There is big differences between my results and the theory. I thought at first that it was because I didn't used enough hands.

This is my results with 50 million hands:



Number of hands generated : 50000000
Straight Flush : 0.0012 % In theory : 0.0012%
Four Of A Kind : 0.0183 % In theory : 0.0240%
Full House : 0.1489 % In theory : 0.1441%
Flush : 0.2286 % In theory : 0.1967%
Straight : 0.3086 % In theory : 0.3532%
Three Of A Kind : 2.2266 % In theory : 2.1128%
Deux Pairs : 4.6107 % In theory : 4.759%
Pair : 41.7652 % In theory : 42.2569%
Nothing : 50.6918 % In theory : 50.1570%

And again, the numbers are pretty much the same so it means that thereare flaws in my logic. The problem is I can't find those flaws. My question will be about my isFourOfAKind() method because I get approximalety 20% less Four Of A Kind hands then the theory. A pretty good difference in my opinion.

In general, my program is built like this

Card --> suit, strenght.
Hand --> Card1, Card2, Card3, Card4, Card5.

This is a representation of my method (Card1 = the strenght of Card1. In reality Card1 would be replace by Card1.getCardSt renght())

if(Card1 == Card2 && Card1 == Card3 && Card1 == Card4 && Card1 != Card5)
return true
else if(Card1 == Card2 && Card1 == Card3 && Card1 != Card4 && Card1 == Card5)
return true
if(Card1 == Card2 && Card1 != Card3 && Card1 == Card4 && Card1 == Card5)
return true
if(Card1 != Card2 && Card1 == Card3 && Card1 == Card4 && Card1 == Card5)
return true
else
return false

I'm pretty sure this logic is good. The problem is my results tells me that my logic is NOT good. Where is the flaw in that method?

Thanks in advance and pardon me for English mistakes...it isn't my first language

kinghippo423

P.S. I saw lots of poker hands generator like mice that works WAY faster than mine. Is there any website that explain some technics to have a "faster" program? It sucks to wait 1 minute ot generate 1 million hands...I hope I explain that well.
Sep 4 '07
13 2562
kinghippo423
7 New Member
And here comes the fun: use regular expressions for finding the score:
Four of a kind is found as follows:

Expand|Select|Wrap|Line Numbers
  1. boolean fook= r.matches("0*40*");
  2.  
A full house is found like this:
Expand|Select|Wrap|Line Numbers
  1. boolean fh= r.matches("0*20*30*") || r.matches("0*30*20*");
  2.  
Checking whether or not all cards have the same suit is easy too:

Expand|Select|Wrap|Line Numbers
  1. boolean ss= s.matches("0*40*");
  2.  
I hope you get the picture.

kind regards,

Jos
I was unterstanding up to this point perfectly. I just want to make use I get it before asking for more explanation.

Let's say my hand is:

Hand (suit - strenght):
Card1 : 2 - 4.
Card1 : 2 - 6.
Card1 : 2 - 8.
Card1 : 2 - 9.
Card1 :2 - 11.

For checking if my hand is a flush, my method should look ike this:

// ss = result of the checking.
// s = the concatenation of the hand information.
isFlush(Card card)
{
boolean result;
if(boolean ss= s.matches("0*0* 0*0*0*");
result = true;
else if(boolean ss= s.matches("1*1* 1*1*1*");
result = true;
else if(boolean ss= s.matches("2*2* 2*2*2*");
result = true;
else if(boolean ss= s.matches("3*3* 3*3*3*");
result = true;
else
result = false;

return result;
}

I'm getting it?

If yes, why it's a better way to built the program?
If not, I'll need more specification on the use here of the regular expressions. I'M almost there though it's just still a little fuzzy...
Sep 5 '07 #11
JosAH
11,448 Recognized Expert MVP
I was unterstanding up to this point perfectly. I just want to make use I get it before asking for more explanation.

Let's say my hand is:

Hand (suit - strenght):
Card1 : 2 - 4.
Card1 : 2 - 6.
Card1 : 2 - 8.
Card1 : 2 - 9.
Card1 :2 - 11.

For checking if my hand is a flush, my method should look ike this:

// ss = result of the checking.
// s = the concatenation of the hand information.
isFlush(Card card)
{
boolean result;
if(boolean ss= s.matches("0*0* 0*0*0*");
result = true;
else if(boolean ss= s.matches("1*1* 1*1*1*");
result = true;
else if(boolean ss= s.matches("2*2* 2*2*2*");
result = true;
else if(boolean ss= s.matches("3*3* 3*3*3*");
result = true;
else
result = false;

return result;
}

I'm getting it?

If yes, why it's a better way to built the program?
If not, I'll need more specification on the use here of the regular expressions. I'M almost there though it's just still a little fuzzy...
You must read up on regular expressions. A flush means the cards all have the
same suit, so the suits string matches this: "0*50*" which translates to human
language as zero or more '0's followed by a '5' followed by zero or more '0's.

This regular expresssion matches "5000", "0500", "0050" or "0005". That's the
fun of those regular expressions: let them do the hard work so your code can
be extremely simple.

kind regards,

Jos
Sep 5 '07 #12
Nepomuk
3,112 Recognized Expert Specialist
You must read up on regular expressions. A flush means the cards all have the
same suit, so the suits string matches this: "0*50*" which translates to human
language as zero or more '0's followed by a '5' followed by zero or more '0's.

This regular expresssion matches "5000", "0500", "0050" or "0005". That's the
fun of those regular expressions: let them do the hard work so your code can
be extremely simple.

kind regards,

Jos
Actually, "0*" could mean one zeros, multiple zeros or no zeros. Therefore the Expression "0*50*" would match "5000" or "0005". What you said was, that "0*" meant zero or more multiple zeros, leaving out the possibility of the empty word.

Greetings,
Nepomuk
Sep 5 '07 #13
JosAH
11,448 Recognized Expert MVP
Actually, "0*" could mean one zeros, multiple zeros or no zeros. Therefore the Expression "0*50*" would match "5000" or "0005". What you said was, that "0*" meant zero or more multiple zeros, leaving out the possibility of the empty word.

Greetings,
Nepomuk
Nope, "0*" just means zero or more '0's. So the expression matches all the
combinations 5000, 0500, 0050, 0005; give it a try.

kind regards,

Jos
Sep 5 '07 #14

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

Similar topics

4
3423
by: james blair | last post by:
Hi I am generating a random number using random.randint(1,10000000000) Whats the possibility that the numbers generated will be same when generated by 100 users at the same time? Whats the best method to generate random numbers so that they are most likely unique?? Thanks
70
6291
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
7
3650
by: A. L. | last post by:
Consider following code segment: #1: double pi = 3.141592653589; #2: printf("%lf\n", pi); #3: printf("%1.12lf\n", pi); #4: printf("%1.15lf\n", pi); The above code outputs as following: 3.141593
5
3355
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
1
4488
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 find the missing cards. One way I could do it is to use programming logic like this
27
5633
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
8919
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
9
4691
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
20
5140
by: A | last post by:
Hi all. Is this a bug or what??? here is a simple code: <?php mt_srand(1); echo mt_rand(0, 255)."<br />"; echo mt_rand(0, 255)."<br />";
0
9719
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
10618
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
10366
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
10371
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
10110
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...
1
7649
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4329
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
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.