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.