Esempio n. 1
0
        /// <summary>
        /// 存放要牌操作
        /// </summary>
        /// <param name="handCards"></param>
        /// <returns></returns>
        public OptionorCollection FreshOptions(HandCardManager handCards)
        {
            handCards.Optionors.Clear();
            MaJiangCollection huCards = GetHuCards(handCards.StandCards);

            if (huCards.Count > 0)
            {
                for (int i = 0; i < huCards.Count; i++)
                {
                    Optionor optionor = new Optionor(new OptionHu(), huCards[i]);
                    handCards.AddOptionor(optionor);
                }
            }
            MaJiangCollection PendCards = handCards.GetPengCards();

            if (PendCards.Count > 0)
            {
                for (int i = 0; i < PendCards.Count; i++)
                {
                    Optionor optionor = new Optionor(new OptionPeng(), PendCards[0]);
                    handCards.AddOptionor(optionor);
                }
            }
            MaJiangCollection GangCards = handCards.GetGangCards();

            if (GangCards.Count > 0)
            {
                for (int i = 0; i < GangCards.Count; i++)
                {
                    Optionor optionor = new Optionor(new OptionGang(), GangCards[i]);
                    handCards.AddOptionor(optionor);
                }
            }
            return(handCards.Optionors);
        }
Esempio n. 2
0
        public bool  Do(HandCardManager handCards, CardModel card)
        {
            MaJiangCollection cards = handCards.SleepCards.FindThree(card);

            ///杠自己碰的牌
            if (!(cards is null))
            {
                if (handCards.IstheSameWhithPikedCard(card))
                {
                    cards.Add(handCards.CardPicked);
                    handCards.SetCardPicked(null);

                    return(true);
                }
            }
            cards = handCards.StandCards.GetSameCards(card, 4);
            //暗杠
            if (!(cards is null))
            {
                handCards.StandCards.RemoveAll(c => c.IsTheSameWith(card));
                handCards.SleepCards.Add(cards);
                return(true);
            }
            cards = handCards.StandCards.GetSameCards(card, 3);
            if (!(cards is null) && handCards.CardPicked.IsTheSameWith(card))
            {
                cards.Add(handCards.CardPicked);
                handCards.SetCardPicked(null);
                handCards.StandCards.RemoveAll(c => c.IsTheSameWith(card));
                handCards.SleepCards.Add(cards);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// 排序
        /// </summary>
        public MaJiangCollection SortByColorThenNameDesc()
        {
            MaJiangCollection majiangs = new MaJiangCollection();
            var temp = this.OrderByDescending(c => c.CardColor).ThenByDescending(c => c.Name).ToList <Card>();

            majiangs.AddRange(temp);
            return(majiangs);
        }
        /// <summary>
        /// 获得搭子需要的牌
        /// </summary>
        /// <param name="maJiangs"></param>
        /// <returns></returns>
        public MaJiangCollection GetMatchedCards()
        {
            if (this.Count > 2)
            {
                throw new ArgumentOutOfRangeException("只能处理一到两张牌");
            }
            MaJiangCollection matchedMajiangs = new MaJiangCollection();

            if (this.Count == 1)
            {
                matchedMajiangs.Add(this[0]);
                return(matchedMajiangs);
            }
            var tempMaJiangCollection = this.SortByColorThenName();
            var preCard   = tempMaJiangCollection[0];
            var afterCard = tempMaJiangCollection[1];

            if (preCard.CardColor != afterCard.CardColor)
            {
                return(matchedMajiangs);
            }
            if (preCard.Name == afterCard.Name)
            {
                matchedMajiangs.Add(preCard);
                return(matchedMajiangs);
            }
            if (preCard.ComparedValue + 2 == afterCard.ComparedValue)
            {
                var card = CreatAfterCard(preCard);
                matchedMajiangs.Add(card);
                return(matchedMajiangs);
            }
            if (preCard.ComparedValue + 1 == afterCard.ComparedValue)
            {
                if (preCard.ComparedValue == 0)
                {
                    Card card = CreatAfterCard(afterCard);
                    matchedMajiangs.Add(card);
                    return(matchedMajiangs);
                }
                else if (afterCard.ComparedValue == 8)
                {
                    Card card = CreatPreCard(preCard);
                    matchedMajiangs.Add(card);
                    return(matchedMajiangs);
                }
                else
                {
                    Card myPreCard   = CreatPreCard(preCard);
                    Card myAfterCard = CreatAfterCard(afterCard);
                    matchedMajiangs.Add(myPreCard);
                    matchedMajiangs.Add(myAfterCard);
                    return(matchedMajiangs);
                }
            }
            return(matchedMajiangs);
        }
        /// <summary>
        /// 移牌(抢杠)
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        internal Card RemoveCardByGrapGang(CardModel card)
        {
            MaJiangCollection majiangs = FindFour(card);

            if (majiangs is null)
            {
                throw new KeyNotFoundException("没有一组4张相同的牌");
            }
            return(majiangs[3]);
        }
Esempio n. 6
0
        public bool Do(HandCardManager handCards, Card card)
        {
            MaJiangCollection majians = handCards.StandCards.GetSameCards(card, 2);

            if (!(majians is null))
            {
                handCards.StandCards.RemoveCountOf(card, 2);
                majians.Add(card);
                handCards.SleepCards.Add(majians);
            }

            return(false);
        }
        /// <summary>
        /// 获得可杠的牌的列表
        /// </summary>
        /// <returns></returns>
        internal MaJiangCollection FindAllThree()
        {
            MaJiangCollection majiangs = new MaJiangCollection();

            for (int i = 0; i < SleepMajiangs.Count; i++)
            {
                var item = SleepMajiangs[i];
                if (item.IsThreeSame())
                {
                    majiangs.Add(item[0]);
                }
            }
            return(majiangs);
        }
        /// <summary>
        /// 获得相同的牌n张
        /// </summary>
        /// <param name="card"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public MaJiangCollection GetSameCards(CardModel card, int n)
        {
            MaJiangCollection majians = new MaJiangCollection();
            var cards = this.FindAll(c => c.IsTheSameWith(card));

            if (cards.Count >= n)
            {
                for (int i = 0; i < 3; i++)
                {
                    majians.Add(cards[i]);
                }
                return(majians);
            }
            return(null);
        }
        /// <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);
        }
        /// <summary>
        /// 去将,从牌中移除一对牌
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        public MaJiangCollection RemoveCountOf(Card card, int count)
        {
            MaJiangCollection majiangs = new MaJiangCollection();
            int k = count;

            for (int j = 0; j < this.Count; j++)
            {
                if (this[j].IsTheSameWith(card) && k > 0)
                {
                    k--;
                    continue;
                }
                majiangs.Add(this[j]);
            }
            return(majiangs);
        }
        /// <summary>
        /// 移除多张牌
        /// </summary>
        /// <param name="cardM"></param>
        /// <param name="n"></param>
        internal MaJiangCollection  RemoveCountOfCards(CardModel cardM, int n)
        {
            MaJiangCollection majiangs = new MaJiangCollection();

            for (int i = base.Count - 1; i >= 0; i--)
            {
                if (base[i].IsTheSameWith(cardM))
                {
                    majiangs.Add(base[i]);
                    base.Remove(base[i]);
                    n--;
                    if (n == 0)
                    {
                        break;
                    }
                }
            }
            return(majiangs);
        }
        /// <summary>
        /// 逆序获得牌中不能组合成顺子或豹子的牌
        /// </summary>
        /// <returns></returns>
        public List <MaJiangCollection> GetMatchedCardsDescCollection()
        {
            var tempMaJiangCollection = this.SortByColorThenNameDesc();
            List <MaJiangCollection> matchedCardsColleciton = new List <MaJiangCollection>();
            MaJiangCollection        checkCards             = new MaJiangCollection();

            if (tempMaJiangCollection.Count == 1)
            {
                checkCards.Add(tempMaJiangCollection[0]);
                matchedCardsColleciton.Add(checkCards);
                return(matchedCardsColleciton);
            }
            if (this.Count == 2)
            {
                checkCards.Add(tempMaJiangCollection[0]);
                checkCards.Add(tempMaJiangCollection[1]);
                if (checkCards.IsMachtedCards())
                {
                    matchedCardsColleciton.Add(checkCards);
                }
                else
                {
                    checkCards.RemoveAt(1);
                }
                return(matchedCardsColleciton);
            }
            int k = 2;

            for (int i = 0; i < tempMaJiangCollection.Count; i++)
            {
                MaJiangCollection myCheckCards = new MaJiangCollection();
                if (k == 0)
                {
                    break;
                }
                if (tempMaJiangCollection.Count - i == 1)
                {
                    myCheckCards.Add(tempMaJiangCollection[i]);
                    matchedCardsColleciton.Add(myCheckCards);
                    return(matchedCardsColleciton);
                }
                if (tempMaJiangCollection.Count - i == 2)
                {
                    myCheckCards.Add(tempMaJiangCollection[i]);
                    myCheckCards.Add(tempMaJiangCollection[i + 1]);
                    if (!myCheckCards.IsMachtedCardsDesc())
                    {
                        myCheckCards.RemoveAt(1);
                        matchedCardsColleciton.Add(myCheckCards);
                        k--;
                        continue;
                    }
                    else
                    {
                        matchedCardsColleciton.Add(myCheckCards);
                        k--;
                        return(matchedCardsColleciton);
                    }
                }
                myCheckCards.Add(tempMaJiangCollection[i]);
                myCheckCards.Add(tempMaJiangCollection[i + 1]);
                myCheckCards.Add(tempMaJiangCollection[i + 2]);
                if (myCheckCards.IsThreeDesc())
                {
                    i = i + 2;
                }
                else
                {
                    myCheckCards.RemoveAt(2);
                    i = i + 1;
                    if (!myCheckCards.IsMachtedCardsDesc())
                    {
                        myCheckCards.RemoveAt(1);
                        i = i - 1;
                    }
                    matchedCardsColleciton.Add(myCheckCards);
                    k--;
                }
            }
            return(matchedCardsColleciton);
        }
Esempio n. 13
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);
        }
 /// <summary>
 /// 添加碰,杠,吃的一组牌
 /// </summary>
 /// <param name="majiangs"></param>
 internal void Add(MaJiangCollection majiangs)
 {
     SleepMajiangs.Add(majiangs);
 }