|
|
Count ALL combinations in Poker Holdem dealing process
Last post 12-22-2008, 2:47 PM by waltham. 8 replies.
-
11-23-2008, 9:40 AM |
-
SunKidDance
-
-
-
Joined on 11-24-2008
-
-
Posts 4
-
-
|
Count ALL combinations in Poker Holdem dealing process
Hello, I'm trying to count all two card combinations at a ten player holdem table: - Pairs 22,. 33, ..., AA (13 combinations in total)
- Non-suited combinations 23o, ..., AKo (78 combinations in total)
- Suited combinations 23s,..., AKs (78 combinations in total)
I wrote a program to sample the dealing process: NAME 1,52 deuce_s trey_s four_s five_s six_s seven_s eight_s nine_s ten_s jack_s queen_s king_s ace_s deuce_c trey_c four_c five_c six_c seven_c eight_c nine_c ten_c jack_c queen_c king_c ace_c deuce_d trey_d four_d five_d six_d seven_d eight_d nine_d ten_d jack_d queen_d king_d ace_d deuce_h trey_h four_h five_h six_h seven_h eight_h nine_h ten_h jack_h queen_h king_h ace_hCOPY deuce_s trey_s four_s five_s six_s seven_s eight_s nine_s ten_s jack_s queen_s king_s ace_s deuce_c trey_c four_c five_c six_c seven_c eight_c nine_c ten_c jack_c queen_c king_c ace_c deuce_d trey_d four_d five_d six_d seven_d eight_d nine_d ten_d jack_d queen_d king_d ace_d deuce_h trey_h four_h five_h six_h seven_h eight_h nine_h ten_h jack_h queen_h king_h ace_h deckNAME 10 numberOfTrialsREPEAT numberOfTrials SHUFFLE deck shuffledDeck'Dealing cards TAKE shuffledDeck (1 11) Player1 TAKE shuffledDeck (2 12) Player2 TAKE shuffledDeck (3 13) Player3 TAKE shuffledDeck (4 14) Player4 TAKE shuffledDeck (5 15) Player5 TAKE shuffledDeck (6 16) Player6 TAKE shuffledDeck (7 17) Player7 TAKE shuffledDeck (8 18) Player8 TAKE shuffledDeck (9 19) Player9 TAKE shuffledDeck (10 20) Player10ENDBut here is the problem How can I count ALL 169 combinations without composing an IF ELSIF ESLE smonster with 169 branches (and a bunch of sub-branches because, for example, Ac,7c and 7c,Ac are the same combination)? Any suggestions are greatly appreciated. Thanks&Regards SunKidDance
|
|
-
11-25-2008, 8:26 AM |
-
Random Walker
-
-
-
Joined on 05-15-2006
-
-
Posts 45
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
SunKidDance,
I'm not sure exactly what you're trying to do. (I don't know the game, just googled it to get a brief idea.) But one way to ensure that the order of two lists is not considered, is to sort both lists before comparing:
NEWCMD COMPARE list1 list2 result SORT list1 list1Sorted SORT list2 list2Sorted SUMABSDEV list1Sorted list2Sorted result END
'Example usage of the above subroutine: COMPARE player1 (king_s ace_s) result
If the result of the compare is zero, then the two lists are equal. If the result is non-zero, then the lists are unequal.
Since you say there are 169 combinations, which is 13^2, it must be the case that the cards' suits don't matter. But your definition of the deck has each card identified with its suit. This makes it harder to compare because, for example, a jack_h should equal a jack_c if we are disregarding their suits. Therefore, comparing by name won't work. So you need to compare by value. And, since the card values are also unique (jack_c = 23, jack_h = 49), their values need to be converted to 1 through 13.
Here are two subroutines, one that converts a pair into a "pairNumber", and one that does the reverse. Because both incorporate a sort, they ignore the order of the pair. They both also ignore the suit of the cards. You can convert the contents of a hand like "player1" to a pair number. If two hands have the same pair number, then they both have the same value of cards.
'Converts the first two elements (cards) of pair into a number representing the 'values of the cards in that pair without regard to the order of the two elements 'or their suits. The pair vector may contain named numbers such as deuce_s, trey_s, etc. NEWCMD GETPAIRNUMBER pair pairNumber @poker ?"Converts a pair to a pairNumber" LET pairValues = (pair - 1) % 13 + 1 'convert named cards to values between 1 and 13 SORT pairValues sortedPair TAKE sortedPair 1 firstCard TAKE sortedPair 2 secondCard LET pairNumber = (firstCard - 1)*13 + secondCard END
'Converts the number of a pair (between 1 and 169) to a pair of values 'between 1 and 13 that represent two cards without regard to their suit. 'The lower number will always be the first element in pair NEWCMD GETPAIR pairNumber pair @poker ?"Converts a pair number to two card values between 1 and 13" LET firstCard = integer((pairNumber - 1) / 13) + 1 LET secondCard = (pairNumber - 1) % 13 + 1 COPY firstCard secondCard pair SORT pair pair END
By the way, the long COPY command at the top of your program can be simplified to this: COPY deuce_s,ace_h deck
Regards,
John
|
|
-
11-28-2008, 12:08 PM |
-
SunKidDance
-
-
-
Joined on 11-24-2008
-
-
Posts 4
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
Hi John,
thanks four your answer, that's exactly what I was looking for. I will incorporate your subroutines in my program and the counting will start soon ;-) .
Again, thanks for your precise answer right on target.
Regards,
SunKidDance
|
|
-
11-28-2008, 5:33 PM |
-
Random Walker
-
-
-
Joined on 05-15-2006
-
-
Posts 45
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
SunKidDance,
You're welcome. One more point, though. If it is true that you don't need to distinguish suits anywhere in your program, then you can simplify the program using the following line instead of your first NAME command:
COPY 4#1,13 deck
which refers only to the values. Or, probably more helpful, change it to this, which uses names for the card values and still doesn't involve suits:
NAME 1,13 deuce trey four five six seven eight nine ten jack queen king ace COPY 4#deuce,ace deck
Now, you can get by with just the COMPARE subroutine. You probably don't need the other two since they were only needed to strip off the "suit" information.
John
|
|
-
11-29-2008, 6:58 AM |
-
SunKidDance
-
-
-
Joined on 11-24-2008
-
-
Posts 4
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
Hi RandomWalker,
unfortunately suit does matter. There are 78 combinations which are off-suited ("o") and 78 combinations which are suited ("s") given a two card Holdem hand (card rank first hand <> card rank second hand) and 13 combinations (pairs) with equal card rank.
Your subroutines are great but don't account for the "suitedness" of the cards. Sorry I didn't get this yesterday. Maybe you have an idea for this case also?
Thanks & Regards,
/SunKidDance
|
|
-
11-29-2008, 1:53 PM |
-
Random Walker
-
-
-
Joined on 05-15-2006
-
-
Posts 45
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
SunKidDance,
Here's a pair of subroutines that converts between pairNumbers and card names. They now take into account the values and suits of the cards. Also, I added a conversion in the GETPAIR subroutine that will give back the card names instead of just numbers as in the earlier subroutines. That required adding "deck" as an input to the GETPAIR routine.
'Converts the first two elements (cards) of pair into a number representing the 'values and suits of the cards in that pair without regard to the order of the two elements. 'The pair vector may contain named numbers such as deuce_s, trey_s, etc. 'The card values must be between 1 and 52 inclusive. 'Input: ' pair: a vector containing two numbers between 1 and 52 representing a specific card. Order doesn't matter. 'Output: ' pairNumber: a single number representing the pair. NEWCMD GETPAIRNUMBER pair pairNumber @poker ?"Converts a pair to a pairNumber. Suits and values are distinguished. Order is not." SORT pair sortedPair TAKE sortedPair 1 firstCard TAKE sortedPair 2 secondCard LET pairNumber = (firstCard - 1)*52 + secondCard END
'Converts a pair number (created by GETPAIRNUMBER) to the corresponding pair of named numbers 'from the list of named numbers, "deck". 'The lower number will always be the first element in pair. 'Inputs: ' deck: the list of named numbers representing the card deck, in order, created by a NAME command. ' pairNumber: a single number representing the pair. 'Output: ' pair: a vector containing two named numbers, each between 1 and 52 representing a specific card. NEWCMD GETPAIR deck pairNumber pair @poker ?"Converts a pair number to two named card values" LET secondCard = (pairNumber - 1) % 52 + 1 LET firstCard = integer((pairNumber - 1)/52) + 1 TAKE deck firstCard firstCard 'convert back to a named number TAKE deck secondCard secondCard 'convert back to a named number COPY firstCard secondCard pair SORT pair pair END
I hope these work for you.
John
|
|
-
12-01-2008, 10:46 AM |
-
SunKidDance
-
-
-
Joined on 11-24-2008
-
-
Posts 4
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
Hi Random Walker,
not exactly. I'd like to count all suited combinations, for example {Ac2c,Ad2d,As2s,Ah2h} should yield one pair number. Likewise all unsuited combinations of A2, i.e. Ac2d, should yield another pair number. Every poker pair, i.e.AA, should yield a different pair number (one number per pair).
Regards,
/SunKidDance
P.S.: Thanks again for your support.
|
|
-
12-01-2008, 9:50 PM |
-
Random Walker
-
-
-
Joined on 05-15-2006
-
-
Posts 45
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
Looks like I'm shooting in the dark, but here's my next shot. The primary subroutines I would expect you to use would be GETCATEGORY and GETPAIRNUMBER. The other two are support for these two. Hope this does it:
'Define constants to be used by subroutines and main program NAME (0 1) false true NAME valuesMatch suitsMatch neitherMatch GLOBAL false true valuesMatch suitsMatch neitherMatch
'Returns true if values of pair match regardless of suit. 'Returns false if values of pair do not match. NEWCMD VALUEMATCH pair result TAKE pair 1 card1 TAKE pair 2 card2 LET val1 = card1%13 LET val2 = card2%13 COPY false result IF val1 = val2 COPY true result END END
'Returns true if suits of pair match regardless of value. 'Returns false if suits of pair do not match. NEWCMD SUITMATCH pair result COPY false result TAKE pair 1 card1 TAKE pair 2 card2 IF card1 <= 13 AND card2 <= 13 OR \ card1 between 14 26 AND card2 between 14 26 OR \ card1 between 27 39 AND card2 between 27 39 OR \ card1 between 40 52 AND card2 between 40 52 COPY true result END END
'Computes a unique number for each pair depending on whether 'their values match, or their suits match but values differ, or 'neither match. The numbers generated are not consecutive and 'can't be used to regenerate the pair from just the pair number. 'The numbers were chosen so that the ranges of the three categories 'do not overlap. NEWCMD GETPAIRNUMBER pair pairNumber SORT pair sortedPair VALUEMATCH pair isValueMatch SUITMATCH pair isSuitMatch TAKE sortedPair 1 card1 TAKE sortedPair 2 card2 LET n1 = (card1 - 1) % 13 + 1 LET n2 = (card2 - 1) % 13 + 1 LET pairNumber = n1 * 13 + n2 'range 14 to 182 Values equal IF isValueMatch <> true IF isSuitMatch = true LET pairNumber = pairNumber*15 'range 210 to 2730 Suits Match, values differ ELSE LET pairNumber = pairNumber*200 'range 2800 to 36400 Neither match END END END
'Computes which category the given pairNumber belongs in. 'The possible categories are: valuesMatch suitsMatch neitherMatch (defined above). NEWCMD GETCATEGORY pairNumber category IF pairNumber between 14 182 COPY valuesMatch category ELSEIF pairNumber between 210 2730 COPY suitsMatch category ELSE COPY neitherMatch category END END
NAME 1,52 deuce_s trey_s four_s five_s six_s seven_s eight_s nine_s ten_s jack_s queen_s king_s ace_s deuce_c trey_c four_c five_c six_c seven_c eight_c nine_c ten_c jack_c queen_c king_c ace_c deuce_d trey_d four_d five_d six_d seven_d eight_d nine_d ten_d jack_d queen_d king_d ace_d deuce_h trey_h four_h five_h six_h seven_h eight_h nine_h ten_h jack_h queen_h king_h ace_h
COPY deuce_s,ace_h deck
'Test program. Generates every combination of two cards. 'Prints out each pair with its category and pair number. 'At the end, it prints the number of pairs it found in each category. COPY 0 valuesMatchCount COPY 0 suitsMatchCount COPY 0 neitherMatchCount FOREACH card1 deck FOREACH card2 deck COPY card1 card2 pair GETPAIRNUMBER pair n GETCATEGORY n category IF category = valuesMatch ADD 1 valuesMatchCount valuesMatchCount ELSEIF category = suitsMatch ADD 1 suitsMatchCount suitsMatchCount ELSE ADD 1 neitherMatchCount neitherMatchCount END PRINT pair category n END END PRINT valuesMatchCount suitsMatchCount neitherMatchCount
|
|
-
12-22-2008, 2:47 PM |
-
waltham
-
-
-
Joined on 12-22-2008
-
-
Posts 2
-
-
|
Re: Count ALL combinations in Poker Holdem dealing process
Are You just trying to find out how many two card combinations are possible? it's 1326.
(52x51)/2
|
|
|
|