public List <HandAction> ParseHandActions(string handText, out List <WinningsAction> winners) { try { var handactions = ParseHandActions(GetCategories(handText).Action, out winners); if (RequiresAdjustedRaiseSizes) { handactions = RaiseAdjuster.AdjustRaiseSizes(handactions); } if (RequiresAllInDetection) { var playerList = ParsePlayers(Lines.Seat); handactions = AllInActionHelper.IdentifyAllInActions(playerList, handactions); } if (RequiresAllInUpdates) { handactions = AllInActionHelper.UpdateAllInActions(handactions); } if (RequiresUncalledBetWinAdjustment) { winners = UncalledBet.FixUncalledBetWins(handactions, winners); } return(handactions); } catch (Exception ex) { throw new HandActionException(handText, "ParseHandActions: Error:" + ex.Message + " Stack:" + ex.StackTrace); } }
public List <HandAction> ParseHandActions(string handText, out List <WinningsAction> winners) { try { string[] handLines = SplitHandsLines(handText); GameType gameType = ParseGameType(handLines); List <HandAction> handActions = ParseHandActions(handLines, gameType, out winners); if (RequiresActionSorting) { handActions = OrderHandActions(handActions); } if (RequiresAdjustedRaiseSizes) { handActions = RaiseAdjuster.AdjustRaiseSizes(handActions); } if (RequiresAllInDetection) { var playerList = ParsePlayers(handLines); handActions = AllInActionHelper.IdentifyAllInActions(playerList, handActions); } if (RequiresAllInUpdates) { handActions = AllInActionHelper.UpdateAllInActions(handActions); } if (RequiresUncalledBetWinAdjustment) { winners = UncalledBet.FixUncalledBetWins(handActions, winners); } return(handActions); } catch (Exception ex) { throw new HandActionException(handText, "ParseHandActions: Error:" + ex.Message + " Stack:" + ex.StackTrace); } }
public HandHistory ParseFullHandHistory(string handText, bool rethrowExceptions = false) { GetCategories(handText); try { bool isCancelled; if (IsValidOrCancelledHand(Lines, out isCancelled) == false) { throw new InvalidHandException(handText); } //Set members outside of the constructor for easier performance analysis HandHistory handHistory = new HandHistory(); handHistory.FullHandHistoryText = handText; handHistory.DateOfHandUtc = ParseDateUtc(Lines.Header); handHistory.GameDescription = ParseGameDescriptor(Lines.Header); handHistory.HandId = ParseHandId(Lines.Header); handHistory.TableName = ParseTableName(Lines.Header); handHistory.DealerButtonPosition = ParseDealerPosition(Lines.Header); handHistory.CommunityCards = ParseCommunityCards(Lines.Summary); handHistory.Cancelled = isCancelled; handHistory.Players = ParsePlayers(Lines.Seat); handHistory.NumPlayersSeated = handHistory.Players.Count; string heroName = ParseHeroName(Lines.Other); handHistory.Hero = handHistory.Players.FirstOrDefault(p => p.PlayerName == heroName); if (handHistory.Cancelled) { return(handHistory); } if (handHistory.Players.Count(p => p.IsSittingOut == false) <= 1) { throw new PlayersException(handText, "Only found " + handHistory.Players.Count + " players with actions."); } // if (SupportRunItTwice) // { // handHistory.RunItTwiceData = ParseRunItTwice(handLines); // } List <WinningsAction> winners; handHistory.HandActions = ParseHandActions(Lines.Action, out winners); handHistory.Winners = winners; if (RequiresAdjustedRaiseSizes) { handHistory.HandActions = RaiseAdjuster.AdjustRaiseSizes(handHistory.HandActions); } if (RequiresAllInDetection) { var playerList = ParsePlayers(Lines.Seat); handHistory.HandActions = AllInActionHelper.IdentifyAllInActions(playerList, handHistory.HandActions); } if (RequiresAllInUpdates) { handHistory.HandActions = AllInActionHelper.UpdateAllInActions(handHistory.HandActions); } if (RequiresUncalledBetFix) { handHistory.HandActions = UncalledBet.Fix(handHistory.HandActions); } if (RequiresUncalledBetWinAdjustment) { winners = UncalledBet.FixUncalledBetWins(handHistory.HandActions, winners); } //Pot calculation mus be done after uncalledBetFix if (RequiresTotalPotCalculation) { handHistory.TotalPot = PotCalculator.CalculateTotalPot(handHistory); handHistory.Rake = PotCalculator.CalculateRake(handHistory); } HandAction anteAction = handHistory.HandActions.FirstOrDefault(a => a.HandActionType == HandActionType.ANTE); if (anteAction != null && handHistory.GameDescription.PokerFormat.Equals(PokerFormat.CashGame)) { handHistory.GameDescription.Limit.IsAnteTable = true; handHistory.GameDescription.Limit.Ante = Math.Abs(anteAction.Amount); } ParseExtraHandInformation(Lines, handHistory); if (handHistory.Players.All(p => p.SeatNumber != handHistory.DealerButtonPosition)) { throw new InvalidHandException(handText, "Dealer not found"); } FinalizeHand(handHistory); SetActionNumbers(handHistory); Lines.Clear(); return(handHistory); } catch (Exception ex) { if (rethrowExceptions) { throw; } logger.Warn("Couldn't parse hand {0} with error {1} and trace {2}", handText, ex.Message, ex.StackTrace); return(null); } }
public virtual HandHistory ParseFullHandHistory(string handText, bool rethrowExceptions = false) { var handHistory = new HandHistory(); try { handText = ClearHandHistory(handText); if (string.IsNullOrEmpty(handText)) { return(null); } string[] handLines = SplitHandsLines(handText); // parse summary hand if (IsSummaryHand(handLines)) { return(ParseSummaryHand(handLines, handHistory)); } if (!IsValidOrCanceledHand(handLines, out bool isCancelled)) { throw new InvalidHandException(handText ?? "NULL"); } //Set members outside of the constructor for easier performance analysis handHistory.DateOfHandUtc = ParseDateUtc(handLines); handHistory.GameDescription = ParseGameDescriptor(handLines); if (handHistory.GameDescription.PokerFormat == PokerFormat.Tournament) { handHistory.GameDescription.Tournament = ParseTournament(handLines); } handHistory.HandId = ParseHandId(handLines); handHistory.TableName = ParseTableName(handLines); handHistory.DealerButtonPosition = ParseDealerPosition(handLines); handHistory.FullHandHistoryText = string.Join("\r\n", handLines); handHistory.CommunityCards = ParseCommunityCards(handLines); handHistory.Cancelled = isCancelled; handHistory.Players = ParsePlayers(handLines); handHistory.NumPlayersSeated = handHistory.Players.Count; var heroName = ParseHeroName(handLines, handHistory.Players); if (!string.IsNullOrEmpty(heroName)) { handHistory.Hero = handHistory.Players.FirstOrDefault(p => p.PlayerName == heroName); } if (handHistory.Cancelled) { return(handHistory); } if (handHistory.Players.Count(p => p.IsSittingOut == false) <= 1) { throw new PlayersException(handText, "Only found " + handHistory.Players.Count + " players with actions."); } handHistory.HandActions = ParseHandActions(handLines, handHistory.GameDescription.GameType); if (handHistory.GameDescription.Limit.BigBlind == 0 || handHistory.GameDescription.Limit.SmallBlind == 0) { ParseBlinds(handHistory); } if (RequiresActionSorting) { handHistory.HandActions = OrderHandActions(handHistory.HandActions, handHistory.Players, handHistory); } if (RequiresAdjustedRaiseSizes) { handHistory.HandActions = AdjustRaiseSizes(handHistory.HandActions); } if (RequiresAllInDetection) { handHistory.HandActions = AllInActionHelper.IdentifyAllInActions(handHistory.Players, handHistory.HandActions); } if (RequiresAllInUpdates) { handHistory.HandActions = AllInActionHelper.UpdateAllInActions(handHistory.HandActions); } if (RequiresSeatTypeAdjustment) { AdjustSeatTypes(handHistory); } if (handHistory.GameDescription.IsTournament && RequiresTournamentSpeedAdjustment) { AdjustTournamentSpeed(handHistory); } if (RequiresUncalledBetCalculations) { CalculateUncalledBets(handLines, handHistory); } if (handHistory.TotalPot == null) { HandHistoryUtils.CalculateTotalPot(handHistory); } HandAction anteAction = handHistory.HandActions.FirstOrDefault(a => a.HandActionType == HandActionType.ANTE); if (!handHistory.GameDescription.Limit.IsAnteTable && anteAction != null) { handHistory.GameDescription.Limit.IsAnteTable = true; handHistory.GameDescription.Limit.Ante = Math.Abs(anteAction.Amount); } try { ParseExtraHandInformation(handLines, handHistory); } catch (Exception) { throw new ExtraHandParsingAction(handLines[0]); } // remove inactive players var players = handHistory.HandActions.Where(x => x.Street == Street.Preflop).Select(x => x.PlayerName).ToList(); foreach (var player in handHistory.Players.ToList()) { if (players.Contains(player.PlayerName)) { if (RequiresBetWinAdjustment) { var playerActions = handHistory.HandActions.Where(x => x.PlayerName.Equals(player.PlayerName)); if (playerActions != null && playerActions.Any()) { player.Win = playerActions.Where(x => x.IsWinningsAction).Sum(x => x.Amount); player.Bet = Math.Abs(playerActions.Where(x => x.Amount < 0).Sum(x => x.Amount)); var uncalledBet = playerActions.Where(x => x.HandActionType == HandActionType.UNCALLED_BET).Sum(x => x.Amount); player.Bet -= uncalledBet; } } continue; } handHistory.Players.Remove(player); } return(handHistory); } catch (Exception ex) { if (rethrowExceptions) { throw; } LogProvider.Log.Warn(this, string.Format("Couldn't parse hand {0} with error {1} and trace {2}", handText, ex.Message, ex.StackTrace)); handHistory.Exception = ex; return(handHistory); } }