示例#1
0
 private void SetHandType(GroupCards[] gc, bool sameColor)
 {
     // Get 4 value
     this.FourValue = gc.SingleOrDefault(x => x.CardCount == 4);
     // Get 3 value
     this.ThreeValue = gc.SingleOrDefault(x => x.CardCount == 3);
     // Get 2 values
     this.PairValues = gc.Where(x => x.CardCount == 2).OrderByDescending(x => x.CardNumber).ToArray();
     // Get 1 values
     this.SingleValues = gc.Where(x => x.CardCount == 1).OrderByDescending(x => x.CardNumber).ToArray();
     // Four of a kind
     if (this.FourValue != null)
     {
         this.HandType = HandType.FourOfAKind;
         return;
     }
     // Full House
     if (this.ThreeValue != null && this.PairValues.Count() == 1)
     {
         this.HandType = HandType.FullHouse;
         return;
     }
     // Three of a kind
     if (this.ThreeValue != null && this.PairValues.Count() == 0)
     {
         this.HandType = HandType.ThreeOfAKind;
         return;
     }
     // Two pairs
     if (this.PairValues.Count() == 2)
     {
         this.HandType = HandType.TwoPairs;
         return;
     }
     // One pair
     if (this.PairValues.Count() == 1 && this.ThreeValue == null)
     {
         this.HandType = HandType.OnePair;
         return;
     }
     // Flush & High card
     if (gc.Count() == 5)
     {
         int        diff   = 1;
         GroupCards tempgc = new GroupCards();
         for (int i = 0; i < gc.Count(); i++)
         {
             if (i == 0)
             {
                 tempgc = gc[i];
                 continue;
             }
             diff   = gc[i].CardNumber - tempgc.CardNumber;
             tempgc = gc[i];
             if (diff != 1)
             {
                 if (sameColor)
                 {
                     this.HandType = HandType.Flush;
                     return;
                 }
                 this.HandType = HandType.HighCard;
                 return;
             }
         }
         // Royal flush
         if (sameColor && gc[0].CardNumber == 10)
         {
             this.HandType = HandType.RoyalFlush;
             return;
         }
         // Straight flush && straight
         if (sameColor)
         {
             this.HandType = HandType.StraightFlush;
             return;
         }
         else
         {
             this.HandType = HandType.Straight;
             return;
         }
     }
     throw new Exception("Unknown hand type");
 }
示例#2
0
 private void SetHandType(GroupCards[] gc, bool sameColor)
 {            
     // Get 4 value
     this.FourValue = gc.SingleOrDefault(x=>x.CardCount == 4);
     // Get 3 value
     this.ThreeValue = gc.SingleOrDefault(x=>x.CardCount == 3);
     // Get 2 values
     this.PairValues = gc.Where(x=>x.CardCount == 2).OrderByDescending(x=>x.CardNumber).ToArray();
     // Get 1 values
     this.SingleValues = gc.Where(x=>x.CardCount == 1).OrderByDescending(x=>x.CardNumber).ToArray();
     // Four of a kind
     if(this.FourValue != null){
         this.HandType = HandType.FourOfAKind;
         return;
     }
     // Full House
     if(this.ThreeValue != null && this.PairValues.Count() == 1){
         this.HandType = HandType.FullHouse;
         return;
     }
     // Three of a kind
     if(this.ThreeValue != null && this.PairValues.Count() == 0){
         this.HandType = HandType.ThreeOfAKind;
         return;
     }
     // Two pairs
     if(this.PairValues.Count() == 2){
         this.HandType = HandType.TwoPairs;
         return;
     }
     // One pair
     if(this.PairValues.Count() == 1 && this.ThreeValue == null){
         this.HandType = HandType.OnePair;
         return;
     }
     // Flush & High card
     if (gc.Count() == 5)
     {
         int diff = 1;
         GroupCards tempgc = new GroupCards();
         for (int i = 0; i < gc.Count(); i++)
         {
             if (i == 0)
             {
                 tempgc = gc[i];
                 continue;
             }
             diff = gc[i].CardNumber - tempgc.CardNumber;
             tempgc = gc[i];
             if (diff != 1)
             {
                 if (sameColor)
                 {
                     this.HandType = HandType.Flush;
                     return;
                 }
                 this.HandType = HandType.HighCard;
                 return;
             }
         }
         // Royal flush
         if (sameColor && gc[0].CardNumber == 10)
         {
             this.HandType = HandType.RoyalFlush;
             return;
         }
         // Straight flush && straight
         if (sameColor)
         {
             this.HandType = HandType.StraightFlush;
             return;
         }
         else
         {
             this.HandType = HandType.Straight;
             return;
         }
     }
     throw new Exception("Unknown hand type");
 }