예제 #1
0
        public static HandsetModel SetsOfThree(HandModel hand)
        {
            HandsetModel setsOf3 = new HandsetModel();

            for (int x = 0; x < 5; x++)
            {
                for (int y = x + 1; y < 5; y++)
                {
                    for (int z = y + 1; z < 5; z++)
                    {

                        setsOf3.Hands.Add(new HandModel(new CardModel[] { hand.Cards[x], hand.Cards[y], hand.Cards[z] }));
                    }
                }
            }

            return setsOf3;
        }
예제 #2
0
        public static HandsetModel SetsOfTwo(HandModel hand)
        {
            HandsetModel setsOf2 = new HandsetModel();

            for (int x = 0; x < 5; x++)
            {
                for (int y = x + 1; y < 5; y++)
                {

                    setsOf2.Hands.Add(new HandModel(new CardModel[] { hand.Cards[x], hand.Cards[y] }));


                }

            }

            return setsOf2;
        }
예제 #3
0
        public static HandsetModel SetsOfFour(HandModel hand)
        {
            HandsetModel setsOf4 = new HandsetModel();

            for (int x = 0; x < 2; x++)
            {
                for (int y = x + 1; y < 3; y++)
                {
                    for (int z = y + 1; z < 4; z++)
                    {
                        for (int w = z + 1; w < 5; w++)
                        {

                            setsOf4.Hands.Add(new HandModel(new CardModel[] { hand.Cards[x], hand.Cards[y], hand.Cards[z], hand.Cards[w] }));
                        }
                    }
                }
            }

            return setsOf4;
        }
       private void CheckForMatches(HandsetModel hands)
       {
           foreach (HandModel c in hands.Hands)
           {
               if (c.Cards.All(x => x.CardNumber == c.Cards[0].CardNumber))
               {
                   if (c.Cards.Count == 4)
                   {
                    ScoringCombos.Add(ScoringHandModel.FourOfAKind(c));
                    return;
                   }


                   if (c.Cards.Count == 3)
                   {
                    ScoringCombos.Add(ScoringHandModel.ThreeOfAKind(c));
                    continue;
                   }

                   if (c.Cards.Count == 2 && !(ScoringCombos.Any(x => x.ScoreType == ScoringHandModel.ScoringType.ThreeOfAKind && x.Cards[0].CardNumber == c.Cards[0].CardNumber)))
                   {
                       ScoringCombos.Add(ScoringHandModel.Pair(c));
                       
                   }
               }
           }
       }
       private void CheckFor15s(HandsetModel hands)
       {
           foreach (HandModel c in hands.Hands)
           {

               if (c.Cards.Sum(x => x.CardValue) == 15)
               {

                   ScoringCombos.Add(ScoringHandModel.Fifteen(c));
               }
           }
       }
        private void CheckForRuns(HandsetModel hands)
       {
           foreach (HandModel handtocheck in hands.Hands)
           {
            var handArray = handtocheck.Cards.OrderBy(x => (int)x.CardNumber).Select(x => (int)x.CardNumber).ToArray();
           

          int min = handtocheck.Cards.Min(x => (int)x.CardNumber);
          int max = handtocheck.Cards.Count;
         
          var range = Enumerable.Range(min, max).ToArray();

          var result = ArraysEqual(range, handArray);
          
               if (result)
              {
              
                   switch (handtocheck.Cards.Count)
              
                   {
                  case 5:
                      ScoringCombos.Add(ScoringHandModel.RunOfFive(handtocheck));
                      return;
                  case 4:
                      ScoringCombos.Add(ScoringHandModel.RunOfFour(handtocheck));
                      break;
                  case 3:
                      if (ScoringCombos.Any(x => x.ScoreType == ScoringHandModel.ScoringType.RunOfFour))
                          return;
                      ScoringCombos.Add(ScoringHandModel.RunOfThree(handtocheck));
                      break;
              
                   }
          
               }

           }       
           
           
        
       }
        public  ObservableCollection<ScoringHandModel> CountHands(HandModel hand)
        {


            ScoringCombos.Clear();
            

            

            //Get Sets of 2,3,4 and 5 is just hand            

            HandsetModel allHands = new HandsetModel();

            allHands.Hands.Add(hand);
            allHands.Hands.AddRange(HandsetModel.SetsOfFour(hand).Hands);
            allHands.Hands.AddRange(HandsetModel.SetsOfThree(hand).Hands);
            allHands.Hands.AddRange(HandsetModel.SetsOfTwo(hand).Hands);
            
            //Check 15s First

            

            

            CheckFor15s(allHands);


            CheckForMatches(allHands);
            
            
            
                //Check for Runs



            CheckForRuns(allHands);
                

                      
                
                        
                    
                //Check For Flush
                if (hand.Cards.All(x => x.Suit == hand.Cards[0].Suit))
                {
                    ScoringCombos.Add(ScoringHandModel.Flush(hand));
                }
            

            

            
          //  player.Score += score;
                return ScoringCombos;
            
        }