예제 #1
0
 /// <summary>
 /// Method for sorting game results in ascending and alphabetical order.
 /// Check the weight of the final hand, if the total is the same,
 /// check the final cards by seniority, if the cards are the same,
 /// then arrange the players in alphabetical order
 /// </summary>
 /// <param name="resultGame">List result game</param>
 /// <returns>Sort list result game</returns>
 public static List <ResultGame> SortCardsResult(List <ResultGame> resultGame)
 {
     return(resultGame.OrderBy(x => x.HandValue).ThenBy(y => y.ResultHand[0].Value)
            .ThenBy(y => y.ResultHand[1].Value).ThenBy(y => y.ResultHand[2].Value)
            .ThenBy(y => y.ResultHand[3].Value).ThenBy(y => y.ResultHand[4].Value)
            .ThenBy(y => Converts.ConvertValueString(y.PlayerCards[0].Value)).ThenBy(y => y.PlayerCards[0].Suit).ToList());
 }
예제 #2
0
        //Method generates cards
        private static List <Card> ParseCard(GameType type, string[] splitText, int i)
        {
            var cardCount = type switch
            {
                GameType.Holdem => 2,
                GameType.Omaha => 4,
                GameType.FiveCard => 5,
                _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
            };

            var chars = splitText[i].ToCharArray();

            if (cardCount * 2 != chars.Length)
            {
                return(null);
            }

            var card = new List <Card>();

            for (var j = 0; j < cardCount * 2; j = j + 2)
            {
                if (chars[j + 1] == 'h' || chars[j + 1] == 'd' || chars[j + 1] == 'c' || chars[j + 1] == 's')
                {
                    if (Converts.ConvertValue(chars[j].ToString()) != 0)
                    {
                        card.Add(new Card
                        {
                            Value = Converts.ConvertValue(chars[j].ToString()), Suit = chars[j + 1]
                        });
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(card);
        }
    }