Search code examples
c++containerspoker

Coding a logical sub pot system for texas holdem poker


Edit It seems like I am getting different responses on how the game actual works, and after reading the official rules, and talking to numerous poker buddies, I guess I don't know the rules myself. Any clarification would be appreciated.

I am working on a little poker game in MSVC++ 2010 Express, and have been stuck trying to come up with a way to code the sub pot system. For some reason I can not get my head around how it should work, and was wondering if SO could post some ways to go about it. Here is a particular situation that can, and more than likely will occur in a texas holdem poker game.

Situation:

Player A has first action with $50 chips and decides to go all in. Player B raises to $150. Player C has only $70s worth of chips and decides to go all in. Player D only has $20 and goes all in. Now, how can I devise a sub pot mechanism to track all these.

From what I understand, what would happen would be:

Player A creates the main pot with $50. You combine B and C's $50s to make the main pot $150. You then take Player B's leftover $100 and split it into $80 and $20. You then make a sub pot for Player B and C worth $40 (Player C's leftover from the $70), and then you give back Player B's $80 sine no one can cover it. Player D's $20 bet goes into Player B, and Cs $40 sub pot, now worth $60. *(or does this not get added? Does it not get added to any bet since it cant cover the main pot of $50, if so then they dont get added to anything *

Now, when it goes down to evaluate. If Player A wins he wins the $150 from Player A, B and C. Next, Player B, C, and D go at it with their sub-pot worth $60.

If Player B wins, he wins everything.

If Player C wins, he wins the $150 from Player A, B, and C. He then challenges Player B, and D for the $60.

Player D can only win the $60, whereas, someone would have already won the Player A, B, and C pot when it goes down this far. (depends if this gets added or not to B, and C's pot, since it doesn't cover the main 50$ bet)

Is this how everything should work? I am having a hard time trying to figure out how I can track each bet, and sub-pot. Any ideas, or logical ways to implement it would help a lot. Thank you for your time. :-)

I was thinking about having each bet being a unique id, or maybe each round has an id, and add each bet to an array to be evaluated that also points to container with player information. I also have to take into consideration that some players might be in sub pots and also be in hand already and fold, which means, I have to track that too.


Solution

  • In this example both main and side pots are calculated wrong.

    RULE: The ruling principle is that each player matches as much of the opponents' bets as he has left in his stack.

    Calculation:

    1) First, we consider a player with the smallest stack (who went all in). In the current example this is a player D with $20.

    2) Next we sum up $20 from each player (A,B,C,D) and the main pot is formed equal to $80, it is contested by all players.

    3) Players' chips left A – $30, B – $130, C – $50, D – $0

    4) Next we consider the second smallest stack, in the current example this is player A who has $30 left. The side pot1 is formed equal to $30(A) + $30(B) +$30(C)= $90. Player D can't win this side pot as he ran out of money.

    5) Players' chips left A – $0, B – $100, C – $20

    6) The side pot2 is formed equal to $20(B) + $20(C)= $40. Player A can't win this side pot as he ran out of money.

    7) Player B has $80 left, this amount is returned to him.

    So we finally get:

    Main pot = $80, contested by all players A,B,C,D

    Side pot1 = $90, contested by A,B,C

    Side pot2 = $40, contested by B,C

    $80 returns to player B