예제 #1
0
            /*********************************************************************/
            /************************** UTILITY METHODS **************************/
            /*********************************************************************/

            /// <summary>
            /// Assumes all BuildNames are extracted beforehand (example: alpha, beta). Run
            /// ExtractBuildNamesFromString() if there is uncertainty.
            /// </summary>
            private static List <byte> ExtractCardsFromString(string cmd)
            {
                cmd = cmd.Replace("10", "T");
                string      remain = cmd;
                List <byte> result = new List <byte>();

                while (remain.Length > 0)
                {
                    if (!charcardValAbbr.Contains(char.ToUpper(remain[0])))
                    {
                        throw new UnparseableMoveException(Errorstr.CardFormat(), cmd);
                    }
                    if (remain.Length > 1 && cardSuitAbbrAscii.Contains(remain[1]))   //example 5h
                    {
                        result.Add(ExtractCardFromString(remain.Substring(0, 2)));
                        remain = remain.Substring(2);
                    }
                    else     //examples 9, 92 (only parses 9 in both scenarios)
                    {
                        result.Add(ExtractCardFromString(remain.Substring(0, 1)));
                        remain = remain.Substring(1);
                    }
                }
                return(result);
            }
예제 #2
0
            private static byte ExtractCardFromString(string cmd)
            {
                cmd = cmd.Replace("10", "T");
                cmd = cmd.ToLower();
                if (cmd.Length < 1 || cmd.Length > 2)
                {
                    throw new UnparseableMoveException(Errorstr.CardFormat(), cmd);
                }

                CardVals  value    = CardVals.NONE;
                CardSuits suit     = CardSuits.NONE;
                char      cmdValue = cmd[0];
                char      cmdSuit  = '\0';

                if (cmd.Length == 2)
                {
                    cmdSuit = cmd[1];
                }
                foreach (CardVals val in Enum.GetValues(typeof(CardVals)))
                {
                    char valabbr = char.ToLower(GetCardValAbbr((byte)val, true)[0]);
                    if (valabbr == cmdValue)
                    {
                        value = val; break;
                    }
                }
                if (value == CardVals.NONE)
                {
                    throw new UnparseableMoveException(Errorstr.CardFormat(), cmd);
                }

                if (cmdSuit != '\0')
                {
                    cmdSuit = char.ToLower(cmdSuit);
                    foreach (CardSuits suitf in Enum.GetValues(typeof(CardSuits)))
                    {
                        char suitabbr = GetCardSuitAbbr((byte)suitf, true);
                        if (suitabbr == cmdSuit)
                        {
                            suit = suitf; break;
                        }
                    }
                    if (suit == CardSuits.NONE)
                    {
                        throw new UnparseableMoveException("Invalid suit provided to a card", cmd);
                    }
                }

                byte result = GetCardDigit(value, suit);

                return(result);
            }