private void CalculateEvDiffByPot(EquityPot pot, HandHistory handHistory, List <int> winnersBySeat) { if (winnersBySeat.Count == 0) { LogProvider.Log.Error($"Could not find a winner of pot #{pot.Index} hand #{handHistory.HandId}"); return; } foreach (var player in pot.Players) { if (!pot.PlayersPutInPot.ContainsKey(player)) { continue; } var netWonPerWinner = (pot.Pot - pot.Rake) / winnersBySeat.Count - pot.PlayersPutInPot[player]; var ev = (pot.Pot - pot.Rake) * player.Equity[pot.Index] - pot.PlayersPutInPot[player]; if (winnersBySeat.Contains(player.Seat)) { player.EvDiff += ev - netWonPerWinner; continue; } player.EvDiff += ev + pot.PlayersPutInPot[player]; } }
/// <summary> /// Builds pot of the specified players /// </summary> /// <param name="equityPlayersWentAllIn">All-in players</param> /// <param name="equityPlayers">Players</param> /// <param name="potIndex">Index of pot</param> /// <returns>Pot of the specified players or null if there is no all-in players</returns> private EquityPot BuildPot(IEnumerable <EquityPlayer> equityPlayersWentAllIn, IEnumerable <EquityPlayer> equityPlayers, int potIndex) { if (equityPlayersWentAllIn.IsNullOrEmpty()) { return(null); } var eligibleEquityPlayers = equityPlayers.Where(x => x.PutInPot > 0).ToList(); if (eligibleEquityPlayers.Count < 2) { return(null); } var equityAllInPlayer = equityPlayersWentAllIn.First(); var pot = new EquityPot { Index = potIndex++, Street = equityAllInPlayer.LastAction.Street }; var allInPlayerPutInPot = equityAllInPlayer.PutInPot; foreach (var equityPlayer in eligibleEquityPlayers) { var putInThisPot = 0m; if (equityPlayer.PutInPot < allInPlayerPutInPot) { pot.Pot += equityPlayer.PutInPot; putInThisPot = equityPlayer.PutInPot; equityPlayer.PutInPot = 0; } else { pot.Pot += allInPlayerPutInPot; putInThisPot = allInPlayerPutInPot; equityPlayer.PutInPot -= allInPlayerPutInPot; } if (equityPlayer.PutInPot != 0 || !equityPlayer.LastAction.IsFold) { pot.Players.Add(equityPlayer); } pot.PlayersPutInPot.Add(equityPlayer, putInThisPot); } return(pot); }
/// <summary> /// Calculates EV Diff for the players involved into the specified pots /// </summary> /// <param name="pot">Pots to calculate EV diff</param> /// <param name="handHistory">Hand history</param> /// <param name="gameType">Type of game</param> private void CalculateEvDiff(EquityPot pot, HandHistory handHistory, GeneralGameTypeEnum gameType) { if (pot.Players .Where(x => x.HoleCards != null) .Count() < 2) { return; } var pokerEvaluator = ServiceLocator.Current.GetInstance <IPokerEvaluator>(gameType.ToString()); pokerEvaluator.SetCardsOnTable(handHistory.CommunityCards); pot.Players .Where(x => x.HoleCards != null) .ForEach(x => pokerEvaluator.SetPlayerCards(x.Seat, x.HoleCards)); var winners = pokerEvaluator.GetWinners(); if (winners.Lo == null || winners.Lo.IsNullOrEmpty()) { CalculateEvDiffByPot(pot, handHistory, winners.Hi.ToList()); return; } var splitPot = new EquityPot { Index = pot.Index, Players = pot.Players, PlayersPutInPot = pot.PlayersPutInPot, Pot = pot.Pot / 2, Rake = pot.Rake / 2, Street = pot.Street }; CalculateEvDiffByPot(splitPot, handHistory, winners.Hi.ToList()); CalculateEvDiffByPot(splitPot, handHistory, winners.Lo.ToList()); }