/// <summary>
        /// 找出相同数量的牌
        /// </summary>
        /// <param name="n">相同数量</param>
        /// <returns>有相同数量牌的集合</returns>
        public MaJiangCollection FindTheSameCards(int n)
        {
            MaJiangCollection cards = new MaJiangCollection();

            for (int i = 0; i < this.Count; i++)
            {
                var card         = this[i];
                var theSameCards = this.FindAll(c => c.Name == card.Name && c.CardColor == card.CardColor);
                if (theSameCards.Count >= n && !cards.Exists(c => c.Name == card.Name && c.CardColor == card.CardColor))
                {
                    cards.Add(card);
                }
            }
            return(cards);
        }
示例#2
0
        /// <summary>
        /// 获得可以胡的牌
        /// </summary>
        /// <returns></returns>
        public virtual MaJiangCollection GetHuCards(MaJiangCollection maJiangs)
        {
            List <Card>       HuCards = new MaJiangCollection();
            MaJiangCollection doubleCards;

            doubleCards = maJiangs.FindTheSameCards(2);
            List <MaJiangCollection> matchedCards = new List <MaJiangCollection>();

            if (doubleCards.Count > 0)
            {
                for (int i = 0; i < doubleCards.Count; i++)
                {
                    MaJiangCollection tempMajiangs = new MaJiangCollection();
                    tempMajiangs.AddRange(maJiangs);
                    tempMajiangs = tempMajiangs.RemoveCountOf(doubleCards[i], 2);
                    List <MaJiangCollection> matchedCardsNeed = tempMajiangs.GetMatchedCardsCollection();
                    if (matchedCardsNeed.Count == 1)
                    {
                        matchedCards.Add(matchedCardsNeed[0]);
                    }
                    List <MaJiangCollection> matchedCardsNeedDesc = tempMajiangs.GetMatchedCardsDescCollection();
                    if (matchedCardsNeedDesc.Count == 1)
                    {
                        matchedCards.Add(matchedCardsNeedDesc[0]);
                    }
                }
            }
            for (int i = 0; i < maJiangs.Count; i++)
            {
                MaJiangCollection tempMajiangs = new MaJiangCollection();
                tempMajiangs.AddRange(maJiangs);
                MaJiangCollection tempOneCard = new MaJiangCollection {
                    maJiangs[i]
                };
                tempMajiangs = tempMajiangs.RemoveCountOf(maJiangs[i], 1);

                List <MaJiangCollection> matchedCardsNeed = tempMajiangs.GetMatchedCardsCollection();
                if (matchedCardsNeed.Count == 0)
                {
                    matchedCards.Add(tempOneCard);
                }
                List <MaJiangCollection> matchedCardsNeedDesc = tempMajiangs.GetMatchedCardsDescCollection();
                if (matchedCardsNeedDesc.Count == 0)
                {
                    matchedCards.Add(tempOneCard);
                }
            }
            if (matchedCards.Count > 0)
            {
                for (int i = 0; i < matchedCards.Count; i++)
                {
                    HuCards.AddRange(matchedCards[i].GetMatchedCards());
                }
            }
            MaJiangCollection husdistnct = new MaJiangCollection();

            if (HuCards.Count == 0)
            {
                return(husdistnct);
            }
            int k = 0;

            do
            {
                husdistnct.Add(HuCards[k]);
                k++;
            } while (!husdistnct.Exists(c => c.IsTheSameWith(HuCards[k])) &&
                     k < HuCards.Count
                     );
            return(husdistnct);
        }