Exemple #1
0
 public List<Game> ParseGames(string allHandsText)
 {
     var games = new List<Game>();
     IEnumerable<string> multipleGames = SplitAllTextInMultipleGames(allHandsText);
     foreach (var concreteGame in multipleGames)
     {
         if (FindBadHand(concreteGame))
             continue;
         var game = new Game { BoardCards = new byte[5] };
         var multipleLines = SplitOneGameTextInMultipleLines(concreteGame);
         game.GameNumber = FindGameNumber(multipleLines);
         game.HandText = concreteGame;
         game.DateOfHand = FindDateOfGame(multipleLines);
         game.TableName = FindTableName(multipleLines);
         game.SmallBlind = FindSmallBlind(multipleLines);
         game.BigBlind = FindBigBlind(multipleLines);
         game.LimitType = FindLimitType(multipleLines);
         game.MoneyType = FindMoneyType(multipleLines);
         game.SeatType = FindSeatType(multipleLines);
         game.ButtonPosition = FindButtonPosition(multipleLines);
         game.NumberOfPlayers = FindNumberOfPlayers(concreteGame);
         game.PlayerHistories = ParsePlayers(game, multipleLines);
         IEnumerable<HandAction> allHandActions = ParseHandActions(game, multipleLines).ToArray();
         foreach (var playerHistory in game.PlayerHistories)
         {
             var playerActions = allHandActions.Where(ha => ha.PlayerName == playerHistory.PlayerName).ToArray();
             playerHistory.HandActions.AddRange(playerActions);
         }
         games.Add(game);
     }
     return games;
 }
Exemple #2
0
        public override IEnumerable<HandAction> ParseHandActions(Game game, IReadOnlyList<string> multipleLines)
        {
            var handActions = new List<HandAction>();
            var currentStreet = Street.Preflop;
            for (var i = StartPlayerRow + game.NumberOfPlayers; i < multipleLines.Count; i++)
            {
                var ha = new HandAction() { Index = i };
                var lowerLine = multipleLines[i].ToLower();
                if (multipleLines[i].StartsWith("**"))
                {

                    if (lowerLine.Contains("flop"))
                    {
                        game.BoardCards.InitializeNewCards(FindFlopCards(multipleLines[i]));
                        currentStreet = Street.Flop;
                        continue;
                    }
                    if (lowerLine.Contains("turn"))
                    {
                        game.BoardCards[3] = FindTurnCard(multipleLines[i]);
                        currentStreet = Street.Turn;
                        continue;
                    }
                    if (lowerLine.Contains("river"))
                    {
                        game.BoardCards[4] = FindRiverCard(multipleLines[i]);
                        currentStreet = Street.River;
                        continue;
                    }
                    if (lowerLine.Contains("down cards"))
                    {
                        continue;
                    }
                    if (lowerLine.Contains("summary"))
                    {
                        currentStreet = Street.Showdown;
                        continue;
                    }
                    throw new ParserException($"No defined action with **. Unnown line -> {multipleLines[i]}", DateTime.Now);
                }//end **

                if (lowerLine.StartsWith("dealt to"))
                {
                    ha.PlayerName  = multipleLines[i].Split(' ')[2].Trim();
                    ha.Street = currentStreet;
                    ha.HandActionType = HandActionType.DEALT_HERO_CARDS;
                    game.Hero = ha.PlayerName;
                    game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindHeroCards(multipleLines[i]));
                    handActions.Add(ha);
                    continue;
                }
                //line don't starts with ** and "dealt to"
                //put new conditional in this place if some new statemants will apear
                //.....
                //.....
                var parts = multipleLines[i].Split(' ');
                ha.PlayerName = parts[0].Trim();
                ha.Street = currentStreet;
                switch (parts[1].Trim())
                {
                    case "posts":
                        switch (parts[2].Trim())
                        {
                            case "big":
                                ha.HandActionType = HandActionType.BIG_BLIND;
                                ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                handActions.Add(ha);
                                break;
                            case "small":
                                ha.HandActionType = HandActionType.SMALL_BLIND;
                                ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                handActions.Add(ha);
                                break;
                            case "ante":
                                ha.HandActionType = HandActionType.ANTE;
                                ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                handActions.Add(ha);
                                break;
                            case "dead":
                                ha.HandActionType = HandActionType.DEAD_BLIND;
                                ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                handActions.Add(ha);
                                break;
                            default:
                                throw new ParserException($"Undefined action. Unnown line -> {multipleLines[i]}", DateTime.Now);
                        }
                        continue;
                    case "folds":
                        ha.HandActionType = HandActionType.FOLD;
                        handActions.Add(ha);
                        continue;
                    case "checks":
                        ha.HandActionType = HandActionType.CHECK;
                        handActions.Add(ha);
                        continue;
                    case "calls":
                        ha.HandActionType = HandActionType.CALL;
                        ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                        handActions.Add(ha);
                        continue;
                    case "bets":
                        ha.HandActionType = HandActionType.BET;
                        ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                        handActions.Add(ha);
                        continue;
                    case "raises":
                        ha.HandActionType = HandActionType.RAISE;
                        ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                        handActions.Add(ha);
                        continue;
                    case "shows":
                        ha.HandActionType = HandActionType.SHOW;
                        game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindShowdounCards(multipleLines[i]));
                        handActions.Add(ha);
                        continue;
                    case "mucks":
                        ha.HandActionType = HandActionType.MUCKS;
                        game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindMuckCards(multipleLines[i]));
                        handActions.Add(ha);
                        continue;
                    case "collected":
                        ha.HandActionType = HandActionType.WINS;
                        ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                        handActions.Add(ha);
                        continue;
                }
            }
            CheckAllHandActionsForUncalled(handActions, multipleLines.Count);
            return handActions;
        }
        public override IEnumerable<HandAction> ParseHandActions(Game game, IReadOnlyList<string> multipleLines)
        {
            var handActions = new List<HandAction>();
            var currentStreet = Street.Preflop;
            for (var i = StartPlayerRow + game.NumberOfPlayers; i < multipleLines.Count; i++)
            {
                var ha = new HandAction() { Index = i };
                var lowerLine = multipleLines[i].ToLower();
                if (multipleLines[i].StartsWith("***"))
                {
                    if (lowerLine.Contains("flop"))
                    {
                        game.BoardCards.InitializeNewCards(FindFlopCards(multipleLines[i]));
                        currentStreet = Street.Flop;
                        continue;
                    }
                    if (lowerLine.Contains("turn"))
                    {
                        game.BoardCards[3] = FindTurnCard(multipleLines[i]);
                        currentStreet = Street.Turn;
                        continue;
                    }
                    if (lowerLine.Contains("river"))
                    {
                        game.BoardCards[4] = FindRiverCard(multipleLines[i]);
                        currentStreet = Street.River;
                        continue;
                    }
                    if (lowerLine.Contains("hole"))
                    {
                        continue;
                    }
                    if (lowerLine.Contains("show down"))
                    {
                        currentStreet = Street.Showdown;
                        continue;
                    }
                    if (lowerLine.Contains("summary"))
                    {
                        break;//пока что summary строки не будем обрабатывать.
                    }
                    throw new ParserException($"No defined action with ***. Unnown line -> {multipleLines[i]}", DateTime.Now);
                } //end ***
                if (lowerLine.StartsWith("dealt to"))
                {
                    ha.PlayerName = HeroNameRegex.Match(multipleLines[i]).Value.Trim();
                    ha.Street = currentStreet;
                    ha.HandActionType = HandActionType.DEALT_HERO_CARDS;
                    game.Hero = ha.PlayerName;
                    game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindHeroCards(multipleLines[i]));
                    handActions.Add(ha);
                    continue;
                }

                //hand actions of type "player:action"
                if (multipleLines[i].Contains(':'))
                {
                    var parts = multipleLines[i].Split(':');
                    ha.PlayerName = parts[0].Trim();
                    ha.Street = currentStreet;
                    var actionParts = parts[1].Trim().Split(' ');
                    switch (actionParts[0])
                    {
                        case "posts":
                            var key = actionParts[1];
                            switch (key)
                            {
                                case "big":
                                    ha.HandActionType = multipleLines[i].Contains("all-in") ? HandActionType.All_IN_BB : HandActionType.BIG_BLIND;
                                    ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                    handActions.Add(ha);
                                    break;
                                case "small":
                                    ha.HandActionType = multipleLines[i].Contains("all-in") ? HandActionType.All_IN_SB : HandActionType.SMALL_BLIND;
                                    ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                    handActions.Add(ha);
                                    break;
                                case "the"://ante
                                    ha.HandActionType = HandActionType.ANTE;
                                    ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                                    handActions.Add(ha);
                                    break;
                                default:
                                    throw new ParserException( $"No defined action that contains posts. Unnown line -> {multipleLines[i]}", DateTime.Now);
                            }
                            continue;
                        case "folds":
                            ha.HandActionType = HandActionType.FOLD;
                            handActions.Add(ha);
                            continue;
                        case "checks":
                            ha.HandActionType = HandActionType.CHECK;
                            handActions.Add(ha);
                            continue;
                        case "calls":
                            ha.HandActionType = multipleLines[i].Contains("all-in") ? HandActionType.ALL_IN_CALL : HandActionType.CALL;
                            ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                            handActions.Add(ha);
                            continue;
                        case "bets":
                            ha.HandActionType = multipleLines[i].Contains("all-in") ? HandActionType.ALL_IN_BET : HandActionType.BET;
                            ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                            handActions.Add(ha);
                            continue;
                        case "raises":
                            ha.HandActionType = multipleLines[i].Contains("all-in") ? HandActionType.ALL_IN_RAISE : HandActionType.RAISE;
                            ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                            handActions.Add(ha);
                            continue;
                        case "doesn't":
                            ha.HandActionType = HandActionType.DIDNT_SHOW_HAND;
                            handActions.Add(ha);
                            continue;
                        case "shows":
                            ha.HandActionType = HandActionType.SHOW;
                            game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindShowdounCards(multipleLines[i]));
                            handActions.Add(ha);
                            continue;
                        case "mucks":
                            ha.HandActionType = HandActionType.MUCKS;
                            game.PlayerHistories.Find(p => p.PlayerName == ha.PlayerName).HoleCards.InitializeNewCards(FindMuckCards(multipleLines));
                            handActions.Add(ha);
                            continue;
                        default:
                            throw new ParserException( $"Cann't parse string with ':' and unnown word. Unnown line -> {multipleLines[i]}", DateTime.Now);
                    }
                }
                //end contains :
                if (lowerLine.Contains("uncalled bet"))
                {
                    ha.HandActionType = HandActionType.UNCALLED_BET;
                    ha.PlayerName = UncalledBetPlayerRegex.Match(multipleLines[i]).Value;
                    ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                    handActions.Add(ha);
                    continue;
                }
                if (lowerLine.Contains("collected"))
                {
                    if (lowerLine.Contains("main"))
                    {
                        ha.HandActionType = HandActionType.WINS_MAIN_POT;
                    }
                    else if (lowerLine.Contains("side"))
                    {
                        ha.HandActionType = HandActionType.WINS_SIDE_POT;
                    }
                    else
                    {
                        ha.HandActionType = HandActionType.WINS;
                    }
                    ha.PlayerName = WinPlayerRegex.Match(multipleLines[i]).Value;
                    ha.Amount = DefineActionAmount(ha, multipleLines[i]);
                    handActions.Add(ha);
                    continue;
                }
                //hand actions without tracking:
                if (lowerLine.Contains("leaves the table"))
                {
                    continue;
                }
                if (lowerLine.Contains("joins the table"))
                {
                    continue;
                }
                if (lowerLine.Contains("will be allowed to play"))
                {
                    continue;
                }
                if (lowerLine.Contains("is disconnected"))
                {
                    continue;
                }
                if (lowerLine.Contains("was removed from the table"))
                {
                    continue;
                }
                if (lowerLine.Contains("finished the tournament"))
                {
                    continue;
                }
                if (lowerLine.Contains("said,"))
                {
                    continue;
                }
                if (lowerLine.Contains("has timed out"))
                {
                    continue;
                }
                if (lowerLine.Contains("is connected"))
                {
                    continue;
                }
                if (lowerLine.Contains("bounty for eliminating"))
                {
                    continue;
                }
                throw new ParserException($"Line with a new words -> {multipleLines[i]}", DateTime.Now);
            }
            return handActions;
        }
Exemple #4
0
 public virtual List<PlayerHistory> ParsePlayers(Game game, IReadOnlyList<string> multipleLines)
 {
     var players = new List<PlayerHistory>();
     for (var i = 0; i < game.NumberOfPlayers; i++)
     {
         string oneLine = multipleLines[StartPlayerRow + i];
         var player = new PlayerHistory
         {
             GameNumber = game.GameNumber,
             PlayerName = FindPlayerName(oneLine),
             SeatNumber = FindSeatNumber(oneLine),
             StartingStack = FindPlayerStartingStack(oneLine),
             HoleCards = new byte[2],
             HandActions = new List<HandAction>(),
             Game = game
         };
         players.Add(player);
     }
     InitializePositionsOfPlayers(players,game.ButtonPosition);
     return players;
 }
Exemple #5
0
 public abstract IEnumerable<HandAction> ParseHandActions(Game game, IReadOnlyList<string> multipleLines);
 public static int ThreeBet(this PlayerHistory ph, Game g)
 {
     if (!ph.HandActions.PreflopHandActions().RaiseActions().Any()) return 0;
     var rrIndex = ph.HandActions.PreflopHandActions().RaiseActions().First().Index;
     return g.PlayerHistories.Any(
         eph => eph.PlayerName != ph.PlayerName && eph.HandActions.PreflopHandActions().Any(a =>
             a.IsRaiseAction() && a.Index < rrIndex)) ? 1 : 0;
 }