Hi I am developing a poker application and I am having some trouble distributing side pots.
The main issue is that I don't know how to distribute chips of players who have folded(dead chips).
Now my code does the following:
- Get the minimum bet of the all-in players.
- Multiply it by the number of players who have bet more than that amount.
- Give the pot to the winner(s) between the players who have bet more than the amount.
- Substract the all-in bet to the following side pots.
- Repeat number 1 until there are no more pots to distribute.
This is working when all players go all-in, but if one folds things get tricky.
For instance:
A bet(200).
B all-in (80).
C all-in (400).
A folds.
B wins the hand.
So the first pot will be B(80) + C(80) and the remaining will be given to C.
A: +0.
B: +80.
C: +520.
Clearly doing something wrong here as B has the right to fight for 80 chips that A has bet.
This code should handle all situations, and it handles distributing chips to folded players. I'm guessing your code has been completed for a LONG time, but I wasn't able to find code examples on StackOverflow that made sense when I was working on this poker side pot problem, so I'm sharing my own...
Based on your example, I get this result:
if you have any questions let me know.
Here's the fiddle, so scenarios can be tested: https://dotnetfiddle.net/P0wgR5