コード例 #1
0
ファイル: Problem054.cs プロジェクト: cpvoinea/ProjectEuler
        bool Check(Card[] cards)
        {
            Hand player1 = new Hand();
            Hand player2 = new Hand();
            for (int i = 0; i < 10; i++)
                if (i < 5)
                    player1.AddCard(cards[i]);
                else
                    player2.AddCard(cards[i]);
            if (player1.Type != player2.Type)
                return (int)player1.Type > (int)player2.Type;

            if (player1.Type == HandType.RoyalFlush)
                return true;
            if (player1.Type == HandType.StraightFlush || player1.Type == HandType.Flush || player1.Type == HandType.Straight || player1.Type == HandType.Nothing)
            {
                if (player1.HighCard > player2.HighCard)
                    return true;
                if (player1.HighCard == player2.HighCard)
                    return true;
                return false;
            }
            if (player1.Type == HandType.ThreeOfAKind || player1.Type == HandType.OnePair)
            {
                if (player1.MaxCard > player2.MaxCard)
                    return true;
                if (player1.MaxCard == player2.MaxCard)
                {
                    if (player1.HighCard > player2.HighCard)
                        return true;
                    if (player1.HighCard == player2.HighCard)
                        return true;
                    return false;
                }
                return false;
            }
            if (player1.Type == HandType.FourOfAKind || player1.Type == HandType.FullHouse || player1.Type == HandType.TwoPair)
            {
                if (player1.MaxCard > player2.MaxCard)
                    return true;
                if (player1.MaxCard == player2.MaxCard)
                {
                    if (player1.SecondCard > player2.SecondCard)
                        return true;
                    if (player1.SecondCard == player2.SecondCard)
                    {
                        if (player1.HighCard > player2.HighCard)
                            return true;
                        if (player1.HighCard == player2.HighCard)
                            return true;
                        return false;
                    }
                }
                return false;
            }
            return false;
        }
コード例 #2
0
ファイル: Problem054.cs プロジェクト: cpvoinea/ProjectEuler
            public void AddCard(Card c)
            {
                if (c.Value > highestCard)
                    highestCard = c.Value;
                if (c.Value < lowCard)
                    lowCard = c.Value;
                count[c.Value]++;
                suit[c.Suit]++;

                int cv = count[c.Value];
                if (cv > maxCount)
                {
                    maxCount = cv;
                    MaxCard = c.Value;
                }

                Cards.Add(c);
            }