0

As there are 52 cards in a deck we know there are 52 choose 2 = 1326 distinct matchups, however in preflop poker this can be bucketed into 169 different hands such as AK offsuit and AK suited as whether it is A hearts K hearts or A spade K spades it makes no difference preflop. My question is, is there a nice mathematical property in which I can uniquely index each of these 169 hands (from 0 to 168 preferably). I am trying to create a look up table as a double[][] = new double [169][169] but have no way of changing a hand representation such as AKs (an Ace and a King of the same suit) to a unique index in this array.

Aly
  • 15,865
  • 47
  • 119
  • 191
  • 2
    If your lookup table is going to be comparing two different starting hands against each other, note that suits *do* matter - for example, the odds of `KhQh` vs `AsTc` are different from `KhQh` vs `AhTc`, even though both are `KQs` vs `ATo`. – caf Mar 19 '10 at 00:37

2 Answers2

2
  1. If the cards are of the same suit, sort the two cards, so that the lower card comes first. If they are of different suits, sort the two cards so that the lower card comes last. A special case will be reserved for when the cards are of the same rank and suit.
  2. Assign each rank a value from 0 to 12 and use a base-13 counting system. The highest value in this system is 12*13 + 12 = 168.
  3. Finally, for cases where both cards are of the same rank and suit, take the value of the rank and add 169 to it. These cases will be in the range 169-181.

Maybe my math is wrong, but I come up with 182 distinct pairs of cards. I'm no expert in the game, so maybe I'm missing something.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
Ben Hocking
  • 7,790
  • 5
  • 37
  • 52
  • Sounds pretty correct and we shall never have 2 of the same card (as only one of each card exist in a standard deck) – Aly Mar 16 '10 at 00:01
  • 1
    Let 0-9 represent 0-9, A=10, B=11, and C=12. Those are our digits. In base-13, you could have B3, which would be converted to decimal as B (i.e., 11) times 13 + 3, or 146. Does that make sense? – Ben Hocking Mar 16 '10 at 00:07
  • Oh, and your answer about not having two of the same card seems obvious now that you explained it. :)' (I could play innocent and claim I was assuming multiple decks, but I just wasn't thinking it through at all.) – Ben Hocking Mar 16 '10 at 00:08
  • My pleasure. It was a fun little exercise. – Ben Hocking Mar 16 '10 at 00:15
  • Two cards of the same rank and suit? That's not possible unless you're playing with multiple decks. – Nick Johnson Sep 30 '10 at 09:37
0

Yes.

An example of a ready made Objective-C (and Java) Texas Hold'em 7- and 5-card evaluator can be found here and further explained here. It "adds" up hands to generate an index that sufficiently characterises the hand for determining rank.

All feedback welcome at the e-mail address found therein.

Ken
  • 30,811
  • 34
  • 116
  • 155