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.
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,zto 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:For example, for the board
A,3,3,2,A, starting at the front, theAis assignedw. Then the3can either be assignedworx. Ifw, then the next3must bex, and ifx, then the next3must bey. The2can be any suit at most one higher than the ones already assigned, except if the3s arexandyit can’t bey(because that’s equivalent tox), and the same for theAexcept it can’t bewagain and it can beyifxhas been assigned to the2(because then it’s no longer equivalent). That yields a total of $14$ possibilities: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.)