コード例 #1
0
ファイル: HandParser.cs プロジェクト: kampiuceris/PsHandler
 public void LoadHand(PokerHand pokerHand)
 {
     ToDo.Clear();
     UnDo.Clear();
     Pots.Clear();
     PotsStreetByStreet.Clear();
     Seats = pokerHand.Seats;
     Players = Seats.Where(o => o != null).ToArray();
     TableSize = pokerHand.TableSize;
     ButtonSeatNumber = pokerHand.ButtonSeat;
     foreach (var player in Players) player.Table = this;
     ToDo.AddRange(pokerHand.PokerCommands);
 }
コード例 #2
0
        //
        public void ReplayHand(PokerHand pokerHand)
        {
            CleanTable();
            PokerHand = pokerHand;

            if (PokerHand != null)
            {
                Table.LoadHand(PokerHand);
                UndoCommandAll();
                GoToPreflop();
            }
        }
コード例 #3
0
ファイル: HandParser.cs プロジェクト: kampiuceris/PsHandler
        private static bool AnalyzeLine(string text, PokerHand pokerHand)
        {
            if (text.Equals("*** SHOW DOWN ***")) { pokerHand.PokerCommands.Add(new PokerCommands.CollectPots(Street.River)); pokerHand.PokerCommands.Add(new PokerCommands.FinalizePots()); pokerHand.Showdown = true; return true; }
            if (text.Equals("*** HOLE CARDS ***")) return true;
            if (text.Equals("*** SUMMARY ***")) return true;
            if (text.StartsWith("Board [")) return true;
            if (text.StartsWith("Seat ") && (text.Contains("folded") || text.Contains("showed") || text.Contains("collected"))) return true;
            if (text.Contains("doesn't show hand")) return true;
            if (text.Contains(" has timed out")) return true;
            if (text.Contains(" has timed out while being disconnected")) return true;
            if (text.Contains(" has timed out while disconnected")) return true;
            if (text.Contains(" is sitting out") && !text.StartsWith("Seat ")) return true;
            if (text.Contains(" has returned")) return true;
            if (text.Contains(" is disconnected")) return true;
            if (text.Contains(" is connected")) return true;
            if (text.Contains(" sits out")) return true;
            if (text.Contains(" joins the table at seat #")) return true;
            if (text.Contains(" will be allowed to play after the button")) return true;
            if (text.Contains(" leaves the table")) return true;
            if (text.Contains(" for eliminating ") && text.Contains(" bounty ")) return true;
            if (text.Contains(" wins an entry to tournament ")) return true;
            if (text.Contains(" wins the tournament - congratulations!")) return true;
            if (text.Contains(" re-buys and receives ")) return true;
            if (text.Contains(" takes the add-on and receives ")) return true;
            if (text.Contains("also received a Golden Sit & Go reward of ")) return true;

            Match match;

            #region 1st Line

            if (Regex1stLine.Match(text).Success)
            {
                if (text.Contains("Tournament #"))
                {
                    match = RegexHeaderTournament.Match(text);
                    if (!match.Success) throw new NotSupportedException();

                    pokerHand.IsTournament = true;
                    pokerHand.HandNumber = long.Parse(match.Groups["hand_id"].Value);
                    pokerHand.TournamentNumber = long.Parse(match.Groups["tournament_id"].Value);
                    if (match.Groups["zoom"].Success) pokerHand.IsZoom = true;
                    if (match.Groups["currency"].Success)
                    {
                        switch (match.Groups["currency"].Value)
                        {
                            case "USD":
                                pokerHand.Currency = PokerEnums.Currency.USD;
                                break;
                            case "EUR":
                                pokerHand.Currency = PokerEnums.Currency.EUR;
                                break;
                            case "BGP":
                                pokerHand.Currency = PokerEnums.Currency.GBP;
                                break;
                            case "":
                                pokerHand.Currency = PokerEnums.Currency.PlayMoney;
                                break;
                            default:
                                pokerHand.Currency = PokerEnums.Currency.Unknown;
                                break;
                        }
                    }
                    if (match.Groups["buyin_fpp"].Success) pokerHand.Currency = PokerEnums.Currency.FPP;
                    if (match.Groups["freeroll"].Success) pokerHand.Currency = PokerEnums.Currency.Freeroll;

                    if (match.Groups["buyin"].Success) pokerHand.BuyIn = decimal.Parse(match.Groups["buyin"].Value);
                    if (match.Groups["bounty"].Success) pokerHand.Bounty = decimal.Parse(match.Groups["bounty"].Value);
                    if (match.Groups["rake"].Success) pokerHand.Rake = decimal.Parse(match.Groups["rake"].Value);

                    if (pokerHand.Currency == PokerEnums.Currency.FPP) pokerHand.BuyIn = decimal.Parse(match.Groups["buyin_fpp"].Value);

                    pokerHand.GameType = match.Groups["game_type"].Value;
                    if (match.Groups["additional_info"].Success) pokerHand.AdditionalInfo = match.Groups["additional_info"].Value;
                    pokerHand.LevelNumber = match.Groups["level_number"].Value;

                    pokerHand.LevelSmallBlind = decimal.Parse(match.Groups["level_sb"].Value);
                    pokerHand.LevelBigBlind = decimal.Parse(match.Groups["level_bb"].Value);

                    if (match.Groups["timezone_et_only"].Success)
                    {
                        pokerHand.TimeStampLocal = new DateTime(int.Parse(match.Groups["year_et_only"].Value), int.Parse(match.Groups["month_et_only"].Value), int.Parse(match.Groups["day_et_only"].Value), int.Parse(match.Groups["hour_et_only"].Value), int.Parse(match.Groups["minute_et_only"].Value), int.Parse(match.Groups["second_et_only"].Value));
                        pokerHand.LocalTimeZoneStr = match.Groups["timezone_et_only"].Value;
                        pokerHand.LocalTimeZone = TimeZone.Parse(pokerHand.LocalTimeZoneStr);
                        pokerHand.TimeStampET = pokerHand.TimeStampLocal;
                    }
                    else
                    {
                        pokerHand.TimeStampLocal = new DateTime(int.Parse(match.Groups["year"].Value), int.Parse(match.Groups["month"].Value), int.Parse(match.Groups["day"].Value), int.Parse(match.Groups["hour"].Value), int.Parse(match.Groups["minute"].Value), int.Parse(match.Groups["second"].Value));
                        pokerHand.LocalTimeZoneStr = match.Groups["timezone"].Value;
                        pokerHand.LocalTimeZone = TimeZone.Parse(pokerHand.LocalTimeZoneStr);
                        pokerHand.TimeStampET = new DateTime(int.Parse(match.Groups["year_et"].Value), int.Parse(match.Groups["month_et"].Value), int.Parse(match.Groups["day_et"].Value), int.Parse(match.Groups["hour_et"].Value), int.Parse(match.Groups["minute_et"].Value), int.Parse(match.Groups["second_et"].Value));
                    }

                    pokerHand.TotalBuyIn = pokerHand.BuyIn + pokerHand.Bounty + pokerHand.Rake;
                    return true;
                }
                else
                {
                    match = RegexHeaderCash.Match(text);
                    if (!match.Success) throw new NotSupportedException();

                    if (match.Groups["zoom"].Success) pokerHand.IsZoom = true;
                    pokerHand.HandNumber = long.Parse(match.Groups["hand_id"].Value);
                    pokerHand.GameType = match.Groups["game_type"].Value;
                    pokerHand.LevelSmallBlind = decimal.Parse(match.Groups["level_sb"].Value);
                    pokerHand.LevelBigBlind = decimal.Parse(match.Groups["level_bb"].Value);
                    if (match.Groups["currency"].Success)
                    {
                        switch (match.Groups["currency"].Value)
                        {
                            case "USD":
                                pokerHand.Currency = PokerEnums.Currency.USD;
                                break;
                            case "EUR":
                                pokerHand.Currency = PokerEnums.Currency.EUR;
                                break;
                            case "BGP":
                                pokerHand.Currency = PokerEnums.Currency.GBP;
                                break;
                            default:
                                pokerHand.Currency = PokerEnums.Currency.Unknown;
                                break;
                        }
                    }
                    else
                    {
                        if (match.Groups["level_sb_currency_symbol"].Success)
                        {
                            switch (match.Groups["level_sb_currency_symbol"].Value)
                            {
                                case "$":
                                    pokerHand.Currency = PokerEnums.Currency.USD;
                                    break;
                                case "€":
                                    pokerHand.Currency = PokerEnums.Currency.EUR;
                                    break;
                                case "£":
                                    pokerHand.Currency = PokerEnums.Currency.GBP;
                                    break;
                                default:
                                    pokerHand.Currency = PokerEnums.Currency.Unknown;
                                    break;
                            }
                        }
                        else
                        {
                            pokerHand.Currency = PokerEnums.Currency.PlayMoney;
                        }
                    }

                    if (match.Groups["timezone_et_only"].Success)
                    {
                        pokerHand.TimeStampLocal = new DateTime(int.Parse(match.Groups["year_et_only"].Value), int.Parse(match.Groups["month_et_only"].Value), int.Parse(match.Groups["day_et_only"].Value), int.Parse(match.Groups["hour_et_only"].Value), int.Parse(match.Groups["minute_et_only"].Value), int.Parse(match.Groups["second_et_only"].Value));
                        pokerHand.LocalTimeZoneStr = match.Groups["timezone_et_only"].Value;
                        pokerHand.LocalTimeZone = TimeZone.Parse(pokerHand.LocalTimeZoneStr);
                        pokerHand.TimeStampET = pokerHand.TimeStampLocal;
                    }
                    else
                    {
                        pokerHand.TimeStampLocal = new DateTime(int.Parse(match.Groups["year"].Value), int.Parse(match.Groups["month"].Value), int.Parse(match.Groups["day"].Value), int.Parse(match.Groups["hour"].Value), int.Parse(match.Groups["minute"].Value), int.Parse(match.Groups["second"].Value));
                        pokerHand.LocalTimeZoneStr = match.Groups["timezone"].Value;
                        pokerHand.LocalTimeZone = TimeZone.Parse(pokerHand.LocalTimeZoneStr);
                        pokerHand.TimeStampET = new DateTime(int.Parse(match.Groups["year_et"].Value), int.Parse(match.Groups["month_et"].Value), int.Parse(match.Groups["day_et"].Value), int.Parse(match.Groups["hour_et"].Value), int.Parse(match.Groups["minute_et"].Value), int.Parse(match.Groups["second_et"].Value));
                    }

                    return true;
                }
            }

            #endregion

            #region 2nd Line

            match = RegexSeatMaxButton.Match(text);
            if (match.Success)
            {
                pokerHand.TableName = match.Groups["table_name"].Value;
                pokerHand.TableSize = (PokerEnums.TableSize)int.Parse(match.Groups["table_size"].Value);
                pokerHand.ButtonSeatHandHistory = int.Parse(match.Groups["button_seat"].Value);
                pokerHand.ButtonSeat = pokerHand.ButtonSeatHandHistory - 1;

                pokerHand.Seats = new Player[(int)pokerHand.TableSize];

                return true;
            }

            #endregion

            #region Player

            match = RegexPlayer.Match(text);
            if (match.Success)
            {
                Player player = new Player();
                player.SeatNumberHandHistory = int.Parse(match.Groups["seat_number"].Value);
                player.SeatNumber = player.SeatNumberHandHistory - 1;
                player.PlayerName = match.Groups["player_name"].Value;
                player.Stack = decimal.Parse(match.Groups["stack"].Value);
                player.IsInPlay = true;

                pokerHand.Seats[player.SeatNumber] = player;

                return true;
            }

            #endregion

            //

            #region Post sb/bb/ante

            match = RegexPostBlinds.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amount = decimal.Parse(match.Groups["amount"].Value);

                switch (match.Groups["type"].Value)
                {
                    case "the ante":
                        pokerHand.PokerCommands.Add(new PokerCommands.PostAnte(text, player, amount));
                        break;
                    case "small blind":
                        pokerHand.PokerCommands.Add(new PokerCommands.PostSmallBlind(text, player, amount));
                        break;
                    case "big blind":
                        pokerHand.PokerCommands.Add(new PokerCommands.PostBigBlind(text, player, amount));
                        break;
                }

                return true;
            }

            #endregion

            #region Dealt to

            match = RegexDealtTo.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                var cards = new[] { match.Groups["card0"].Value, match.Groups["card1"].Value };
                player.PocketCards = cards;
                player.IsHero = true;

                pokerHand.PokerCommands.Add(new PokerCommands.DealtTo(text, player));

                return true;
            }

            #endregion

            #region Fold

            match = RegexFold.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                bool foldAndShow = true;
                if (match.Groups["card1"].Success)
                {
                    player.PocketCards = new[] { match.Groups["card0"].Value, match.Groups["card1"].Value };
                }
                else if (match.Groups["card0"].Success)
                {
                    player.PocketCards = new[] { match.Groups["card0"].Value };
                }
                else
                {
                    foldAndShow = false;
                }
                pokerHand.PokerCommands.Add(new PokerCommands.Fold(text, player, foldAndShow));

                return true;
            }

            #endregion

            #region Check

            match = RegexCheck.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                pokerHand.PokerCommands.Add(new PokerCommands.Check(text, player));

                return true;
            }

            #endregion

            #region Call

            match = RegexCall.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amount = decimal.Parse(match.Groups["amount"].Value);
                bool allIn = match.Groups["all_in"].Success;

                pokerHand.PokerCommands.Add(new PokerCommands.Call(text, player, amount, allIn));

                return true;
            }

            #endregion

            #region Bet

            match = RegexBet.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amount = decimal.Parse(match.Groups["amount"].Value);
                bool allIn = match.Groups["all_in"].Success;

                pokerHand.PokerCommands.Add(new PokerCommands.Bet(text, player, amount, allIn));

                return true;
            }

            #endregion

            #region Raise

            match = RegexRaise.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amountInTotal = decimal.Parse(match.Groups["amount_in_total"].Value);
                bool allIn = match.Groups["all_in"].Success;

                pokerHand.PokerCommands.Add(new PokerCommands.Raise(text, player, amountInTotal, allIn));

                return true;
            }

            #endregion

            #region Uncalled Bet Return

            match = RegexUncalledBetReturn.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amount = decimal.Parse(match.Groups["amount"].Value);

                pokerHand.PokerCommands.Add(new PokerCommands.UncalledBetReturn(text, player, amount));

                return true;
            }

            #endregion

            #region Shows

            match = RegexShows.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                if (match.Groups["card0"].Success && match.Groups["card1"].Success)
                {
                    player.PocketCards = new[] { match.Groups["card0"].Value, match.Groups["card1"].Value };
                }
                if (match.Groups["card0one"].Success)
                {
                    player.PocketCards = new[] { match.Groups["card0one"].Value };
                }
                string info = match.Groups["showdown_info"].Value;

                pokerHand.PokerCommands.Add(new PokerCommands.Shows(text, player, info));

                return true;
            }

            #endregion

            #region Collect From Pot

            match = RegexCollectFromPot.Match(text);
            if (match.Success)
            {
                if (!pokerHand.PokerCommands.Any(a => a is PokerCommands.FinalizePots))
                {
                    pokerHand.PokerCommands.Add(new PokerCommands.CollectPots(Street.Preflop));
                    pokerHand.PokerCommands.Add(new PokerCommands.FinalizePots());
                }

                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                decimal amount = decimal.Parse(match.Groups["amount"].Value);

                pokerHand.PokerCommands.Add(new PokerCommands.CollectFromPot(text, player, amount));

                return true;
            }

            #endregion

            #region Muck

            match = RegexMuck.Match(text);
            if (match.Success)
            {
                var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                pokerHand.PokerCommands.Add(new PokerCommands.Fold(text, player, true));

                return true;
            }

            #endregion

            #region Total Pot

            match = RegexTotalPot.Match(text);
            if (match.Success)
            {
                if (!pokerHand.IsTournament)
                {
                    pokerHand.Rake = decimal.Parse(match.Groups["rake"].Value);
                    return true;
                }
                else
                {
                    return true;
                }
            }

            #endregion

            #region MuckedInfo

            if (text.Contains(" mucked "))
            {
                match = RegexMuckedInfo.Match(text.Replace("(button) ", "").Replace("(small blind) ", "").Replace("(big blind) ", ""));
                if (match.Success)
                {
                    var player = pokerHand.Seats.First(o => o != null && o.PlayerName.Equals(match.Groups["player_name"].Value));
                    player.PocketCards = new[] { match.Groups["card0"].Value, match.Groups["card1"].Value };

                    return true;
                }
            }

            #endregion

            #region Flop

            match = RegexFlop.Match(text);
            if (match.Success)
            {
                string[] cards = { match.Groups["card0"].Value, match.Groups["card1"].Value, match.Groups["card2"].Value };

                pokerHand.PokerCommands.Add(new PokerCommands.CollectPots(Street.Preflop));
                pokerHand.PokerCommands.Add(new PokerCommands.Flop(text, cards));

                return true;
            }

            #endregion

            #region Turn

            match = RegexTurn.Match(text);
            if (match.Success)
            {
                string card = match.Groups["card3"].Value;

                pokerHand.PokerCommands.Add(new PokerCommands.CollectPots(Street.Flop));
                pokerHand.PokerCommands.Add(new PokerCommands.Turn(text, card));

                return true;
            }

            #endregion

            #region River

            match = RegexRiver.Match(text);
            if (match.Success)
            {
                string card = match.Groups["card4"].Value;

                pokerHand.PokerCommands.Add(new PokerCommands.CollectPots(Street.Turn));
                pokerHand.PokerCommands.Add(new PokerCommands.River(text, card));

                return true;
            }

            #endregion

            #region Win Tournament

            match = RegexWinTournament.Match(text);
            if (match.Success)
            {
                return true;
            }

            #endregion

            #region Finished

            match = RegexFinished.Match(text);
            if (match.Success)
            {
                return true;
            }

            #endregion

            #region Chat

            match = RegexChat.Match(text);
            if (match.Success)
            {
                return true;
            }

            #endregion

            return false;
        }