Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hand shape frequencies
#1
OK, so I've written a few things for analytic purposes, one of which is a random hand dealer.  One of the analytic tools checks the hand shape...what are the suit lengths?  So, 5-5-5-5, 6-5-5-4, etc.  I then ran 2.5 million deals, or 10M total hands, and checked the hand shapes.

On the dealing methodology:  I dealt the first hand as the first 20 cards, next hand was next 20, etc.  If the dealing is truly random, then it doesn't matter if you do it like this, or 1, 4, or 5 cards per hand at a time.  Note that this DOES matter when dealing by hand, because it's not completely random.  The RNG is a fast Mersenne Twister implementation:

 * <h3>MersenneTwister and MersenneTwisterFast</h3>
 * <p><b>Version 13</b>, based on version MT199937(99/10/29)
 * of the Mersenne Twister algorithm found at 
 * <a href="http://www.math.keio.ac.jp/matumoto/emt.html">
 * The Mersenne Twister Home Page</a>, with the initialization
 * improved using the new 2002/1/26 initialization algorithm
 * By Sean Luke, October 2004.

 * <h3>About the Mersenne Twister</h3>
 * <p>This is a Java version of the C-program for MT19937: Integer version.
 * The MT19937 algorithm was created by Makoto Matsumoto and Takuji Nishimura,
 * who ask: "When you use this, send an email to: matumoto@math.keio.ac.jp
 * with an appropriate reference to your work".  Indicate that this
 * is a translation of their algorithm into Java.

In the table below, the first column is the shape;  the 4 numbers add up to 20.  Those are *hexadecimal* numbers, so a=10, b=11, etc.  The second column is the percentage that pattern is dealt. to 2 digits.  I cut this report off at 0.1%;  it *did* report a single 15 card suit, and one 11-9 hand (!).

6554 15.33
7643 11.28
7544 9.57
6653 9.01
8543 7.32
7553 7.20
7652 6.01
6644 5.98
8642 3.06
8633 2.15
8552 1.94
7742 1.87
5555 1.65
9542 1.63
8444 1.62
9443 1.52
8732 1.43
7733 1.33
6662 1.25
9533 1.15
8651 1.02
9632 0.96
7661 0.79
8741 0.64
7751 0.64
9641 0.43
a532 0.42
a433 0.40
a442 0.28
9551 0.27
9731 0.20
a541 0.19
9722 0.16
8831 0.12
b432 0.12
a631 0.11
8750 0.10
8822 0.10

These look correct.  5-5-5-5 is actually unlikely because there's only 1 way it can happen;  6-5-5-4 is much more likely because there are 12 separate ways to deal 6-5-5-4 (6S 4H, 6S 4D, 6S 4C, 6H 4S, 6H 4D, etc.), and each specific 6-5-5-4 is only a little less likely than 5-5-5-5.  And the numbers bear that out.

So I think these numbers are good...at least within statistical error, and with the sample size, that should be minimal.  (Plus I'm not reporting down to the very low-frequency cases like that 11-9.)  And on one very *simple* case, the 5-5-5-5 case, it is correct.  The test run generated 1.645%;  the theoretical is 1.634%.  The difference is sampling error, and that's a perfectly acceptable sample error.  (5-5-5-5 is  20c5 ^4 / 80c20.  This one's easy. Smile  )

But if anyone sees a possible error, let me know.  I'm gonna go through a couple more combinatorial checks with some of these shapes, to check the predicted versus the sampled, and therefore, the randomness of the dealing.  (That's ONE check, not the last one.)
Reply
#2
OK, ran some verification.

The probability of a specific shape...say, 7 hearts, 5 spades, 5 diamonds, and 3 clubs...is simple. Let H = number of hearts, C = number of clubs, etc. where C+H+S+D = 20. This can be dealt in

20cD * 20cH * 20cS * 20cC

possible ways.

Then, count the number of different ways any shape can be dealt. For 7-6-4-3, it's 24. For 7-5-5-3, it's 12...any of 4 for the 7 card suit, any of 3 for the 3 card suit...but then the other 2 suits lengths are defined. For 5-5-5-5, it's *1*.

So, multiply that count by the number of ways from above. That is the total number of ways a given shape can be dealt.

There are 80c20 total possible hands. So divide THAT number, by 80c20, and you get the frequency that hand shape should be dealt.

So, I checked 6-5-5-4, 7-6-4-3, 7-5-4-4, and 6-6-5-3...the 4 most common cases. The numbers agreed to about 0.01%...and that's statistical error.

So I'm pretty happy.
Reply
#3
OK, so I got the complete code for determining the frequency of every hand shape *exactly*.

First method lists all possible shapes.  It always goes in descending length, so the longest suit is listed first, the second longest next, etc.  This is useful for counting the number of ways that shape can happen.
Code:
public static void shapes() {
   int l;
   for (int i=20; i>=5; i--) {
       int t1 = 20 - i;
       int f1;
       if (t1 % 3 > 0)
           f1 = t1/3 + 1;
       else
           f1 = t1/3;
       for (int j=Math.min(i,  20-i); j>= f1; j--) {
           int t2 = 20 - (i+j);
           int f2;
           if (t2 % 2 > 0)
               f2 = t2/2 + 1;
           else
               f2 = t2/2;
           for (int k=Math.min(j, 20-(i+j)); k>=f2; k--) {
               l = 20 - (i+j+k);
               System.out.println(i + "-" + j + "-" + k + "-" + l + "       " + prob(i,j,k,l));
           }
       }
   }
}



Then here's the number of ways that any shape can occur.  The method above ensures that i>= j >= k >= l
Code:
private static int numWays(int i, int j, int k, int l) {
    int result = 0;
    if (i == j && i == k && i == l)
        result = 1;
    else if (i == j && k == l)
        result = 6;
    else if (i == j && i == k)
        result = 4;
    else if (i == j)
       result = 12;
   else if (j == k && j == l)
       result = 4;
   else if (j == k || k == l)
       result = 12;
   else
       result = 24;
   return result;
}


Now here's the probability computation:
Code:
public static double prob(int i, int j, int k, int l) {
   double d1 = Comb.combOp(20, i);
   double d2 = Comb.combOp(20, j);
   double d3 = Comb.combOp(20, k);
   double d4 = Comb.combOp(20, l);
   double d5 = Comb.combOp(80, 20);
   return ((double) numWays(i,j,k,l) * d1 * d2 * d3 * d4 / d5);
}


combOp is the number of combinations of r objects from a set of size n, noted generally as C(n,r) or numerically as e.g. 20c7 (or 20C7).  This is 
Code:
n! / ( (n-r) ! * r!)


This actually simplifies mathematically very nicely into this:
Code:
public static double combOp(int m, int n) {
   double c = 1.0;
   if (m<0 || n<0 || m<=n)
       c = 1.0;
   else {
       for (int loop=1; loop <=n;  loop++) {
           c *= (double) (m-loop+1) / (double) (loop);
       }
   }
   return c;
}


Here is the COMPLETE output, shape first, probability next:

20-0-0-0       1.1314405385813831E-18
19-1-0-0       1.35772864629766E-15
18-2-0-0       1.2253501032836385E-13
18-1-1-0       2.579684427965554E-13
17-3-0-0       4.411260371821098E-12
17-2-1-0       2.940840247880732E-11
17-1-1-1       1.0318737711862215E-11
16-4-0-0       7.967839046601858E-11
16-3-1-0       7.499142632095866E-10
16-2-2-0       5.936821250409227E-10
16-2-1-1       1.2498571053493108E-9
15-5-0-0       8.159067183720304E-10
15-4-1-0       1.0198833979650378E-8
15-3-2-0       2.2797393601571433E-8
15-3-1-1       2.399725642270677E-8
15-2-2-1       3.799565600261906E-8
14-6-0-0       5.099416989825189E-9
14-5-1-0       8.159067183720303E-8
14-4-2-0       2.422223070166965E-7
14-4-1-1       2.5497084949125944E-7
14-3-3-0       1.7098045201178576E-7
14-3-2-1       1.1398696800785716E-6
14-2-2-2       3.007989433540675E-7
13-7-0-0       2.0397667959300757E-8
13-6-1-0       4.079533591860151E-7
13-5-2-0       1.5502227649068576E-6
13-5-1-1       1.6318134367440604E-6
13-4-3-0       2.9066676842003577E-6
13-4-2-1       9.68889228066786E-6
13-3-3-1       6.83921808047143E-6
13-3-2-2       1.082876196074643E-5
12-8-0-0       5.386259195502856E-8
12-7-1-0       1.325848417354549E-6
12-6-2-0       6.2977799824341074E-6
12-6-1-1       6.629242086772744E-6
12-5-3-0       1.511467195784186E-5
12-5-2-1       5.038223985947286E-5
12-4-4-0       1.0037086847004359E-5
12-4-3-1       9.446669973651161E-5
12-4-2-2       7.478613729140502E-5
12-3-3-2       1.0558042911727768E-4
11-9-0-0       9.575571903116187E-8
11-8-1-0       2.872671570934856E-6
11-7-2-0       1.679407995315762E-5
11-7-1-1       1.767797889806065E-5
11-6-3-0       5.038223985947286E-5
11-6-2-1       1.679407995315762E-4
11-5-4-0       8.564980776110386E-5
11-5-3-1       4.030579188757829E-4
11-5-2-2       3.190875191099948E-4
11-4-4-1       2.6765564925344956E-4
11-4-3-2       0.0011965781966624804
11-3-3-3       2.8154781097940716E-4
10-10-0-0       5.793221001385294E-8
10-9-1-0       4.213251637371122E-6
10-8-2-0       3.0019417916269243E-5
10-8-1-1       3.159938728028342E-5
10-7-3-0       1.1084092769084029E-4
10-7-2-1       3.6946975896946766E-4
10-6-4-0       2.355369713430356E-4
10-6-3-1       0.0011084092769084028
10-6-2-2       8.774906775524857E-4
10-5-5-0       1.507436616595428E-4
10-5-4-1       0.0018842957707442848
10-5-3-2       0.004211955252251931
10-4-4-2       0.002797001534698548
10-4-3-3       0.003948708048986185
9-9-2-0       1.8193586615920753E-5
9-9-1-1       1.915114380623237E-5
9-8-3-0       1.6374227954328677E-4
9-8-2-1       5.458075984776225E-4
9-7-4-0       4.2824903880551925E-4
9-7-3-1       0.002015289594378914
9-7-2-2       0.0015954375955499736
9-6-5-0       6.851984620888308E-4
9-6-4-1       0.004282490388055192
9-6-3-2       0.009572625573299841
9-5-5-1       0.002740793848355323
9-5-4-2       0.016273463474609732
9-5-3-3       0.01148715068795981
9-4-4-3       0.015256372007446622
8-8-4-0       2.609642580221133E-4
8-8-3-1       0.0012280670965746508
8-8-2-2       9.722197847882652E-4
8-7-5-0       0.0010277976931332461
8-7-4-1       0.006423735582082788
8-7-3-2       0.014358938359949763
8-6-6-0       6.423735582082789E-4
8-6-5-1       0.010277976931332462
8-6-4-2       0.030512744014893244
8-6-3-3       0.021538407539924642
8-5-5-2       0.01952815616953168
8-5-4-3       0.07323058563574379
8-4-4-4       0.016209895257912037
7-7-6-0       7.906136101024971E-4
7-7-5-1       0.006324908880819977
7-7-4-2       0.018777073239934303
7-7-3-3       0.013254404639953627
7-6-6-1       0.00790613610102497
7-6-5-2       0.06008663436778978
7-6-4-3       0.11266243943960583
7-5-5-3       0.07210396124134773
7-5-4-4       0.09576307352366495
6-6-6-2       0.01251804882662287
6-6-5-3       0.09012995155168467
6-6-4-4       0.059851920952290597
6-5-5-4       0.15322091763786394
5-5-5-5       0.01634356454803882


Finally, I copied this into my spreadsheet, resorted it by frequency, then compared the top 35.  They all matched up with a maximum deviation between predicted and observed of about 0.015%.

Nice thing is, this means I trust both parts.  Smile  

EDIT:  STUPID BOARD SOFTWARE is killing whitespace chars....<sigh>  sorry if the code's less than well formatted.

[mickmackusa edited to wrap all codes with MyBB Code tags and preserve the whitespaces/tabs]
Reply
#4
Bravo for making this. My friends and I were playing a game the other day when someone had a 9 9 1 1 hand and we were curious how common it was. Now we know! We did some light calculations and had it at somewhere between 1 out of every 100,000 and 1,000,000, but it's good to know it's about as common as a 13-3-2-2. The mathematics in pinochle has always been the most interesting part of the game to me.
Reply
#5
Of note: if you were playing live at the table, then a deal may NOT be random. Do you shuffle enough? I believe you need 7 shuffles for an 80 card deck. Do you shuffle fairly well? Used to play at work over lunch, and some people don't. They leave big clumps of cards in groups, so the non-uncommon 12 consecutive cards in a suit don't always get adequately broken up. Still, that was a RARE hand. Smile
Reply
#6
Some short-suit frequencies. These are computed.

Probability of a void: 0.47%
a singleton*: 4.6%
a doubleton*: 19.4%

* -- with no *shorter* suit. There can be multiples...so 10-6-2-2 counts for a doubleton, but 10-7-2-1 doesn't, it counts for a singleton.
Reply
#7
This is great information.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)