Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 12-26-2017, 04:13 PM   #1
statmanhal
Pooh-Bah
 
Join Date: Jan 2009
Posts: 4,156
Dealing pairs routine

Need a software routine, preferably in Visual Basic. Assume N players and each is dealt a pair from a standard deck (N <=5) . Want to output for each rank the number of players that have that pair. Thus, the value for each rank is 0, 1, or 2. There are initially 6 combinations for each rank and that number reduces to 1 if a player is dealt that pair. An output for N=5 might be, 1 player has a 4 pair, 1 a 6 pair, 2 each have a pair of tens, and 1 has aces.
statmanhal is offline   Reply With Quote
Old 12-26-2017, 10:25 PM   #2
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

Are you looking for a simulation? Like the function performs 1 random draw and tells you what the outcome was? Because I think it's not too hard to analytically arrive at the distributions of outcomes, but that doesn't sound like what you want.

I don't know VB but I could probably do it in python, C++ or java.
RustyBrooks is offline   Reply With Quote
Old 12-27-2017, 12:28 AM   #3
statmanhal
Pooh-Bah
 
Join Date: Jan 2009
Posts: 4,156
Re: Dealing pairs routine

Yes, it is for a simulation program. You can easily do it analytically for 1 opponent, and easily approximate it for n>1 but Iím not sure an exact solution for more than 1 opponent is easy.

Anyway, I did develop a routine I think is correct. It involves a dynamically changing vector that relates a random number to a dealt pair. The vector changes as pairs are dealt. I thought a more elegant solution might be available, but since this was for some research I am doing, elegance is not a priority. If you do come up with a python approach, I can probably translate it into VBA.
statmanhal is offline   Reply With Quote
Old 12-27-2017, 02:37 PM   #4
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

For the 5 person game, there are only 26 choose 5 ways to deal the pairs (65,780) - simple enumeration seems like it would work well. I'll take a pass at that.
RustyBrooks is offline   Reply With Quote
Old 12-27-2017, 03:20 PM   #5
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

Actually when I started writing this I realized it is actually not too hard to calculate. First, instead of thinking of it as 6 cards, and you choose 2 and then there are 2 left to make another pair, think of it as a list of numbers from 0 to 26. 0 and 1 and the first pairs, 2 and 3 are the 2nd pairs, and so forth, making 13 pairs.

For a 5 person game, the counts can be
A A / B B / C
A A / B / C / D
A / B / C / D / E
There aren't any other ways it could go.

There are 26c5 total outcomes, so we can count the ways to do particular outcomes to find the probability. For example, the chance for a specific AABBC match, like say
2 pairs of 5s, 2 pairs of 6s, 1 pair of 7s
is 2 / 26c5. This is because we have to draw both of the 5 and 6 pairs, but we get to choose "which" 7 pair we get.

If we want to know the chance of being in a AABBC situation that involves 5, 6 and 7, then that's 6/26c5 because there are 6 ways to arrange A B and C, but AABB is the same as BBAA so there are 3 unique ways

If we want to know the chance that it'll be a AABBC situation in general, then, it's
13c3 * 6 / 26c5 = 286*6 / 65780 = 1716/65780

The other ones yield to similar analysis. For AABCD types, you have
8 ways to make any specific one (because there are 2 choices for B C and D, 2*2*2=8)

There are 32 ways to make an AABCD type that uses, say, 5 6 7 and 8, because although there are 4! ways to arrange the letters, all the combos of BCD are the same, so it's 4!/3!.

So there are 32*13c4 ways to make all AABCD types.

For the ABCDE types, you have 32 ways to pick any particular set of pairs, because each pair has 2 ways and there are 5 of them, 2^5 = 32. So there are 32*13c5 ways to make ABCDE types.

For any "type" the formula is fairly simple, the only thing you have to do manually is figure out which "types" are available given the number of players. The formula is
2^S*RcD*13cR
where
S is the number of single pairs
D is the number of double pairs
R is the number of distinct ranks
I *think* this is right
RustyBrooks is offline   Reply With Quote
Old 12-27-2017, 03:26 PM   #6
Lattimer
I are smart
 
Lattimer's Avatar
 
Join Date: Feb 2009
Location: New England
Posts: 12,570
Re: Dealing pairs routine

I think each player is only dealt 2 cards and it's guaranteed to be a pair.
Lattimer is offline   Reply With Quote
Old 12-27-2017, 04:46 PM   #7
statmanhal
Pooh-Bah
 
Join Date: Jan 2009
Posts: 4,156
Re: Dealing pairs routine

I just got back to this.
Thanks for the response Rusty, I will look at it carefully and get back to you. Lattimerís comment is correct and I think your analysis assumes this.

Actually, the problem Iím dealing with is actually a little more complex. It assumes hero has a set of known rank, so we know hero has a pair and one flop card gives him a set. Iím then interested in the probability of hero losing to a higher set or quads, recognizing hero can also get quads. But, if the thread problem I posed can be analytically solved, it shouldnít be too hard to modify.
statmanhal is offline   Reply With Quote
Old 12-27-2017, 05:12 PM   #8
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

Yeah I know they're guaranteed to get a pair. That's why I said you could just make a "deck" out of 26 items, each item representing a pair.

But that's really very different than your OP. Neither the code nor the analysis are that similar, I think.
RustyBrooks is offline   Reply With Quote
Old 12-27-2017, 06:39 PM   #9
statmanhal
Pooh-Bah
 
Join Date: Jan 2009
Posts: 4,156
Re: Dealing pairs routine

With a fairly quick check, Rusty's approach looks good. Summing his probs for the example gives a total prob of 100%, as it should. I'll now try to modify it to attack the overset problem I'm addressing.

Thanks for your responses guys.
statmanhal is offline   Reply With Quote
Old 12-27-2017, 07:43 PM   #10
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

BTW because the sample size is small, attacking it enumeratively, instead of doing the math, is very feasible. In python, it's actually quite easy, because python has a function that makes all combinations possible from a list. Here's an example:

Code:
#!/usr/bin/env python

from collections import defaultdict
import itertools

sizes = defaultdict(int)
count = 0
for i in itertools.combinations(range(26), 5):
    count += 1
    foo = defaultdict(int)
    for el in i:
        foo[el/2] += 1

    sizes[len(foo)] += 1

print count, sizes
Code:
(otx) lolbutts:~/Code/labs-pulse $ ./pairs2.py
65780 defaultdict(<type 'int'>, {3: 1716, 4: 22880, 5: 41184})
RustyBrooks is offline   Reply With Quote
Old 12-27-2017, 07:46 PM   #11
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

I should say, the reason I'm counting and printing the sizes is that "foo" contains the pairs in this set and how many of each there are. So for example it'll be something like
{2: 1, 5: 1, 7: 1, 10: 2}
meaning 1 pair of 2s, 1 pair of 5s, 1 pair of 7s and 2 pairs of 10s. The length of this dict is 4. Any dict that has a length of 4 must be 3 individual pairs and 1 double-pair.

len(3) = double double single
len(4) = DSSS
len(5) = SSSSS
RustyBrooks is offline   Reply With Quote
Old 12-28-2017, 01:08 PM   #12
statmanhal
Pooh-Bah
 
Join Date: Jan 2009
Posts: 4,156
Re: Dealing pairs routine

Iím having second thoughts about Rustyís initial structure. He postulated 26 pairs, 2 for each for the 13 ranks. For two players, by his method, the probability of two different pairs (AB) equals 96% vs 4% for two same rank pairs (AA). You can get these results by straightforward calculation, e.g.,

P(2 pairs of same rank | 26 possible pairs) = 13*(2/26)*(1/25) = 1/25 = 4%.

In the OP, I postulated each rank had 6 possible pairs, leading to a total of 78. If we use 78 possible pairs as the initial structure,

P(2 pairs of same rank|78 possible pairs) = 13*(6/78)*(1/73) = 1.4%,

a significant difference from Rustyís result.

So, while his calculation algorithm is nice, I think the basic assumption of 26 pairs is not supportable.
statmanhal is offline   Reply With Quote
Old 12-28-2017, 02:11 PM   #13
Lattimer
I are smart
 
Lattimer's Avatar
 
Join Date: Feb 2009
Location: New England
Posts: 12,570
Re: Dealing pairs routine

Quote:
Originally Posted by RustyBrooks View Post
Yeah I know they're guaranteed to get a pair. That's why I said you could just make a "deck" out of 26 items, each item representing a pair.

But that's really very different than your OP. Neither the code nor the analysis are that similar, I think.
I very quickly glanced at your analysis and assumed you were using 5-card hands based on the ABCDE, that's why I made my post. It was an unfortunate coincidence you were giving a 5 player example.
Lattimer is offline   Reply With Quote
Old 12-28-2017, 04:42 PM   #14
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,643
Re: Dealing pairs routine

Yeah, I think you're right, my model doesn't match reality.

I wrote another program, this one takes a normal holdem deck, and deals out every possible pair of holdem hands. If both hands aren't pairs, it throws them out. If they are, it counts them and checks if they're the same pair. It gets the same number as you - 1.36986%

Code:
#!/usr/bin/env python

from collections import defaultdict
import itertools

count = 0
match = 0
deck = [
    '2c', '2h', '2s', '2d',
    '3c', '3h', '3s', '3d',
    '4c', '4h', '4s', '4d',
    '5c', '5h', '5s', '5d',
    '6c', '6h', '6s', '6d',
    '7c', '7h', '7s', '7d',
    '8c', '8h', '8s', '8d',
    '9c', '9h', '9s', '9d',
    'Tc', 'Th', 'Ts', 'Td',
    'Jc', 'Jh', 'Js', 'Jd',
    'Qc', 'Qh', 'Qs', 'Qd',
    'Kc', 'Kh', 'Ks', 'Kd',
    'Ac', 'Ah', 'As', 'Ad',
]

for i in itertools.permutations(deck, 4):
    if i[0][0] != i[1][0] or i[2][0] != i[3][0]:
        continue

    count += 1
    if i[0][0] == i[2][0]:
        match += 1

print match, count, 100.0*match/count
RustyBrooks is offline   Reply With Quote
Old 04-06-2018, 05:46 PM   #15
heehaww
Pooh-Bah
 
heehaww's Avatar
 
Join Date: Aug 2011
Location: Tacooos!!!!
Posts: 4,390
Re: Dealing pairs routine

Quote:
Originally Posted by statmanhal View Post
P(2 pairs of same rank|78 possible pairs) = 13*(6/78)*(1/73) = 1.4%
I like your approach! Here's another.

N(AB) = C(13,2) * C(4,2)^2
N(AA) = 13 * 3

P(AA) = 39 / 2847 = 1.36986301%

For N(AA) you multiply by 3 because all 3 ways to distribute the cards among the two players are valid (in that they all result in the players having pairs). For N(AB) there is only one valid distribution (since I'm treating the players as unlabeled).

For the 5-player case:

N(ABCDE) = C(13,5) * 6^5 = 10007712
N(AABCD) = 4*C(13,4) * 6^3 * 3 = 1853280
N(AABBC) = 3*C(13,3) * 6 * 3^2 = 46332
Total = 11907324

Again the magenta terms are the ways to distribute the cards.
heehaww is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 12:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online