Thread: Breaking a up a tie in stud poker

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    228

    Breaking a up a tie in stud poker

    So I have a functioning program that simulates stud poker. The only problem is that ranks players by their hand and doesn't check if multiple players have the ranks. Now inevitably, there are situations where you can get a tie. For example if two players have flush and the same cards but with different suits, then the players would split the pot.This means I wont be able to eliminate them all unless I take in consideration their suit but you dont really do that in stud poker.

    To start off, the players cards are already sorted. Now at first I thought that all I had to was compare the highest card from their deck but that won't work. Take these two sets of cards where both have one pair.

    5 5 7 8 9

    2 2 4 7 14 <--- Ace

    Going by that logic the second set of cards should win because the first highest card is an ace compared to the 9 but the first set of cards has the higher pair. So this approach wont work.

    My next approach was to compare their pairs, and then their highest card, next highest card etc. The problem is that I don't know where the pair, two pair etc starts. I know that the highest card is at the end of the hand because I sorted it, but how can I know where the pair, two pair etc starts?

    Once I've dealt with figures out how to deal with pair, two pairs, three of a kind, dealing with straights and flushes should be no problem.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    You need to store some extra information about each hand.

    So for example, when you have a pair, you need to also record that 5 and 2 are the respective values of the pairs.

    https://en.wikipedia.org/wiki/List_of_poker_hands
    There are 9 kinds of hands.

    9 Straight flush
    8 Four of a kind
    7 Full house
    6 Flush
    5 Straight
    4 Three of a kind
    3 Two pair
    2 One pair
    1 High card

    With some bit manipulation magic, you could do the following (for the examples listed on the wiki page)
    0x090B0000 is a Straight flush, where the high card in the flush is a jack.
    0x08060000 is Four of a kind, where the 6 is the card you have 4 of
    0x07050D00 is a Full house, where you have three 5's and 2 kings
    0x060B0000 is a Flush, where the jack is the high card in the flush
    And so on.

    > 5 5 7 8 9
    > 2 2 4 7 14 <--- Ace
    0x02050000 represents the first hand (a pair, with the 5 card being the pair)
    vs.
    0x02020000 represents the second hand (a pair, with the 2 card being the pair)

    Having done all this, simple numeric comparison will identify the winning hand, and resolve the next level tie-breakers based on the value of pairs etc.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    228
    Ok that makes sense. Then if their pairs, two pairs etc still give me a tie. Then I could start checking their first highest card, then second etc.

  4. #4
    Registered User
    Join Date
    Dec 2015
    Posts
    68
    I was thinking that maybe you should create a bit to that represent a value and then OR them and then check final result.
    Code:
    array[16]={0,BIT0+BITE, BIT1, BIT2,BIT3,BIT4,BIT5,BIT6,BIT7,BIT8,BIT9,BITA,BITB,BITC,BITD,BIT0+BITE}; // card value zero is dummy byte
    
    unsigned int checkstraight= array[card[0]] | array[card[1]] | array[card[2]] | array[card[3]] | array[card[4]];
    if (checkstraight == 0x200F || checkstraight == 0x3E || checkstraight == 0x7C || checkstraight == 0xF8 || checkstraight == 0x1F0.....
    It would be easy to find what players have the highest straight as checkstraights value will be higher with a higher top card, should ace not count as high card when it's a 1?
    As you don't have card value with 1, maybe put a dummy zero in that array spot too.
    And instead of comparing with every value up to 0x3E00 maybe a function that returns 1 if it find 5 countinues bits.
    This bit-pattern test should also be usefully with other hands recognitions.
    Last edited by tonyp12; 03-10-2016 at 12:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-08-2012, 09:32 PM
  2. Breaking out of a loop
    By theitsmith in forum C Programming
    Replies: 3
    Last Post: 02-09-2012, 12:30 PM
  3. Breaking out of a loop
    By kiros88 in forum C Programming
    Replies: 5
    Last Post: 09-01-2009, 11:49 AM
  4. Designing a program to deal out seven card stud poker hands
    By killsthehorse in forum C++ Programming
    Replies: 29
    Last Post: 12-08-2008, 04:03 PM
  5. breaking out of program
    By sworc66 in forum C Programming
    Replies: 4
    Last Post: 11-02-2003, 12:38 AM