Poker game good algorithm for solving ties between two pairs

sshou14

New Member
This is the Poker problem in one of previous year's final. See question here
I attempted most questions in the problem and have attached my worksheets, and here's my question:
Does anyone have any good idea how to best solve ties between two pairs?
8C 8D 7S 5S 5C
9C 8S 8H 5H 5D

Here's my idea:
step 1: rank the five cards (solved in part 1)
step 2: Since there're two pairs in five cards, there must be a pair in the first three cards, and another pair in the last three cards. We can use the Mode function to find the two pairs
step 3: if both pairs are equal, we can just do a high card rank for all the cards in order to break ties.

What do you think is the best way to do it?
 

edopts

New Member
Hi sshoul14,
Was puzzling over this one for some time. You can't just find the high card if both pairs are equal because the high card could be part of one of the pairs. You have to find the one that isn't a pair or the one that occurs least frequently and rank them. I assume during your sorting process you separated the numbers and suits. For me, this was in row 9. I found this on another site but it worked great to find the single card for player 1.

=INDEX($D$9:$H$9, MATCH(MIN(INDEX(COUNTIF($D$9:$H$9,$D$9:$H$9),0)), INDEX(COUNTIF($D$9:$H$9,$D$9:$H$9), 0),0))

Use the same format for player 2 and then rank them. I hate really long formulas so I made a little table for high pair/low pair/single for each player using Mode as you suggested in step 2 and the above for the single.
Once I found that line it was easy.
 

Peter_SSs

MrExcel MVP, Moderator
You can't just find the high card if both pairs are equal because the high card could be part of one of the pairs. You have to find the one that isn't a pair or the one that occurs least frequently and rank them.
Welcome to the MrExcel board!

The blue part is right. The red part might work but I don't agree with the underlined part.

I'm guessing to some extent but I don't think sshou14 was suggesting "just find the high card". Considering the particular example shown and given it is already established that there are two equal pairs then I think the underlined part below meant:

Hand1: 8+8+7+5+5=33
Hand2: 9+8+8+5+5=35
Hand2 wins

Does anyone have any good idea how to best solve ties between two pairs?
8C 8D 7S 5S 5C
9C 8S 8H 5H 5D

Here's my idea:
step 1: rank the five cards (solved in part 1)
step 2: Since there're two pairs in five cards, there must be a pair in the first three cards, and another pair in the last three cards. We can use the Mode function to find the two pairs
step 3: if both pairs are equal, we can just do a high card rank for all the cards in order to break ties.
 

edopts

New Member
Peter,
Well that is much less complicated and works equally well. Just out of curiosity though, I think my method might be necessary to determine tie breaks for a full house since the total could be vastly different. The problem assigns a value of 14 to an ace. Therefore, a full house of AA222 is beaten by 44333 but the first hand would total 34 while the second hand only totals 17.
I believe I have solved the problem, so I am just interested if you would have a different method of solving that tie break.
Thanks,
Ed
 

Peter_SSs

MrExcel MVP, Moderator
I think my method might be necessary to determine tie breaks for a full house ..
As far as my knowledge of poker hands goes it is not possible to get a tie with two full house hands so a tie breaker would be unnecessary.
 

edopts

New Member
Ah, true. its part of the steps of the original problem.
First you identify each player's hand. If both players have the same hand, (a full house, straight, 2 pair, etc), then you have to determine which is better. My use of the words "tie breaks" was the verbiage used in the problem and not necessarily in the context of poker.
 

TimHeng

New Member
Hi edopts, Peter,

Actually, the blue part highlighted is incorrect, in the context that shhou14 was using it, I think. The high card rule should work its way down both hands, see that both high cards tie, and move to the next highest card. This is required to solve one of the other parts of the problem, to break ties when there are no hand combinations available.

So if we had two hands with the following cards, we should have the following results:

H1 : 8, 8, 7, 5, 5
H2 : 8, 8, 5, 5, 4
Win: T, T, 1, -, -

... thus identifying that Hand 1 is the winner.

sshou14, your approach is basically the way that we solved the 'two pairs' problem in the official Corality Worked Solution, except we took a different approach to determining the value of the two pairs, rather than using the MODE function as you have.
 

toidayma

New Member
In the case there are 2 pairs, after solving step 1, the higher pair is the 2nd card and the lower pair is the 4th card.
If both pairs are equal, we can just do a high card rank for all the cards in order to break ties.

For ranking high card, since all the card are ranked then you can find the winner by comparing the two sums: Sum1 of player1 = Card1*10^4 + Card2*10^3 +Card3*10^2 +Card4*10 + Card5. Similar for Player2.
If sum1 = sum2 then it's a tie, if sum1 > sum 2 then player 1 wins.


 

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Macro to copy values across rows and transposing them and add the user id
    [FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Hi,[/COLOR][/SIZE][/FONT] [FONT=Times New...
Top