//比较牌的大小
        public static bool CompareSize <T>(int lastPlayCardType, T lastHandsNum, T playHandsNum) where T : IList <int>
        {
            List <int> lastHands = JoyLandlordsCardTool.CardConvertorSize(lastHandsNum);

            lastHands.Sort();
            List <int> playHands = JoyLandlordsCardTool.CardConvertorSize(playHandsNum);

            playHands.Sort();
            switch (lastPlayCardType)
            {
            case PlayCardType.DanZhang:
            case PlayCardType.DuiZi:
            case PlayCardType.SanZhang:
            case PlayCardType.ZhaDan:
            case PlayCardType.LianDui:
                return(playHands[0] > lastHands[0]);

            case PlayCardType.SanDaiYi:
            case PlayCardType.SanDaiEr:
                int last3MinSzie = GetSameNumMinToSize(lastHands, 3);
                int play3MinSzie = GetSameNumMinToSize(playHands, 3);
                return(play3MinSzie > last3MinSzie);

            case PlayCardType.SiDaiEr:
            case PlayCardType.SiDaiErDui:
                int last4MinSzie = GetSameNumMinToSize(lastHands, 4);
                int play4MinSzie = GetSameNumMinToSize(playHands, 4);
                return(play4MinSzie > last4MinSzie);

            case PlayCardType.FeiJiBuDai:
            case PlayCardType.FeiJiDaiDanZhang:
            case PlayCardType.FeiJiDaiDuiZi:
                if (lastHands.Count == playHands.Count)
                {
                    int feiJiLast3MinSzie = GetSameNumMinToSize(lastHands, 3);
                    int feiJiPlay3MinSzie = GetSameNumMinToSize(playHands, 3);
                    return(feiJiPlay3MinSzie > feiJiLast3MinSzie);
                }
                return(false);

            case PlayCardType.ShunZi:
                if (lastHands.Count == playHands.Count)
                {
                    return(playHands[0] > lastHands[0]);
                }
                return(false);

            case PlayCardType.WangZha:
                return(false);

            default:
                break;
            }
            return(false);
        }
示例#2
0
 //设置这个牌所对应的牌
 public void SetCardDataUI(int num)
 {
     if (pCardNum != num)
     {
         pCardNum       = num;
         pCardSize      = JoyLandlordsCardTool.CardConvertorSize(num);
         pCardHuaSeType = JoyLandlordsCardTool.CardConvertorType(num);
         RestorUI();
     }
     gameObject.SetActive(true);
 }
        //得到这个牌里面相同数量 最小的牌 并转换成size
        public static int GetSameNumMinToSize <T>(T cards, int num) where T : IList <int>
        {
            List <int>            sameCountList = new List <int>();
            Dictionary <int, int> sameCountDic  = GetSameCount(cards, ref sameCountList);

            sameCountList.Clear();
            foreach (var sameCount in sameCountDic)
            {
                if (sameCount.Value == num)
                {
                    sameCountList.Add(sameCount.Key);
                }
            }
            sameCountList.Sort();
            if (sameCountList.Count > 0)
            {
                return(JoyLandlordsCardTool.CardConvertorSize(sameCountList[0]));
            }
            else
            {
                return(0);
            }
        }
        //根据选中的牌 得到这个牌的类型
        public static int GetCardsType <T>(T cards) where T : IList <int>
        {
            if (cards.Count == 0)
            {
                return(PlayCardType.None);
            }
            //单张
            if (cards.Count == 1)
            {
                return(PlayCardType.DanZhang);
            }
            //获取牌大小不考虑花色
            List <int> cardSizes = JoyLandlordsCardTool.CardConvertorSize(cards);

            cardSizes.Sort();
            List <int>            sameCount    = new List <int>();
            Dictionary <int, int> sameCountDic = GetSameCount(cardSizes, ref sameCount);

            //对子或者王炸
            if (cards.Count == 2)
            {
                if (sameCount.Count == 1 && sameCount[0] == 2)
                {
                    return(PlayCardType.DuiZi);
                }
                if (cardSizes[0] >= 53 && cardSizes[1] >= 53)
                {
                    return(PlayCardType.WangZha);
                }
                return(PlayCardType.None);
            }
            //三不带
            if (cards.Count == 3)
            {
                if (sameCount.Count == 1 && sameCount[0] == 3)
                {
                    return(PlayCardType.SanZhang);
                }
                return(PlayCardType.None);
            }
            //三带一或者炸弹
            if (cards.Count == 4)
            {
                if (sameCount.Count > 1 && sameCount[1] == 3)
                {
                    return(PlayCardType.SanDaiYi);
                }
                if (sameCount.Count == 1 && sameCount[0] == 4)
                {
                    return(PlayCardType.ZhaDan);
                }
                return(PlayCardType.None);
            }

            //判断是不是顺子
            if (IsShunZi(cardSizes))
            {
                return(PlayCardType.ShunZi);
            }

            //三带二
            if (cards.Count == 5)
            {
                if (sameCount.Count == 2 && sameCount[0] == 2 && sameCount[1] == 3)
                {
                    return(PlayCardType.SanDaiEr);
                }
                return(PlayCardType.None);
            }
            //判断是不是飞机
            int cardFeiJiType = IsFeiJi(cardSizes, sameCountDic);

            if (cardFeiJiType != PlayCardType.None)
            {
                return(cardFeiJiType);
            }
            //判断是不是连对
            if (IsLianDui(cardSizes, sameCount))
            {
                return(PlayCardType.LianDui);
            }
            //四带二
            if (cards.Count == 6)
            {
                if (sameCount[sameCount.Count - 1] == 4)
                {
                    return(PlayCardType.SiDaiEr);
                }
                return(PlayCardType.None);
            }
            //四带二对
            if (cards.Count == 8)
            {
                if (sameCount.Count == 3 && sameCount[2] == 4 && sameCount[0] == 2 && sameCount[1] == 2)
                {
                    return(PlayCardType.SiDaiErDui);
                }
                return(PlayCardType.None);
            }
            return(PlayCardType.None);
        }