using System.Collections.Generic;
public ulong potCommitment;
public uint handStrength;
public ulong chipsRemaining;
public bool folded = false;
public Player(ulong pc, uint hs, ulong chipsBehind, bool isFolded): this(pc, hs, chipsBehind)
public Player(ulong pc, uint hs, ulong chipsBehind)
chipsRemaining = chipsBehind;
public static List<Player> winners = new List<Player>();
public static List<Player> players = new List<Player>();
public static void Main()
players.Add(new Player(210, 342, 0));
players.Add(new Player(170, 342, 0));
players.Add(new Player(460, 341, 0));
players.Add(new Player(10, 341, 0));
players.Add(new Player(180, 170, 0));
players.Add(new Player(130, 171, 0));
players.Add(new Player(820, 340, 0));
players.Add(new Player(10, 169, 0, true));
players.Add(new Player(10, 169, 0, true));
players.Add(new Player(10, 169, 0, true));
while (PotChipsRemaining(players) > 0)
PayOutWinners(CalculateAndSortWinners(players), players);
foreach (var player in players)
player.chipsRemaining += player.potCommitment;
player.potCommitment = 0;
Console.WriteLine($"***********************\nFinal results:");
PotChipsRemaining(players);
public static List<Player> CalculateAndSortWinners(List<Player> playersInHand)
foreach (var player in players) if (player.potCommitment > 0 && !player.folded)
if (player.handStrength > highHand)
highHand = player.handStrength;
else if (player.handStrength == highHand)
winners.Sort((x, y) => x.potCommitment.CompareTo(y.potCommitment));
public static void PayOutWinners(List<Player> winners, List<Player> playersInHand)
ulong currentCommitment, collectionAmount;
List<Player> paidWinners = new List<Player>();
foreach (var playerPot in winners)
currentCommitment = playerPot.potCommitment;
foreach (var player in playersInHand) if (player.potCommitment > 0)
collectionAmount = Math.Min(currentCommitment, player.potCommitment);
player.potCommitment -= collectionAmount;
collectedSidePot += collectionAmount;
foreach (var player in winners) if (paidWinners.IndexOf(player) == -1) winnersToPay++;
Console.WriteLine($"collectedSidePot: {collectedSidePot} winnersToPay: {winnersToPay}");
foreach (var player in winners) if (paidWinners.IndexOf(player) == -1)
player.chipsRemaining += collectedSidePot / (ulong)winnersToPay;
if (player.potCommitment <= 0)
Console.WriteLine($"Player {players.IndexOf(player)} fully paid out ({player.chipsRemaining}).");
public static ulong PotChipsRemaining(List<Player> playersInHand)
foreach (var player in playersInHand) if (!player.folded)
Console.WriteLine($"Player {players.IndexOf(player)} chips: {player.chipsRemaining} Commitment: {player.potCommitment} \tHandStrength: {player.handStrength}\tFolded: {player.folded}");
tally += player.potCommitment;
foreach (var player in playersInHand) if (player.folded)
Console.WriteLine($"Player {players.IndexOf(player)} chips: {player.chipsRemaining} Commitment: {player.potCommitment} \tHandStrength: {player.handStrength}\tFolded: {player.folded}");