Esempio n. 1
0
    private PokerRank GetPokerRank()
    {
        PokerRank pair     = CheckPair();
        PokerRank straight = CheckStraight();
        bool      flush    = CheckFlush();

        // Top
        if (pair == PokerRank.None && straight == PokerRank.None && !flush)
        {
            return(PokerRank.Top);
        }
        else if (straight != PokerRank.None)
        {
            // Flush, StraightFlush, BackStraightFlush, RoyalStraightFlush
            if (flush)
            {
                switch (straight)
                {
                case PokerRank.Straight:
                    return(PokerRank.StraightFlush);

                case PokerRank.BackStraight:
                    return(PokerRank.BackStraightFlush);

                case PokerRank.Mountain:
                    return(PokerRank.RoyalStraightFlush);

                case PokerRank.None:
                    return(PokerRank.Flush);
                }
            }
            // Straight, BackStraight, Mountain
            else
            {
                return(straight);
            }
        }
        else if (flush)
        {
            return(PokerRank.Flush);
        }
        // OnePair, TwoPair, Triple, FullHouse, FourCard
        else
        {
            return(pair);
        }

        return(PokerRank.None);
    }
Esempio n. 2
0
    private void SetBoardActive(bool active)
    {
        foreach (GameObject obj in boardObjects)
        {
            obj.SetActive(active);
        }

        foreach (GameObject obj in cards)
        {
            obj.SetActive(active);
            obj.transform.GetChild(0).gameObject.SetActive(active);
        }

        rank          = GetPokerRank();
        rankText.text = rank.ToString();
    }
Esempio n. 3
0
        /// <summary>
        /// Add one card to player.
        /// </summary>
        /// <param name="suit">suit.</param>
        /// <param name="rank">rank.</param>
        /// <returns>true if added <otherwise>false.</otherwise></returns>
        public bool AddCard(PokerSuit suit, PokerRank rank)
        {
            if ((int)rank >= 2 && !suit.Equals(PokerSuit.None))
            {
                if (_cardCount < MAX_CARDS)
                {
                    var indexCard = Array.IndexOf(Cards, ((suit, rank)));
                    if (indexCard == ELEMENT_NOT_EXIST)
                    {
                        Cards[_cardCount++] = new Card(suit, rank);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
    public void ChangeCard(int cardIndex)
    {
        int spriteIndex = suffledCardIndexs[0];

        GameObject card = cards[cardIndex];

        card.GetComponent <Image>().sprite = cardSprites[spriteIndex];

        Card cardData = card.GetComponent <Card>();

        cardData.Init(spriteIndex / cardCountbyShape, spriteIndex % cardCountbyShape);

        suffledCardIndexs.Remove(spriteIndex);

        card.transform.GetChild(0).gameObject.SetActive(false);

        rank          = GetPokerRank();
        rankText.text = rank.ToString();
    }
Esempio n. 5
0
        public PokerRank Evaluate()
        {
            handRank = PokerRank.Nothing;

            if (cards.Count() < 5)
            {
                return(handRank);
            }

            cards.Sort();

            var groupedRank = cards
                              .GroupBy(u => u.Rank)
                              .OrderBy(k => k.Key)
                              .ToDictionary(group => group.Key, group => group.Count());

            var quads = groupedRank.ContainsValue(4);
            var trips = groupedRank.ContainsValue(3);
            var pair  = groupedRank.ContainsValue(2);
            var pairs = groupedRank.Where(g => g.Value == 2)
                        .Select(g => g.Key);

            var groupedSuit = cards
                              .GroupBy(u => u.Suit)
                              .ToDictionary(group => group.Key, group => group.Count());

            var flush    = groupedSuit.ContainsValue(5);
            var sum      = ((int)cards[4].Rank - (int)cards[0].Rank);
            var straight = (((int)cards[4].Rank - (int)cards[0].Rank) == 4) ? true : false;

            // Check for a wheel Straight
            if (cards[4].Rank == Card.enumRank.Ace &&
                cards[0].Rank == Card.enumRank.Two &&
                cards[0].Rank == Card.enumRank.Three &&
                cards[0].Rank == Card.enumRank.Four &&
                cards[0].Rank == Card.enumRank.Five)
            {
                straight = true;
            }

            if (straight && flush && cards[4].Rank == Card.enumRank.Ace)
            {
                handRank = PokerRank.Royal;
            }
            else if (straight && flush)
            {
                handRank = PokerRank.StraightFlush;
            }
            else if (quads)
            {
                handRank = PokerRank.Quads;
            }
            else if (trips && pair)
            {
                handRank = PokerRank.Boat;
            }
            else if (flush)
            {
                handRank = PokerRank.Flush;
            }
            else if (straight)
            {
                handRank = PokerRank.Straight;
            }
            else if (trips)
            {
                handRank = PokerRank.Set;
            }
            else if (pairs.Count() > 1)
            {
                handRank = PokerRank.TwoPair;
            }
            else if (pair)
            {
                handRank = PokerRank.Pair;
            }

            return(handRank);
        }
Esempio n. 6
0
 public void Reset()
 {
     rank = PokerRank.Rank_4;
     type = PokerType.Type_Unknown;
 }
Esempio n. 7
0
 public void Deconstruct(out PokerSuit suit, out PokerRank rank)
 {
     suit = Suit;
     rank = Rank;
 }
Esempio n. 8
0
 public Card(PokerSuit suit, PokerRank rank)
 {
     Suit = suit;
     Rank = rank;
 }