All five-card boards avoiding redundant suit combinations

63 Views Asked by At

I'm looking to narrow a space of all 5-card boards in Texas Hold'em. For context, in Texas Hold'em we have a max of five dealt community cards, where the first three are dealt in one shot, then the fourth and lastly the fifth. Five cards dealt in this way, where the order of the first three cards is irrelevant but it matters which cards were the fourth and fifth, are called a "board". There are

$${52 \choose 3 }\cdot 49\cdot 48$$

such boards, about 52 million.

Now, a bit of notation. In cards we use two characters to represent each card, the first character is the index, and the second is the suit. For example Ah is the Ace of hearts, 5c is the 5 of clubs.

I am looking for an algorithm to create all possible 5-card boards, but removing the redundant suit combination swaps - I consider Ah, Kh, 9d, 5c, 4s the same as As, Ks, 9c, 5d, 4h the same as Ac, Kc, 9d, 5s, 4h and so on, we can consider all of the mas Ax, Kx, 9y, 5z, 4w where x y z and w can be any suit.

Can you help me come up with the most efficient algorithm? The only algo I have now, looking for all the boards and then removing the duplicates, which is not very efficient.

1

There are 1 best solutions below

9
On BEST ANSWER

I’d start by generating all possible “$5$-rank boards”, i.e. all combinations of $5$ ranks with the relevant order distinctions, regardless of suits. You can easily do that by allowing all five cards to be of any rank (that’s $\binom{13+3-1}3=455$ possibilities for the flop and $13$ each for the turn and river, so $455\cdot13\cdot13=76895$ in all) and then removing the $13$ impossible boards with $5$ identical ranks, for a total of $76895-13=76882$ possible $5$-rank boards.

Then you can assign suits w, x, y, z to them as follows. For each $5$-rank board, go through the ranks one by one and to each rank assign all suits allowed under the following rules:

  • The suit must be lower than any equivalent suit, where two suits are equivalent if they’ve been assigned to the same set of ranks in the flop and neither has been assigned to the turn.
  • The suit must be different from any suit assigned to the same rank so far.
  • Within the flop, the suit must be higher than any suit assigned to the same rank so far.

For example, for the board A, 3, 3, 2, A, starting at the front, the A is assigned w. Then the 3 can either be assigned w or x. If w, then the next 3 must be x, and if x, then the next 3 must be y. The 2 can be any suit at most one higher than the ones already assigned, except if the 3s are x and y it can’t be y (because that’s equivalent to x), and the same for the A except it can’t be w again and it can be y if x has been assigned to the 2 (because then it’s no longer equivalent). That yields a total of $14$ possibilities:

Aw, 3w, 3x, 2w, Ax
Aw, 3w, 3x, 2w, Ay
Aw, 3w, 3x, 2x, Ax
Aw, 3w, 3x, 2x, Ay
Aw, 3w, 3x, 2y, Ax
Aw, 3w, 3x, 2y, Ay
Aw, 3w, 3x, 2y, Az
Aw, 3x, 3y, 2w, Ax
Aw, 3x, 3y, 2w, Az
Aw, 3x, 3y, 2x, Ax
Aw, 3x, 3y, 2x, Ay
Aw, 3x, 3y, 2x, Az
Aw, 3x, 3y, 2z, Ax
Aw, 3x, 3y, 2z, Az 

Here’s Java code that performs this algorithm and checks that it results in the same number $2554656$ of inequivalent boards as the inefficient algorithm you described. (In fact I didn’t wait for the inefficient algorithm to complete for $13$ ranks; I checked the validity by performing the comparison for up to $9$ ranks.)