• 判断顺子的方法


            /// <summary>
            /// 检查顺子
            /// </summary>
            /// <param name="cards">排序后的原始牌</param>
            /// <param name="kingCount">癞子数量</param>
            /// <param name="handCards">比较牌</param>
            /// <returns></returns>
            public static bool CheckStraight(List<int> cards, int kingCount, out List<int> handCards)
            {
                handCards = new List<int>();
                var cards2 = cards.Take(cards.Count - kingCount).ToList();
                for (int i = 0; i < cards2.Count; i++)
                {
                    var pre = cards2[i];
                    handCards.Add(pre);
                    if (i == cards2.Count - 1)
                    {
                        break;
                    }
                    var cur = cards2[i + 1];
                    var interval = (cur%100) - (pre%100);
                    if (interval == 1)
                    {
                        continue;
                    }
                    else if(interval>1&&kingCount > 0)
                    {
                        pre = pre % 100;
                        while (interval > 1)
                        {
                            if (kingCount<=0)
                            {
                                return false;
                            }
                            kingCount--;
                            pre++;
                            handCards.Add(pre);
                            interval--;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                if (kingCount>0)
                {
                    var first = handCards.First();
                    var last=handCards.Last();
                    while (14-(last%100)>0&&kingCount>0)//先从后面补
                    {
                        var newlast = (last % 100) + 1;
                        handCards.Add(newlast);
                        kingCount--;
                        last = newlast;
                    }
                    if (kingCount > 0)//最后从前面补
                    {
                        while ((first%100)-2>0&&kingCount>0)
                        {
                            var newfirst = (first % 100) - 1;
                            handCards.Insert(0, newfirst);
                            kingCount--;
                            first = newfirst;
                        }
                    }
                }
                handCards.Reverse();
                return true;
            }

    例如:110,212,113,癞子,癞子

    110%100 表示10

    110/100   表示花色,方块

  • 相关阅读:
    14.Java基础_函数/函数重载/参数传递
    98. 验证二叉搜索树(深搜)
    13.Java基础_数组内存图
    12Java基础_数组定义格式/动态初始化/静态初始化
    计算几何基础
    11.Java基础_IDEA常用快捷键
    Add Two Numbers
    Two Sum
    登录界面id属性的使用
    系统查看
  • 原文地址:https://www.cnblogs.com/kingge/p/10845897.html
Copyright © 2020-2023  润新知