Ejemplo n.º 1
0
        //----------------------------------------------------------------end

        /// <summary>
        /// 检测出的牌可能组成的顺子
        /// </summary>
        /// <param name="cdsplitStruct"></param>
        /// <param name="hdSplitSutuct">所有手牌</param>
        private int[] CheckPossbShunzi(CdSplitStruct cdsplitStruct, CdSplitStruct hdSplitSutuct)
        {
            var danCds = cdsplitStruct.DanCds;

            if (cdsplitStruct.OrgCds.Length != danCds.Count || danCds.Count < 2)
            {
                return(null);
            }

            //排序好的 框出来的牌
            var sortedCds = PokerRuleUtil.GetSortedValues(danCds.ToArray());

            var listTemp = new List <int>();

            listTemp.AddRange(hdSplitSutuct.DanCds);
            listTemp.AddRange(hdSplitSutuct.DuiCds);
            listTemp.AddRange(hdSplitSutuct.ThreeCds);
            listTemp.AddRange(hdSplitSutuct.FourCds);

            var keys = listTemp.ToArray();

            var allposbShunList = PokerRuleUtil.GetAllPossibleShun(keys, 5);

            if (allposbShunList == null || allposbShunList.Count < 1)
            {
                return(null);
            }

            //存手牌中最终找到的那组顺牌
            var findShun = new List <int>();

            foreach (var shunCds in allposbShunList)
            {
                var shuncdsLen = shunCds.Length;
                if (shuncdsLen >= 5)
                {
                    if (shunCds[0] <= sortedCds[0] && shunCds[shuncdsLen - 1] >= sortedCds[sortedCds.Length - 1])
                    {
                        findShun.Clear();
                        findShun.AddRange(shunCds);
                        break;
                    }
                }
            }
            if (findShun.Count < 1)
            {
                return(null);
            }

            return(findShun.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 检测潜在的三带的牌
        /// </summary>
        /// <param name="cdsplitStruct"> 已经被弹起的牌值的数据结构</param>
        /// <param name="hdSplitSutuct"> 手牌</param>
        /// <returns></returns>
        private int[] CheckThreeWith(CdSplitStruct cdsplitStruct, CdSplitStruct hdSplitSutuct)
        {
            var danList = cdsplitStruct.DanCds;
            var duiList = cdsplitStruct.DuiCds;

            var sanList = hdSplitSutuct.ThreeCds;

            foreach (var v in sanList)
            {
                int value = v;

                if (value < PokerRuleUtil.SmallJoker)
                {
                    value &= 0xf;
                }

                if (danList.Contains(value) || duiList.Contains(value))
                {
                    var orderCds = cdsplitStruct.OrderSortedCds;
                    var otherCds = new List <int>();
                    for (int i = 0; i < orderCds.Length; i++)
                    {
                        if (orderCds[i] != value)
                        {
                            otherCds.Add(orderCds[i]);
                        }
                    }

                    //组合一下牌变成wholecards
                    otherCds.AddRange(new [] { value, value, value });
                    if (_getCdsType != null)
                    {
                        int[] cds = otherCds.ToArray();
                        cds = PokerRuleUtil.GetSortedValues(cds);
                        var type = _getCdsType(cds);
                        //如果有合法牌返回这组牌
                        if (type > 0)
                        {
                            return(otherCds.ToArray());
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 找到顺牌,不管是连对 还是顺子 还是连三, 最小是连2组,!但!!!检索以后可能还存在 带有2的链子,这种情况,在使用方法后检查
        /// </summary>
        /// <param name="orgcards"></param>
        /// <param name="lenlimit">限制顺牌的最小长度</param>
        /// <returns></returns>
        public int[] CheckShun(int[] orgcards, int lenlimit)
        {
            var cards = PokerRuleUtil.GetSortedValues(orgcards);

            var cardsLen = cards.Length;

            if (cardsLen < lenlimit || lenlimit < 2)
            {
                return(null);
            }

            var canLianCds = new List <int>();

            for (int i = 0; i < cardsLen - 1; i++)
            {
                if (cards[i] == cards[i + 1] - 1)
                {
                    canLianCds.Add(cards[i]);

                    if (i == cardsLen - 2)
                    {
                        canLianCds.Add(cards[i + 1]);
                    }
                }
                else
                {
                    canLianCds.Add(cards[i]);
                    if (canLianCds.Count >= lenlimit)
                    {
                        break;
                    }
                    canLianCds.Clear();
                }
            }

            if (canLianCds.Count >= lenlimit)
            {
                return(canLianCds.ToArray());
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 移除数组中的不能组成链子的大牌
        /// </summary>
        /// <param name="cds"></param>
        /// <returns></returns>
        private int[] RemoveBigCdsInArray(int[] cds)
        {
            if (cds == null)
            {
                return(null);
            }
            var tempList = new List <int>();
            int len      = cds.Length;

            for (int i = 0; i < len; i++)
            {
                int val = cds[i];
                if (PokerRuleUtil.GetValue(val) < 15)
                {
                    tempList.Add(val);
                }
            }
            return(tempList.ToArray());
            //return cds.Where(cd => PokerRuleUtil.GetValue(cd) < 15).ToArray();
        }
Ejemplo n.º 5
0
        public CdSplitStruct(int[] cards)
        {
            OrgCds = (int[])cards.Clone();

            DanCds   = new List <int>();
            DuiCds   = new List <int>();
            ThreeCds = new List <int>();
            FourCds  = new List <int>();

            if (cards == null)
            {
                throw new Exception("CdSplitStruct 生成错误  cards为null");
            }

            OrderSortedCds = PokerRuleUtil.GetSortedValues(cards);

            var cdsDic = new Dictionary <int, short>(); //牌值 ,个数

            for (int i = 0; i < OrderSortedCds.Length; i++)
            {
                if (!cdsDic.ContainsKey(OrderSortedCds[i]))
                {
                    cdsDic[OrderSortedCds[i]] = 1;
                    continue;
                }

                cdsDic[OrderSortedCds[i]] += 1;
            }

            foreach (var key in cdsDic.Keys)
            {
                switch (cdsDic[key])
                {
                case 1:
                    DanCds.Add(key);
                    break;

                case 2:
                    DuiCds.Add(key);
                    break;

                case 3:
                    ThreeCds.Add(key);
                    break;

                case 4:
                    FourCds.Add(key);
                    break;
                }
            }

            SortedCds = new int[DanCds.Count + DuiCds.Count * 2 + ThreeCds.Count * 3 + FourCds.Count * 4];
            int sortedI = 0;

            foreach (var cd in DanCds)
            {
                SortedCds[sortedI] = cd;
                sortedI++;
            }
            foreach (var cd in DuiCds)
            {
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
            }
            foreach (var cd in ThreeCds)
            {
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
            }
            foreach (var cd in FourCds)
            {
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
                SortedCds[sortedI] = cd;
                sortedI++;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 检测出牌可能组成的连对
        /// </summary>
        /// <param name="cdsplitStruct"></param>
        /// <param name="hdSplitSutuct"></param>
        /// <returns></returns>
        private int[] CheckpossbLianDui(CdSplitStruct cdsplitStruct, CdSplitStruct hdSplitSutuct)
        {
            var danCds = cdsplitStruct.DanCds;
            var duiCds = cdsplitStruct.DuiCds;

            if (cdsplitStruct.OrgCds.Length != danCds.Count + duiCds.Count * 2 || (danCds.Count + duiCds.Count) < 2)
            {
                return(null);
            }

            var chooseCdsValueList = new List <int>();

            chooseCdsValueList.AddRange(danCds);
            chooseCdsValueList.AddRange(duiCds);
            chooseCdsValueList.Sort();

            //存手牌中对牌的值列表
            var allduiHandCdValue = hdSplitSutuct.DuiCds;

            //框选出的牌
            var chooseCds = chooseCdsValueList.ToArray();
            //所有可能的连对 组
            var alposbLdList = PokerRuleUtil.GetAllPossibleShun(allduiHandCdValue.ToArray(), 3);

            if (alposbLdList == null || alposbLdList.Count < 1)
            {
                return(null);                                             //没有找到符合条件的连对
            }
            var findLd = new List <int>();

            foreach (var ldCds in alposbLdList)
            {
                var ldLen = ldCds.Length;
                if (ldLen >= 3)
                {
                    if (ldCds[0] <= chooseCds[0] &&
                        ldCds[ldCds.Length - 1] >= chooseCds[chooseCds.Length - 1])
                    {
                        findLd.Clear();
                        findLd.AddRange(ldCds);
                        break;
                    }
                }
            }

            if (findLd.Count < 1)
            {
                return(null);                  //没有找到符合条件的连对
            }
            var findldLen   = findLd.Count;
            var returnLdCds = new int[findldLen * 2];
            int j           = 0;

            for (int i = 0; i < findldLen; i++)
            {
                returnLdCds[j++] = findLd[i];
                returnLdCds[j++] = findLd[i];
            }

            return(returnLdCds);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  在有别家出牌的情况下 智能检测出牌
        /// </summary>
        /// <param name="selectCds">已经框选出来的牌值</param>
        /// <param name="canOutCardListDic">提示牌组和对应的类型</param>
        /// <param name="compareCds">要去比较的牌,上家牌</param>
        public int[] ChkCanoutCdListWithLastCdList(int[] selectCds, Dictionary <int[], CardType> canOutCardListDic, int[] compareCds)
        {
            if (canOutCardListDic == null || canOutCardListDic.Count < 1)
            {
                return(null);
            }

            //检查选出的牌是不是就是提示牌组中的某组牌
            var selcdsPureSortValues = PokerRuleUtil.GetSortedValues(selectCds);
            var selCdsType           = PokerRuleUtil.GetCdsType(selectCds);
            var selcdsLen            = selectCds.Length;

            foreach (var canoutCds in canOutCardListDic.Keys)
            {
                if (selcdsLen == canoutCds.Length && selCdsType == canOutCardListDic[canoutCds])
                {
                    if (DDzUtil.IsTwoArrayEqual(selcdsPureSortValues, PokerRuleUtil.GetSortedValues(canoutCds)))
                    {
                        return(canoutCds);
                    }
                }

                //检查选的牌是不是提示牌组的子集
                if (DDzUtil.IsSubsetArray(PokerRuleUtil.GetSortedValues(canoutCds), selcdsPureSortValues))
                {
                    return(canoutCds);
                }
            }



            //检查提示牌组中有没有

            //DDzUtil.IsTwoArrayEqual()


/*            var listTemp = new List<int>();
 *
 *          //如果是提示牌的子集 直接返回相应的提示牌组
 *          var posbFitCdsList = new List<int[]>();
 *          foreach (var canOutcds in canOutCardList)
 *          {
 *              listTemp.Clear();
 *              listTemp.AddRange(canOutcds);
 *
 *              bool findNotMatch = false;
 *              for (int i = 0; i < selectCds.Length; i++)
 *              {
 *                  if (listTemp.Contains(selectCds[i]) || listTemp.Contains(HdCdsCtrl.GetValue(selectCds[i])))
 *                  {
 *                      posbFitCdsList.Add(canOutcds);
 *                      listTemp.Remove(selectCds[i]);
 *                  }
 *                  else
 *                  {
 *                      findNotMatch = true;
 *                      break;
 *                  }
 *              }
 *
 *              if (!findNotMatch) return canOutcds;
 *          }
 *
 #region 进一步查找可能的牌
 *          //如果框选的牌中,含有有符合提示的牌组中的某张牌 ,则看下是不是  三带的情况的牌组
 *          if (posbFitCdsList.Count > 0)
 *          {
 *              var compareType = _getCdsType(PokerRuleUtil.GetSortedValues(compareCds));
 *              //如果不是三带的类型 就不用检测了
 *              if (compareType != CardType.C31 && compareType != CardType.C32) return null;
 *
 *              foreach (var posbFitCds in posbFitCdsList)
 *              {
 *                  //排除不是三顺和三条的提示牌
 *                  if (_getCdsType(PokerRuleUtil.GetSortedValues(posbFitCds)) != CardType.C3) continue;
 *
 *                  //拼凑可能合法的牌组
 *                  listTemp.Clear();
 *                  listTemp.AddRange(selectCds);
 *                  for (int i = 0; i < posbFitCds.Length; i++)
 *                  {
 *                      listTemp.Remove(posbFitCds[i]);
 *                  }
 *
 *                  for (int i = 0; i < posbFitCds.Length; i++)
 *                  {
 *                      listTemp.Add(posbFitCds[i]);
 *                  }
 *
 *                  var finalCds = PokerRuleUtil.GetSortedValues(listTemp.ToArray());
 *
 *                  if (finalCds.Length == compareCds.Length && _getCdsType(finalCds) == compareType)
 *                      return finalCds;
 *              }
 *          }
 #endregion*/

            return(null);
        }