All pastes #263502 Raw Edit

aLFie

public text v1 · immutable
·published 2006-12-01 16:32 UTC
rendered paste body
Parser.cs
------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace HandRecorderPS.parser
{
    class Parser
    {

    }
}
------------------------------------------------------------------------------------------------------------


PartyParser.cs
------------------------------------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace HandRecorderPS.parser
{
    class PartyParser : Parser
    {
        // PROPERTIES
        private Dictionary<string, string> __getData;
        public Dictionary<string, string> _getData
        {
            get { return __getData; }
            set { __getData = value; }
        }

        private Dictionary<int, Dictionary<string, string>> __getPlayers;
        public Dictionary<int, Dictionary<string, string>> _getPlayers
        {
            get { return __getPlayers; }
        }

        private string __getHero;
        public string _getHero
        {
            get { return __getHero; }
        }

        private string __getHeroCards;
        public string _getHeroCards
        {
            get { return __getHeroCards; }
        }

        private int __getTotalPlayers;
        public int _getTotalPlayers
        {
            get { return __getTotalPlayers; }
        }

        private string __history;
        public string _history
        {
            get { return __history; }
        }

        // METHODS
        public PartyParser(string history)
        {
            getData(history);
            getPlayers(history);
            getRounds(history);
        }

        private void getData(string history)
        {
            // INTO CONFIGFILE
            string __handid = @"\*{5} Hand History for Game \d+ \*{5}";
            string __offerer = "";
            string[] __gametype = new string[] { @"Hold\'em[^\n]*Trny:\d+", @"NL Hold\'em[^\n]*Trny:\d+", @"PL Hold\'em[^\n]*Trny:\d+", @"(.*)\sTexas\sHold\'em\s-\s[^\n]*?,\s\d\d:\d\d:\d\d\s", @"\$(\d+) NL Hold\'em - [^\n]*?, \d\d:\d\d:\d\d ", @"\$(\d+) PL Hold\'em - [^\n]*?, \d\d:\d\d:\d\d " };
            string[] __moneysymbol = new string[] { "T", "T", "T", "$", "$", "$" };
            string[] __gametitle = new string[] { "Texas Hold'em Tournament", "NL Texas Hold'em Tournament", "PL Texas Hold'em Tournament", "Texas Holdem", "NL Texas Holdem", "PL Texas Holdem" };
            string[] __gamedisplay = new string[] { "Limit", "NL", "PL", "Limit", "NL", "PL" };
            string[] __gamemethod = new string[] { "Tourney", "Tourney", "Tourney", "Ring", "Ring", "Ring" };
            string __tourneylevel = @"Level:\d+ Blinds[ ]*?\((\d+)\/(\d+)\)";
            string __ringlimit = @"(.*?)\s(Texas\sHold\'em\s-\s|NL\sHolde\'em|PL\sHold\'em)";
            string __smallblind = @"posts\ssmall\sblind\s\[\$(.*)\]";
            string __bigblind = @"posts\sbig\sblind\s\[\$(.*)\]";
            string __cap = "4";

            Dictionary<string, string> gamedata = new Dictionary<string, string>();

            if (Regex.IsMatch(history, __handid))
            {
                gamedata.Add("HandId", Regex.Match(history, __handid).Groups[1].ToString());
                gamedata.Add("Site", __offerer);
                gamedata.Add("Cap", __cap);
            }

            for (int i = 0; i < __gametype.Length; i++)
            {
                if (Regex.IsMatch(history, __gametype[i]))
                {
                    gamedata.Add("MoneySymbol", __moneysymbol[i]);
                    gamedata.Add("GameTitle", __gametitle[i]);
                    gamedata.Add("GameDisplay", __gamedisplay[i]);
                    gamedata.Add("GameMethod", __gamemethod[i]);
                }
            }

            if (gamedata["GameMethod"].ToString() == "Tourney")
            {
                gamedata.Add("TourneyLevel", Regex.Match(history, __tourneylevel).Groups[1].ToString());
                gamedata.Add("BlindSmall", Regex.Match(history, __tourneylevel).Groups[2].ToString());
                gamedata.Add("BlindBig", Regex.Match(history, __tourneylevel).Groups[3].ToString());
            }
            else if (gamedata["GameMethod"].ToString() == "Ring")
            {
                string RingLimit = Regex.Match(history, __ringlimit).Groups[1].ToString();
                RingLimit = Regex.Replace(RingLimit, @"\$", @"");
                gamedata.Add("Limit", RingLimit);
                if (gamedata["GameDisplay"].ToString() == "Limit")
                {
                    string[] spLimit = RingLimit.Split('/');
                    gamedata.Add("SmallBlind", Regex.Match(history, __smallblind).Groups[1].ToString());
                    gamedata.Add("BigBlind", Regex.Match(history, __bigblind).Groups[1].ToString());
                    gamedata.Add("SmallBet", spLimit[0]);
                    gamedata.Add("BigBet", spLimit[1]);
                }
                else if (gamedata["GameDisplay"].ToString() == "NL")
                {
                    gamedata.Add("SmallBlind", Regex.Match(history, __smallblind).Groups[1].ToString());
                    gamedata.Add("BigBlind", Regex.Match(history, __bigblind).Groups[1].ToString());
                }
                else if (gamedata["GameDisplay"].ToString() == "PL")
                {
                    gamedata.Add("SmallBlind", Regex.Match(history, __smallblind).Groups[1].ToString());
                    gamedata.Add("BigBlind", Regex.Match(history, __bigblind).Groups[1].ToString());
                }
            }

            __getData = gamedata;

        }

        private void getPlayers(string history)
        {
            // INTO CONFIGFILE
            string __stacks = @"Seat\s(\d+):\s(\w+)\s\(\s\$(.+)\s\)";
            string __button = @"Seat\s(\d+)\sis\sthe\sbutton";
            string __totalplayers = @"Total\snumber\sof\splayers\s:\s(\d+).*?";
            string __sitoutsearch = @"(\S+) is sitting out.";
            string __sitoutplayerA = @"Seat \d+: ";
            string __sitoutplayerE = @" \(.*?\)";
            string __buttontitle = "Button";
            string __herodata = @"Dealt to (\w+) \[  (\d|T|J|Q|K|A)(c|d|h|s)\s(\d|T|J|Q|K|A)(c|d|h|s)\s\]";
            int __cardpockets = 2;

            Regex rx;
            MatchCollection mc;
            Dictionary<int, Dictionary<string, string>> players = new Dictionary<int, Dictionary<string, string>>();

            int ButtonSeat = 0;
            if (Regex.IsMatch(history, __totalplayers))
                ButtonSeat = Convert.ToInt16(Regex.Match(history, __button).Groups[1].ToString());

            int SitoutPlayers = 0;
            rx = new Regex(__sitoutsearch);
            mc = rx.Matches(history);
            foreach (Match mtch in mc)
            {
                if (Regex.IsMatch(history, __sitoutplayerA + mtch.Groups[1].ToString() + __sitoutplayerE))
                {
                    SitoutPlayers++;
                }
            }

            int TotalPlayers = 0;
            if (Regex.IsMatch(history, __totalplayers))
                TotalPlayers = Convert.ToInt16(Regex.Match(history, __totalplayers).Groups[1].ToString()) - SitoutPlayers;

            Stack seats;
            seats = getSeats(TotalPlayers);

            // hero erkennen
            string HeroName = "";
            if (Regex.IsMatch(history, __herodata))
            {
                HeroName = Regex.Match(history, __herodata).Groups[1].ToString();
            }


            int i = 0;
            int pSeat = 0;
            rx = new Regex(__stacks);
            mc = rx.Matches(history);
            foreach (Match mtch in mc)
            {
                players.Add(i, new Dictionary<string, string>());
                players[i].Add("PlayerSeatNumber", mtch.Groups[1].ToString());
                players[i].Add("PlayerName", mtch.Groups[2].ToString());
                players[i].Add("PlayerStack", mtch.Groups[3].ToString());
                pSeat = Convert.ToInt16(players[i]["PlayerSeatNumber"].ToString());
                if (pSeat == ButtonSeat)
                {
                    players[i].Add("PlayerSeatTitle", __buttontitle);
                }
                else if ((pSeat > ButtonSeat) && (pSeat < ButtonSeat + 2) && (i <= TotalPlayers))
                {
                    players[i].Add("PlayerSeatTitle", seats.Pop().ToString());
                }
                i++;
            }

            // benennt die restlichen positionen
            i = 0;
            pSeat = 0;
            int x = 1;
            while (seats.Count > 0)
            {
                pSeat = Convert.ToInt16(players[i]["PlayerSeatNumber"]);
                if ((pSeat == x) && (pSeat != ButtonSeat))
                {
                    players[i].Add("PlayerSeatTitle", seats.Pop().ToString());
                    i = 0;
                    x++;
                }
                else if (i == (TotalPlayers - 1))
                {
                    i = 0;
                    x++;
                }
                else
                {
                    i++;
                }
            }
            __getTotalPlayers = TotalPlayers;
            __getHero = HeroName;
            __getPlayers = players;
        }

        private Stack getSeats(int TotalPlayers)
        {
            string[] SeatTitleList;
            if (TotalPlayers == 10)
            {
                SeatTitleList = new string[] { "CO", "MP3", "MP2", "MP1", "UTG+2", "UTG+1", "UTG", "BB", "SB" };
            }
            else if (TotalPlayers == 9)
            {
                SeatTitleList = new string[] { "CO", "MP3", "MP2", "MP1", "UTG+2", "UTG+1", "BB", "SB" };
            }
            else if (TotalPlayers == 8)
            {
                SeatTitleList = new string[] { "CO", "MP3", "MP2", "MP1", "UTG+2", "BB", "SB" };
            }
            else if (TotalPlayers == 7)
            {
                SeatTitleList = new string[] { "CO", "MP3", "MP2", "MP1", "BB", "SB" };
            }
            else if (TotalPlayers == 6)
            {
                SeatTitleList = new string[] { "CO", "MP3", "MP2", "BB", "SB" };
            }
            else if (TotalPlayers == 5)
            {
                SeatTitleList = new string[] { "CO", "MP3", "BB", "SB" };
            }
            else if (TotalPlayers == 4)
            {
                SeatTitleList = new string[] { "CO", "BB", "SB" };
            }
            else if (TotalPlayers == 3)
            {
                SeatTitleList = new string[] { "BB", "SB" };
            }
            else if (TotalPlayers == 2)
            {
                SeatTitleList = new string[] { "BB" };
            }
            else
            {
                SeatTitleList = new string[0];
            }
            return arrToStack(SeatTitleList);
        }

        private void getRounds(string history)
        {
            // INTO CONFIGFILE
            string __actions = @"\*\* Dealing down cards \*\*(.*)\*\* Dealing Flop \*\*\s+\[(.+?)\](.*)\*\* Dealing Turn \*\*\s+\[(.+?)\](.*)\*\* Dealing River \*\*\s+\[(.+?)\](.*)";
            string[] __cleanM = new string[] { @"\>You\shave\soptions[^\n]*\n" };
            string[] __cleanR = new string[] { @"" };
            string __showncards = @"(\w+)\s+(shows|doesn\'t show)\s+\[\s+(\d|T|J|Q|K|A)(c|d|h|s),\s+(\d|T|J|Q|K|A)(c|d|h|s)\s+\](.+)\.";
            int __cardcount = 2;
            string __winner_alt = @"(\w+)\s+wins\s+\$(.+)";
            string __winner = @"(\w+)\s+wins\s+\$(.+)\s+from\s+(the\s+)*(\w+)\s+pot";
            string __winner_check = @"(\w+)\s+wins";
            string __heroalias = "HERO";
            string __heroaliason = "1";

            // cleanup
            for (int i = 0; i < __cleanM.Length; i++)
            {
                history = Regex.Replace(history, __cleanM[i], __cleanR[i]);
            }


            for (int i = 0, j = 0; i < __getTotalPlayers; i++)
            {
                if (__getPlayers[i]["PlayerName"].ToString() == __getHero)
                {
                    __getPlayers[i].Add("PlayerAlias", __heroalias);
                    __getPlayers[i].Add("PlayerAliasOn", __heroaliason);
                }
                if (Regex.IsMatch(history, __showncards))
                {
                    if (__getPlayers[i]["PlayerName"].ToString() == Regex.Match(history, __showncards).Groups[1].ToString())
                    {

                        // GEZEIGTE KARTEN DER ANDEREN SPIELER!!!!!!!!!!

                    }
                }
                //history = Regex.Replace(history, __getPlayers[i]["PlayerName"].ToString(), __getPlayers[i]["PlayerSeatTitle"].ToString());
            }

            if (Regex.IsMatch(history, __actions))
            {

            }


            __history = history;

        }

        private Stack arrToStack(string[] myStr)
        {
            Stack myStack = new Stack();
            if (myStr.Length > 0)
            {
                foreach (string sStr in myStr)
                {
                    myStack.Push(sStr);
                }
            }
            return myStack;
        }

    }
}

------------------------------------------------------------------------------------------------------------