Пример #1
0
 public SelectedInfo()
 {
     CardType = CardType.none;
     Index    = -1;
     Dun      = new SssDun {
         Cards = new List <int>()
     };
     SelectedCards = new List <PokerCard>();
 }
Пример #2
0
 public void Reset()
 {
     CardType = CardType.none;
     Index    = -1;
     if (Dun == null)
     {
         Dun = new SssDun();
     }
     Dun.Cards.Clear();
     Dun.CardType = CardType.none;
     SelectedCards.Clear();
 }
Пример #3
0
        /// <summary>
        /// 将牌列表添加到数据添加入字典中
        /// </summary>
        /// <param name="keyType">key</param>
        /// <param name="dic">字典</param>
        /// <param name="cards1">第一组牌</param>
        /// <param name="cards2">第二组牌</param>
        void AddListToDic(CardType keyType, Dictionary <CardType, List <SssDun> > dic, List <int> cards1, List <int> cards2 = null)
        {
            var tempList = cards1;

            if (cards2 != null)
            {
                tempList.AddRange(cards2);
            }

            SssDun dun = new SssDun
            {
                CardType = keyType,
                Cards    = tempList
            };

            AddToDic(dic, keyType, dun);
        }
Пример #4
0
        /// <summary>
        /// 获取按钮状态位,同时初始化字典
        /// </summary>
        /// <param name="pokerList"></param>
        /// <returns></returns>
        private int GetBtnState(List <int> pokerList)
        {
            if (pokerList.Count < 3)
            {
                return(0);
            }

            int btnState = 0;


            CnList cnList = new CnList(pokerList);
            VnList vnList = new VnList(pokerList);

            CnList cn5 = cnList.GetMoreThan(5, true, true);     //同花色5个以上
            VnList vn2 = vnList.GetMoreThan(2, true);           //同数值的2个以上

            _cardTypeDic.Clear();

            //同花顺,128
            if (cn5.Count > 0)
            {
                foreach (var cnItem in cn5)
                {
                    if (HaveAndAdd(cnItem.Cards, CardType.tonghuashun, CardType.tonghuashun))
                    {
                        btnState |= GetStateVal(CardType.tonghuashun);
                    }
                }
            }

            //铁支
            VnList vn4 = vnList.GetEqual(4, true);

            if (vn4.Count > 0)
            {
                foreach (var item in vn4)
                {
                    SssDun dun = new SssDun
                    {
                        CardType = CardType.tiezhi,
                        Cards    = item.Cards
                    };
                    AddToDic(_cardTypeDic, CardType.tiezhi, dun);
                }
                btnState |= GetStateVal(CardType.tiezhi);
            }

            VnList vn3 = vnList.GetMoreThan(3, true);

            //葫芦
            if (vn3.Count > 0 && vn2.Count > 0)
            {
                foreach (var item3 in vn3)
                {
                    foreach (var item2 in vn2)
                    {
                        if (item3.Val == item2.Val)
                        {
                            continue;
                        }

                        AddListToDic(CardType.hulu, _cardTypeDic, item3.Cards.GetRange(0, 3), item2.Cards.GetRange(0, 2));

                        btnState |= GetStateVal(CardType.hulu);
                    }
                }
            }

            //同花
            if (cn5.Count > 0)
            {
                btnState = cn5.Where(item => HaveAndAdd(item.Cards, CardType.tonghua))
                           .Aggregate(btnState, (current, item) => current | GetStateVal(CardType.tonghua));
            }

            //顺子
            {
                List <SssDun> dunList = new List <SssDun>();
                HelpLz        help    = new HelpLz();
                if (help.CheckShunZi(pokerList, dunList, 5, false))
                {
                    foreach (var dun in dunList)
                    {
                        AddToDic(_cardTypeDic, CardType.shunzi, dun);
                    }
                    btnState |= GetStateVal(CardType.shunzi);
                }
            }

            //三条
            if (vn3.Count > 0)
            {
                int count = vn3.Count;
                for (int i = 0; i < count; i++)
                {
                    AddListToDic(CardType.santiao, _cardTypeDic, vn3[i].Cards.GetRange(0, 3));
                }
                btnState |= GetStateVal(CardType.santiao);
            }

            //两对
            if (vn2.Count > 1)
            {
                int count = vn2.Count;
                for (int i = 0; i < count; i++)
                {
                    int vn2Vi = vn2[i].Val;
                    for (int j = i; j < count; j++)
                    {
                        int vn2Vj = vn2[j].Val;
                        if (vn2Vi == vn2Vj)
                        {
                            continue;
                        }
                        AddListToDic(CardType.liangdui, _cardTypeDic, vn2[i].Cards.GetRange(0, 2),
                                     vn2[j].Cards.GetRange(0, 2));
                        btnState |= GetStateVal(CardType.liangdui);
                    }
                }
            }

            //对子
            if (vn2.Count > 0)
            {
                int count = vn2.Count;
                for (int i = 0; i < count; i++)
                {
                    AddListToDic(CardType.yidui, _cardTypeDic, vn2[i].Cards.GetRange(0, 2));
                }
                btnState |= GetStateVal(CardType.yidui);
            }

            return(btnState);
        }
Пример #5
0
 /// <summary>
 /// 添加到字典中
 /// </summary>
 /// <param name="dic"></param>
 /// <param name="key"></param>
 /// <param name="dun"></param>
 private void AddToDic(Dictionary <CardType, List <SssDun> > dic, CardType key, SssDun dun)
 {
     if (dic == null)
     {
         dic = new Dictionary <CardType, List <SssDun> >();
     }
     if (!dic.ContainsKey(key))
     {
         dic.Add(key, new List <SssDun>());
     }
     dic[key].Add(dun);
 }