All pastes #262481 Raw Edit

aLFie

public text v1 · immutable
#262481 ·published 2006-11-30 16:08 UTC
rendered paste body
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace HandRecorderPS.parser
{
    class Players
    {
        private Dictionary<int, Dictionary<string, string>> __getPlayers;
        public Dictionary<int, Dictionary<string, string>> _getPlayers
        {
            get { return __getPlayers; }
            set { __getPlayers = value; }
        }
        public void getPlayers(string history)
        {
            Regex rx;
            MatchCollection mc;
            Dictionary<int, Dictionary<string, string>> players = new Dictionary<int, Dictionary<string, string>>();
            
            // 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";


            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);

            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) && (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)
                {
                    i = 0;
                    x++;
                }
                else
                {
                    i++;
                }
            }

            __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 Stack arrToStack(string[] myStr)
        {
            Stack myStack = new Stack();
            if (myStr.Length > 0)
            {
                foreach (string sStr in myStr)
                {
                    myStack.Push(sStr);
                }
            }
            return myStack;
        }
    }
}