private List <Player> CreateGameGeneralPlayers(HandHistories.Objects.Hand.HandHistory history) { var result = new List <Player>(); seatMap.TryGetValue(history.GameDescription.SeatType.MaxPlayers, out Dictionary <int, int> seats); foreach (var player in history.Players) { var uncalledBet = history.HandActions .Where(a => a.PlayerName == player.PlayerName && a.HandActionType == HandActionType.UNCALLED_BET) .Select(a => a.Amount) .DefaultIfEmpty(0) .Sum(); result.Add( new Player { Name = player.PlayerName, Chips = player.StartingStack, Bet = player.Bet, Win = player.Win + uncalledBet, Seat = seats != null && seats.ContainsKey(player.SeatNumber) ? seats[player.SeatNumber] : player.SeatNumber, Dealer = history.DealerButtonPosition == player.SeatNumber, } ); } return(result); }
internal static IEnumerable <EquityRangeSelectorItemViewModel> GetHeroRange(HandHistories.Objects.Hand.HandHistory currentHandHistory, HandHistories.Objects.Cards.Street currentStreet) { if (currentHandHistory.Hero == null) { return(null); } if (init) { TempConfig.Init(); HandHistory.Init(); Card.Init(); init = false; } var handAnalyzer = new HandAnalyzer(); var handHistory = new HandHistory(); handHistory.ConverToEquityCalculatorFormat(currentHandHistory, currentStreet); var heroRange = handAnalyzer.BuildPlayerRange(handHistory, currentHandHistory.Hero.PlayerName); return(GroupHands(heroRange)); }
private List <Cards> CreateGameRoundsRoundCards(HandHistories.Objects.Hand.HandHistory history, Street street) { var result = new List <Cards>(); if (street == Street.Preflop) { foreach (var player in history.Players) { result.Add( new Cards { Player = player.PlayerName, Type = CardsType.Pocket, Value = CreateGameRoundsRoundCardsTextForPlayer(history, player), } ); } } else if (street >= Street.Flop && street <= Street.River) { result.Add( new Cards { Type = StreetCardsTypeMapping[street], Value = CardsToText(GetCardsDealtOnStreet(history.CommunityCards, street)) } ); } return(result); }
private string GetTotalBuyInString(HandHistories.Objects.Hand.HandHistory history) { var buyIn = history.GameDescription.Tournament.BuyIn.TotalBuyin().ToString(CultureInfo.InvariantCulture); var currency = history.GameDescription.Tournament.BuyIn.GetCurrencySymbol(); return($"{currency}{buyIn}"); }
private string CalculateStrongestOpponent(HandHistories.Objects.Hand.HandHistory CurrentGame, Street CurrentStreet) { try { IEnumerable <EquityRangeSelectorItemViewModel> oponnentHands = new List <EquityRangeSelectorItemViewModel>(); var opponentName = string.Empty; MainAnalyzer.GetStrongestOpponent(CurrentGame, CurrentStreet, out opponentName, out oponnentHands); if (AutoGenerateHandRanges) { if (!string.IsNullOrEmpty(opponentName) && oponnentHands.Any() && PlayersList.Any(x => x.PlayerName == opponentName && x.Cards.All(c => !c.Validate()))) { oponnentHands.ForEach(r => r.UsedCards = _board.Cards); var player = PlayersList.FirstOrDefault(x => x.PlayerName == opponentName); player?.SetRanges(oponnentHands); } } return(opponentName); } catch (Exception ex) { LogProvider.Log.Error(this, "Could not determine the strongest opponent", ex); } return(string.Empty); }
private List <Round> CreateGameRounds(HandHistories.Objects.Hand.HandHistory history) { var result = new List <Round>(); var actionGroups = history.HandActions .Where(a => ValidStreets.Contains(a.Street) && ActionMapping.ContainsKey(a.HandActionType)) .GroupBy(GetRoundNumber) .ToDictionary(g => g.Key, g => g.ToList()); int currentActionNumber = 0; for (Street street = Street.Init; street <= history.CommunityCards.Street; street++) { result.Add( new Round { No = (int)street, Cards = CreateGameRoundsRoundCards(history, street), Actions = CreateGameRoundsRoundActions(history, actionGroups, street, ref currentActionNumber), } ); } return(result); }
private void LoadBoardData(HandHistories.Objects.Hand.HandHistory CurrentGame, int numberOfCards) { if (CurrentGame.CommunityCards.Count() > 5) { throw new ArgumentOutOfRangeException( "CommunityCards", CurrentGame.CommunityCards.Count(), "Can handle no more than 5 cards on a board"); } List <CardModel> boardCardsList = new List <CardModel>(); int length = numberOfCards < CurrentGame.CommunityCards.Count() ? numberOfCards : CurrentGame.CommunityCards.Count(); for (int i = 0; i < length; i++) { boardCardsList.Add(new CardModel() { Rank = new RangeCardRank().StringToRank(CurrentGame.CommunityCards.ElementAt(i).Rank), Suit = new RangeCardSuit().StringToSuit(CurrentGame.CommunityCards.ElementAt(i).Suit) }); } Board.SetCollection(boardCardsList); }
private void LoadPlayersData(HandHistories.Objects.Hand.HandHistory CurrentGame) { PlayersList.Clear(); var players = CurrentGame.Players; for (int i = 0; i < players.Count; i++) { var list = new List <CardModel>(); if (players[i].hasHoleCards) { foreach (var card in players[i].HoleCards) { list.Add(new CardModel() { Rank = new RangeCardRank().StringToRank(card.Rank), Suit = new RangeCardSuit().StringToSuit(card.Suit) }); } } if (i > PlayersList.Count - 1) { PlayersList.Add(new PlayerModel()); } var currentPlayer = PlayersList[i]; currentPlayer.SetCollection(list); currentPlayer.PlayerName = players[i].PlayerName; } }
private string GetBuyInString(HandHistories.Objects.Hand.HandHistory history) { // Most of this code was taken from HandHistories.Objects.GameDescription.Buyin.ToString() // because it's not possible to replace currency symbol using just ToString() method var currency = history.GameDescription.Tournament.BuyIn.GetCurrencySymbol(); var separator = " + "; var format = CultureInfo.InvariantCulture; var prizePoolValue = history.GameDescription.Tournament.BuyIn.PrizePoolValue; var rake = history.GameDescription.Tournament.BuyIn.Rake; var prizePoolString = (prizePoolValue != Math.Round(prizePoolValue)) ? prizePoolValue.ToString("N2", format) : prizePoolValue.ToString("N0", format); var rakeString = (rake != Math.Round(rake)) ? rake.ToString("N2", format) : rake.ToString("N0", format); if (history.GameDescription.Tournament.BuyIn.IsKnockout) { var KnockoutValue = history.GameDescription.Tournament.BuyIn.KnockoutValue; string knockoutString = (KnockoutValue != Math.Round(KnockoutValue)) ? KnockoutValue.ToString("N2", format) : KnockoutValue.ToString("N0", format); return(string.Format("{0}{1}{4}{0}{3}{4}{0}{2}", currency, prizePoolString, rakeString, knockoutString, separator)); } return(string.Format("{0}{1}{3}{0}{2}", currency, prizePoolString, rakeString, separator)); }
private GameGeneral CreateGameGeneral(HandHistories.Objects.Hand.HandHistory history) { var result = new GameGeneral { StartDate = history.DateOfHandUtc, Players = CreateGameGeneralPlayers(history), }; return(result); }
private List <Action> CreateGameRoundsRoundActions(HandHistories.Objects.Hand.HandHistory history, Dictionary <int, List <HandAction> > roundActions, Street street, ref int currentActionNumber) { var result = new List <Action>(); int roundIndex = (int)street; if (!roundActions.ContainsKey(roundIndex)) { return(result); } var investments = history.Players.ToDictionary(p => p.PlayerName, p => 0m); if (street == Street.Preflop) { var actionAmountMapping = new[] { HandActionType.SMALL_BLIND, HandActionType.BIG_BLIND, HandActionType.POSTS, HandActionType.STRADDLE }; var players = history.Players.ToList(); var actions = history.HandActions.Where(a => actionAmountMapping.Contains(a.HandActionType)); actions.ForEach(action => { investments[action.PlayerName] = Math.Abs(action.Amount); }); } foreach (var action in roundActions[roundIndex]) { var amount = Math.Abs(action.Amount); investments[action.PlayerName] += amount; var sum = action.HandActionType == HandActionType.RAISE ? investments[action.PlayerName] : amount; result.Add( new Action { No = currentActionNumber++, Type = ActionMapping[action.HandActionType], Player = action.PlayerName, Sum = sum, } ); } return(result); }
private Game CreateGame(HandHistories.Objects.Hand.HandHistory history) { var result = new Game { GameCode = (ulong)history.HandId, General = CreateGameGeneral(history), Rounds = CreateGameRounds(history), }; return(result); }
private string CreateGameRoundsRoundCardsTextForPlayer(HandHistories.Objects.Hand.HandHistory history, HandHistories.Objects.Players.Player player) { if (player.hasHoleCards) { return(CardsToText(player.HoleCards)); } int totalCards = history.GameDescription.GameType == GameType.PotLimitOmaha ? 4 : 2; return(string.Join(" ", Enumerable.Repeat("X", totalCards))); }
private void LoadData(RequestEquityCalculatorEventArgs obj) { try { ResetAll(null); if (obj.IsEmptyRequest) { IsEquityCalculatorModeEnabled = true; _currentHandHistory = null; IsPreflopVisible = IsFlopVisible = IsTurnVisible = IsRiverVisible = false; CurrentStreet = Street.Null; InitPlayersList(); return; } _currentHandHistory = ServiceLocator.Current.GetInstance <IDataService>().GetGame(obj.GameNumber, obj.PokersiteId); if (_currentHandHistory == null) { return; } SetStreetVisibility(_currentHandHistory); LoadBoardByCurrentStreet(); LoadPlayersData(_currentHandHistory); EquityCalculatorMode = _currentHandHistory.GameDescription.TableType.Contains(HandHistories.Objects.GameDescription.TableTypeDescription.ShortDeck) ? EquityCalculatorMode.HoldemSixPlus : EquityCalculatorMode.Holdem; IsEquityCalculatorModeEnabled = false; var strongestOpponent = CalculateStrongestOpponent(_currentHandHistory, _currentStreet); PlayersList.RemoveAll(x => _currentHandHistory .HandActions.Any(a => (a.HandActionType == HandActionType.FOLD) && (a.PlayerName == x.PlayerName)) && (x.PlayerName != StorageModel.PlayerSelectedItem?.Name) && (x.PlayerName != strongestOpponent)); } catch (ArgumentOutOfRangeException ex) { LogProvider.Log.Error(this, "Board contains more than 5 cards", ex); } catch (Exception ex) { LogProvider.Log.Error(this, "Error during EquityCalculatorViewModel.LoadData()", ex); } }
private General CreateGeneral(HandHistories.Objects.Hand.HandHistory history) { var result = new General { Mode = "real", Chipsin = 0, Chipsout = 0, GameCount = 1, Awardpoints = 0, StatusPoints = 0, Ipoints = 0, IsAsian = "0", StartDate = history.DateOfHandUtc, Duration = "N/A", TableName = history.TableName, Nickname = history.Hero != null ? history.Hero.PlayerName : !string.IsNullOrEmpty(history.HeroName) ? history.HeroName : string.Empty, GameType = GetGameType(history) }; if (history.GameDescription.IsTournament) { history.GameDescription.Tournament.BuyIn.Currency = GetCurrency(history); result.TournamentName = history.GameDescription.Tournament.TournamentName; result.TournamentCurrency = history.GameDescription.Tournament.BuyIn.Currency.ToString(); result.Currency = history.GameDescription.Tournament.BuyIn.Currency; result.BuyIn = GetBuyInString(history); // These two functions add $ currency symbol to buyins with empty currency (Gold, Club Chips, etc.) result.TotalBuyIn = GetTotalBuyInString(history); // Otherwise HM2 will consider it's euros and convert to $ anyway // For some reason HM2 doesn't want to import tournament hand without place // If place is unknown we put number of players involved in the hand there result.Place = history.GameDescription.Tournament.FinishPosition > 0 ? history.GameDescription.Tournament.FinishPosition : history.Players.Count; result.Win = history.GameDescription.Tournament.TotalPrize; } else { history.GameDescription.Limit.Currency = GetCurrency(history); result.Currency = history.GameDescription.Limit.Currency; var blinds = history.GameDescription.Limit.ToString(CultureInfo.InvariantCulture, false, true, "/"); result.GameType = $"{result.GameType} {blinds}"; result.Bets = 0; result.Wins = 0; } return(result); }
internal static void GetStrongestOpponent(HandHistories.Objects.Hand.HandHistory currentHandHistory, HandHistories.Objects.Cards.Street currentStreet, out string strongestOpponentName, out IEnumerable <EquityRangeSelectorItemViewModel> strongestOpponentHands) { strongestOpponentName = null; strongestOpponentHands = new List <EquityRangeSelectorItemViewModel>(); if (init) { TempConfig.Init(); HandHistory.Init(); Card.Init(); init = false; } var handAnalyzer = new HandAnalyzer(); var handHistory = new HandHistory(); handHistory.ConverToEquityCalculatorFormat(currentHandHistory, currentStreet); // analyze preflop ranges var hand_range = handAnalyzer.PreflopAnalysis(handHistory); var hand_collective = new Hashtable(); foreach (string key in hand_range.Keys) { var hand_distribution = new hand_distribution { hand_range = (float)Convert.ToDouble(hand_range[key]) }; hand_collective.Add(key, hand_distribution); } if (currentStreet != HandHistories.Objects.Cards.Street.Preflop) { var street = currentStreet == HandHistories.Objects.Cards.Street.Flop ? 1 : currentStreet == HandHistories.Objects.Cards.Street.Turn ? 2 : 3; hand_collective = handAnalyzer.PostflopAnalysis(handHistory, street, hand_collective); } strongestOpponentHands = GroupHands(handAnalyzer.StrongestOpponentHands); strongestOpponentName = handAnalyzer.StrongestOpponentName; }
public static HandInfoDataContract Map(HandHistories.Objects.Hand.HandHistory hh) { if (hh == null) { throw new ArgumentNullException("hh"); } var handInfo = new HandInfoDataContract(); handInfo.GameNumber = hh.HandId; handInfo.DateUtc = hh.DateOfHandUtc.ToString(); handInfo.PlayerName = hh.Hero?.PlayerName ?? string.Empty; handInfo.HoleCards = (hh.Hero?.hasHoleCards ?? false) ? hh.Hero.HoleCards.ToString() : string.Empty; handInfo.CommunityCards = hh.CommunityCardsString; handInfo.Win = hh.Hero?.Win ?? 0; handInfo.PokerSite = hh.GameDescription.Site.ToString(); return(handInfo); }
public string Convert(HandHistories.Objects.Hand.HandHistory history) { try { var target = new HandHistory { SessionCode = history.GameDescription.Identifier.ToString(), General = CreateGeneral(history), Games = new List <Game> { CreateGame(history) }, }; var handHistoryXml = SerializationHelper.SerializeObject(target, true); return(handHistoryXml); } catch (Exception e) { throw new DHInternalException(new NonLocalizableString("Failed to convert handhistory to IPoker format."), e); } }
private string GetGameType(HandHistories.Objects.Hand.HandHistory history) { switch (history.GameDescription.GameType) { case GameType.NoLimitHoldem: return("Holdem NL"); case GameType.PotLimitOmaha: return("Omaha PL"); case GameType.PotLimitHoldem: return("Holdem PL"); case GameType.NoLimitOmahaHiLo: return("Omaha Hi-Lo NL"); case GameType.PotLimitOmahaHiLo: return("Omaha Hi-Lo PL"); default: return(string.Empty); } }
private void SetStreetVisibility(HandHistories.Objects.Hand.HandHistory CurrentGame) { IsPreflopVisible = CurrentGame != null && CurrentGame.PreFlop != null && CurrentGame.PreFlop.Any(); IsFlopVisible = CurrentGame != null && CurrentGame.Flop != null && CurrentGame.Flop.Any(); IsTurnVisible = CurrentGame != null && CurrentGame.Turn != null && CurrentGame.Turn.Any(); IsRiverVisible = CurrentGame != null && CurrentGame.River != null && CurrentGame.River.Any(); if (IsRiverVisible) { CurrentStreet = Street.River; } else if (IsTurnVisible) { CurrentStreet = Street.Turn; } else if (IsFlopVisible) { CurrentStreet = Street.Flop; } else if (IsPreflopVisible) { CurrentStreet = Street.Preflop; } }
private Currency GetCurrency(HandHistories.Objects.Hand.HandHistory history) { return(Currency.USD); }