Esempio n. 1
0
 public Deck()
 {
     int cnt = 0;
     cards = new Card[52];
     for (int i = 2; i < 15; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             cards[cnt] = new Card((Suit)j, (Value)i);
             cnt++;
         }
     }
     numberOfCards = 51;
 }
Esempio n. 2
0
        public static PokerHandValue getPokerHand(Card[] hand)
        {
            // record how many of each rank we have
            int[] rank = new int[15];
            PokerHandValue _pokerHandValue = new PokerHandValue();
            _pokerHandValue.pokerHand = PokerHand.None;
            _pokerHandValue.rank1 = Value.Two;
            _pokerHandValue.rank2 = Value.Two;

            for (int i = 0; i < hand.Length; i++)
            {
                rank[hand[i].value]++;
            }
            int sameCards = 1, sameCards2 = 1;
            //int firstValue = 0, secondValue = 0;
            for (int i = 2; i < 15; i++)
            {
                if (rank[i] > sameCards)
                {
                    if (sameCards != 1)
                    {
                        sameCards2 = sameCards;
                        _pokerHandValue.rank2 = _pokerHandValue.rank1;
                    }
                    sameCards = rank[i];
                    _pokerHandValue.rank1 = (Value)i;
                }
                else if (rank[i] > sameCards2)
                {
                    sameCards2 = rank[i];
                    _pokerHandValue.rank2 = (Value)i;
                }
            }

            if (sameCards2 == 1)
            {
                if (sameCards == 2)
                    _pokerHandValue.pokerHand = PokerHand.OnePair;
                else if (sameCards == 3)
                    _pokerHandValue.pokerHand = PokerHand.ThreeOfaKind;
                else if (sameCards == 4)
                    _pokerHandValue.pokerHand = PokerHand.FourOfaKind;

            }
            else if (sameCards2 == 2)
            {
                if (sameCards == 2)
                    _pokerHandValue.pokerHand = PokerHand.TwoPair;
                else if (sameCards == 3)
                    _pokerHandValue.pokerHand = PokerHand.FullHouse;

            }
            else if (sameCards2 == 3)
            {
                if (sameCards == 2)
                    _pokerHandValue.pokerHand = PokerHand.FullHouse;
            }

            if (sameCards == 1)
            {
                bool straight = true;
                bool flush = true;
                if (hand[0].value <= 10)
                {
                    for (int i = 0; i < hand.Length - 1; i++)
                    {
                        if (hand[i].value != hand[i + 1].value - 1)
                            straight = false;
                        if (hand[i].suit != hand[i + 1].suit)
                            flush = false;
                    }
                }
                if (straight && flush)
                {
                    if (hand[0].value == 10 && hand[0].suit == (int)Suit.Spades)
                        _pokerHandValue.pokerHand = PokerHand.RoyalFlush;
                    else
                    {
                        _pokerHandValue.pokerHand = PokerHand.StraightFlush;
                        _pokerHandValue.rank1 = (Value)hand[0].value;
                        _pokerHandValue.rank2 = (Value)hand[4].value;

                    }
                }
                if (straight && !flush)
                {
                    _pokerHandValue.pokerHand = PokerHand.Straight;
                    _pokerHandValue.rank1 = (Value)hand[0].value;
                    _pokerHandValue.rank2 = (Value)hand[4].value;
                }
                if (!straight && flush)
                {
                    _pokerHandValue.pokerHand = PokerHand.Flush;
                    _pokerHandValue.rank1 = (Value)hand[0].value;
                    _pokerHandValue.rank2 = (Value)hand[4].value;
                }

            }

            return _pokerHandValue;
        }
Esempio n. 3
0
 public Player(string _name)
 {
     Name = _name;
     id = numberOfPlayers++;
     Hand = new Card[5];
 }
Esempio n. 4
0
 // Methods
 public void addCardToHand(Card _card)
 {
     Hand[numberOfCards++] = _card;
 }
Esempio n. 5
0
 // Constructors
 public Player()
 {
     Name = "Default";
     id = numberOfPlayers++;
     Hand = new Card[5];
 }