Пример #1
0
        //存储自己手牌 牛的下标


        #region 普通场
        //计算传入的Poker列表 是否有牛 (有牛自动排序)
        /// <summary>
        ///  返回排列下标 是否有牛
        /// </summary>
        /// <param name="pokerList"></param>
        /// <param name="whetherNiu"></param>
        /// <returns></returns>
        public int[] Calculate(List <NiuNiu.Poker> pokerList, out bool whetherNiu)
        {
            int[]      pokerSubscript     = new int[pokerList.Count];
            List <int> arrPart            = new List <int>();
            int        openPokerSubscript = 0;

            for (int i = 0; i < pokerList.Count; i++)
            {
                pokerSubscript[i] = i;
                if (pokerList[i].status == NN_ENUM_POKER_STATUS.POKER_STATUS_UPWARD)
                {
                    openPokerSubscript++;
                    arrPart.Add(i);
                }
            }
            if (openPokerSubscript < 3)
            {
                whetherNiu = false;
                return(pokerSubscript);
            }


            //arr  为翻开的poker 下标数组
            int[] arr = arrPart.ToArray();


            lst_Combination.Clear();
            //求组合          arr 是 下标集合
            lst_Combination = MyNiuNiuCombination <int> .GetCombination(arr, 3);



            if (lst_Combination.Count == 0)
            {
                Debug.Log("没有3张牌的组合");
            }



            //计算是否有牛  --------------得到排序后数组--------------------

            pokerSubscript = SumNiuNiu(pokerList, pokerSubscript, out whetherNiu);

            return(pokerSubscript);
        }
Пример #2
0
        //-----计算牛-------------------

        public List <Poker> CalculateNiu(List <Poker> pokerList, out bool whetherNiu)
        {
            whetherNiu = false;

            //求3张组合
            List <Poker[]> lst_CombinationNew = MyNiuNiuCombination <Poker> .GetCombination(pokerList.ToArray(), 3);

            if (lst_CombinationNew.Count == 0)
            {
                Debug.Log("没有3张牌的组合");
            }

            for (int i = 0; i < lst_CombinationNew.Count; i++)
            {
                int sum = 0;
                for (int j = 0; j < lst_CombinationNew[i].Length; j++)
                {
                    sum += Mathf.Clamp(lst_CombinationNew[i][j].size, 0, 10);
                }

                //对10取余 等于0 说明有牛
                if ((sum % 10) == 0)
                {
                    Debug.Log("有牛");
                    Debug.Log("这三张牌大小为:" + lst_CombinationNew[i][0].size + " " + lst_CombinationNew[i][1].size + " " + lst_CombinationNew[i][2].size);

                    whetherNiu = true;

                    for (int j = 0; j < pokerList.Count; ++j)
                    {
                        //pokerList[j] 是否在 lst_CombinationNew[i]中
                        for (int k = 0; k < lst_CombinationNew[i].Length; ++k)
                        {
                            if (lst_CombinationNew[i][k].index == pokerList[j].index)
                            {
                                //判断是否前移
                                for (int t = j; t > 0; --t)
                                {
                                    //前一位不在lst_CombinationNew[i]zhong中 那么前移
                                    bool isZai = false;
                                    for (int y = 0; y < lst_CombinationNew[i].Length; ++y)
                                    {
                                        if (lst_CombinationNew[i][y].index == pokerList[t - 1].index)
                                        {
                                            isZai = true;
                                        }
                                    }

                                    if (!isZai)
                                    {
                                        Poker temp = pokerList[t];
                                        pokerList[t]     = pokerList[t - 1];
                                        pokerList[t - 1] = temp;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }


                                break;
                            }
                        }
                    }

                    return(pokerList);
                }
            }


            //pokerSubscript = SumNiuNiu(pokerList, pokerSubscript, out whetherNiu);


            return(pokerList);
        }