Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string importPath = @"c:\Temp\import.txt";
            string exportPath = @"c:\Temp\export.txt";

            string[] readText = File.ReadAllLines(importPath);

            Parsing parsing = new Parsing();
            double  handID  = parsing.ParseHandId(readText);

            Players[] players = new Players[parsing.PlayersNumberParse(readText)];
            players = parsing.ParsePlayers(readText);

            StreamWriter str = new StreamWriter(exportPath);

            str.WriteLine($"HandID = {handID}");
            for (int i = 0; i < players.Length; i++)
            {
                str.WriteLine($"Seat #{players[i].SeatNumber}, Name: {players[i].PlayerName} , Stack: {players[i].StartingStack}");
            }
            str.Close();
        }
Ejemplo n.º 2
0
        public Players[] ParsePlayers(string[] handLines)
        {
            Parsing playersParsing = new Parsing();
            int     x = playersParsing.PlayersNumberParse(handLines);

            Players[] playerList = new Players[x];

            int  lastLineRead = -1;
            bool foundSeats   = false;



            for (int lineNumber = 2; lineNumber < handLines.Length - 1; lineNumber++)
            {
                string line = handLines[lineNumber].TrimEnd();



                if (!foundSeats && !line.StartsWith("Seat ") && line[6] != ':')
                {
                    continue;
                }
                else if (foundSeats && !line.StartsWith("Seat "))
                {
                    lastLineRead = lineNumber;
                    break;
                }
                foundSeats = true;

                char endChar = line[line.Length - 1];


                if (endChar != ')' && endChar != 't')
                {
                    lastLineRead = lineNumber;
                    break;
                }

                const int seatNumberStartIndex = 4;
                int       spaceIndex           = line.IndexOf(' ', seatNumberStartIndex);
                int       colonIndex           = line.IndexOf(':', spaceIndex + 1);
                int       seatNumber           = IntParse.Parse(line, spaceIndex + 1);

                int openParenIndex = line.LastIndexOf('(');

                if (line[openParenIndex + 1] == 'm')
                {
                    line           = line.Remove(openParenIndex);
                    openParenIndex = line.LastIndexOf('(');
                }

                int spaceAfterOpenParen = line.IndexOf(' ', openParenIndex);

                string playerName = line.Substring(colonIndex + 2, (openParenIndex - 1) - (colonIndex + 1));
                char   scopeIndex = line[openParenIndex + 1];
                if ((scopeIndex == '0') | (scopeIndex == '1') | (scopeIndex == '2') | (scopeIndex == '3') | (scopeIndex == '4') | (scopeIndex == '5') | (scopeIndex == '6') | (scopeIndex == '7') | (scopeIndex == '8') | (scopeIndex == '9'))
                {
                    string stackString = line.Substring(openParenIndex + 1, spaceAfterOpenParen - (openParenIndex + 1));
                    double stack       = Convert.ToDouble(stackString, CultureInfo.InvariantCulture);

                    playerList[lineNumber - 2] = new Players(playerName, stack, seatNumber);
                }
                else
                {
                    string stackString = line.Substring(openParenIndex + 2, spaceAfterOpenParen - (openParenIndex + 2));
                    double stack       = Convert.ToDouble(stackString, CultureInfo.InvariantCulture);

                    playerList[lineNumber - 2] = new Players(playerName, stack, seatNumber);
                }
            }



            return(playerList);
        }