Пример #1
0
        /// <summary>
        /// 检测是否是炸弹
        /// </summary>
        /// <param name="ordinary"></param>
        /// <returns></returns>
        private Poker CheckIsBomb(List <Poker> ordinary)
        {
            Poker maxPoker = ordinary[0];

            for (int j = 0; j < ordinary.Count - 1; ++j)
            {
                if (ordinary[j].size != ordinary[j + 1].size)
                {
                    return(null);
                }
            }
            return(maxPoker);
        }
Пример #2
0
        /// <summary>
        /// 检测是否是顺子
        /// </summary>
        /// <param name="pokers"></param>
        /// <returns></returns>
        private Poker CheckIsStraight(List <Poker> pokers)
        {
            if (pokers == null || pokers.Count != 5)
            {
                return(null);
            }

            List <Poker> ordinary = new List <Poker>();

            for (int i = 0; i < pokers.Count; ++i)
            {
                if (!pokers[i].isUniversal)
                {
                    ordinary.Add(pokers[i]);
                }
            }



            for (int j = 0; j < ordinary.Count - 1; ++j)
            {
                if (ordinary[j].size == (ordinary[j + 1].size))
                {
                    return(null);                                           //有一对
                }
            }

            if (ordinary[ordinary.Count - 1].size > 14)
            {
                return(null); //有王
            }



            int UniversalCount = pokers.Count - ordinary.Count; //万能牌数量


            Poker maxPoker     = null; //当前最大单牌
            int   maxSizeScope = ordinary[0].size - 1 + pokers.Count;

            if (ordinary[ordinary.Count - 1].size <= maxSizeScope)
            {
                if (maxSizeScope > 14)
                {
                    maxPoker = new Poker(-1, ordinary[0].color, 14); //最大牌为A
                }
                else
                {
                    maxPoker = new Poker(-1, ordinary[0].color, maxSizeScope);  //最大牌为: 最小牌+4
                }
            }

            if (ordinary[ordinary.Count - 1].size == 14)
            {
                bool isMinStraight = true;
                for (int i = 0; i < ordinary.Count - 1; i++)
                {
                    if (ordinary[i].size >= 5)
                    {
                        isMinStraight = false;
                        break;
                    }
                }
                if (isMinStraight)
                {
                    maxPoker = new Poker(-1, ordinary[0].color, 5);                //最大牌为: 5 //是12345
                }
            }

            return(maxPoker);
        }
Пример #3
0
        /// <summary>
        /// 判断牌型
        /// </summary>
        /// <param name="pokers"></param>
        /// <returns></returns>
        private PokersType GetPokerType(List <Poker> pokers, out int maxSize)
        {
            //排序??



            List <Poker> ordinary = new List <Poker>();

            for (int i = 0; i < pokers.Count; ++i)
            {
                if (!pokers[i].isUniversal)
                {
                    ordinary.Add(pokers[i]);
                }
            }

            int universalSum = pokers.Count - ordinary.Count;

            maxSize = ordinary.Count > 0 ? ordinary[ordinary.Count - 1].size : pokers[0].size;


            if (pokers.Count == 1)
            {
                return(PokersType.Single);
            }
            else if (pokers.Count == 2)
            {
                if (pokers[0].size == pokers[1].size || ordinary.Count < 2)
                {
                    return(PokersType.Two);
                }
            }
            else if (pokers.Count == 3)
            {
                bool isThree = true;
                for (int i = 0; i < ordinary.Count - 1; i++)
                {
                    if (ordinary[i].size != ordinary[i + 1].size)
                    {
                        isThree = false;
                    }
                }
                if (isThree)
                {
                    maxSize = ordinary[0].size;
                    return(PokersType.Three);
                }
            }
            else if (pokers.Count == 4)
            {
                if (pokers[0].size > 14)
                {
                    return(PokersType.FourKings);
                }

                if (CheckIsBomb(ordinary) != null)
                {
                    return(PokersType.Bomb);
                }
            }
            else if (pokers.Count == 5)
            {
                if (CheckIsBomb(ordinary) != null)
                {
                    return(PokersType.Bomb);                              //炸弹
                }
                //三带二  顺子  炸弹 同花顺

                Poker poker = CheckIsStraight(pokers);
                if (poker != null)
                {
                    maxSize = poker.size;
                }

                bool isStraight = poker != null;
                bool isFlush    = true;

                //是否是同花
                for (int j = 1; j < ordinary.Count; ++j)
                {
                    if (ordinary[0].color != ordinary[j].color)
                    {
                        isFlush = false;
                    }
                }

                if (isStraight && isFlush)
                {
                    return(PokersType.StraightFlush);
                }
                else if (isStraight)
                {
                    return(PokersType.Straight);
                }

                //是否是三带二
                int differentSizeSum = 0;
                if (ordinary.Count > 0)
                {
                    ++differentSizeSum;
                }
                for (int i = 1; i < ordinary.Count; ++i)
                {
                    if (ordinary[0].size != ordinary[i].size)
                    {
                        ++differentSizeSum;
                    }
                }
                if (differentSizeSum == 2)
                {
                    return(PokersType.ThreeWithTwo);
                }
            }
            else if (pokers.Count == 6)
            {
                //三连对 钢板 炸弹
                if (CheckIsBomb(ordinary) != null)
                {
                    return(PokersType.Bomb);                              //炸弹
                }
                if (CheckIsSteelPlate(ordinary, universalSum) != null)
                {
                    return(PokersType.SteelPlate);
                }
                if (CheckIsThreeEven(ordinary, universalSum) != null)
                {
                    return(PokersType.ThreeEven);
                }
            }
            else if (pokers.Count > 6)
            {
                if (CheckIsBomb(ordinary) != null)
                {
                    return(PokersType.Bomb);                              //炸弹
                }
            }

            return(PokersType.HighCard);
        }
Пример #4
0
        /// <summary>
        ///  找同花顺  以最小牌为基准
        /// </summary>
        /// <param name="currStraightFlush"></param>
        /// <returns></returns>
        private List <Poker> LookingForStraightFlush(int currStraightFlush, List <Poker> ordinary, int universalSum)
        {
            if (currStraightFlush < 0)
            {
                currStraightFlush = 0;
            }

            //------1-------------按照当前手牌查找------------------------------------------

            if (currStraightFlush > 10)
            {
                return(null);
            }

            // ---优先----查找 A 2 3 4 5

            if (currStraightFlush == 0)
            {
                //黑红梅方
                //for (int i = 1; i < 5; i++)
                //{

                //}


                //Poker poker = ExistPoker(14, ordinary[i].color);

                //for (int j = 1; j < 5; j++)
                //{
                //    Poker poker = ExistPoker(ordinary[i].size + j, ordinary[i].color);
                //    if (poker == null) continue;
                //}
            }


            for (int i = 0; i < ordinary.Count; i++)
            {
                if (ordinary[i].size > 10)
                {
                    break;
                }
                if (ordinary[i].size < currStraightFlush || (ordinary[i].size == ordinary[i - 1].size && ordinary[i].color == ordinary[i - 1].color))
                {
                    continue;
                }

                for (int j = 1; j < 5; j++)
                {
                    Poker poker = ExistPoker(ordinary[i].size + j, ordinary[i].color);
                    if (poker == null)
                    {
                        continue;
                    }
                }
            }



            //补

            //从后向前补 1 - 10
            //  补特殊的 J  Q

            // ----优先---查找 A 2 3 4 5

            for (int i = 0; i < ordinary.Count; i++)
            {
                if (ordinary[i].size > 12)
                {
                    break;
                }
                int x = ordinary[i].size > 10 ? (5 + 10 - ordinary[i].size) : 5;
                //int universalSumClone = ordinary[i].size > 10 ? (universalSum + 10 - ordinary[i].size) : universalSum; ;
                for (int j = 1; j < x; j++)
                {
                    if (i > 0 && ordinary[i].size == ordinary[i - 1].size && ordinary[i].color == ordinary[i - 1].color)
                    {
                        continue;
                    }

                    Poker poker = ExistPoker(ordinary[i].size + j, ordinary[i].color);
                    if (poker == null)
                    {
                        --universalSum;
                    }
                    if (universalSum < 0)
                    {
                        break;
                    }
                }
            }



            //------2-------------从12345 -- 10JQKA  全部查找------------------------------------------
            int universalSumClone = universalSum;

            //整

            //组
            if (currStraightFlush == 0)
            {
                //找 12345
                //区分花色
                for (int j = 1; j <= 4; ++j)
                {
                    universalSumClone = universalSum;

                    if (ExistPoker(14, j) == null)
                    {
                        --universalSumClone;
                    }

                    //顺子长度
                    for (int k = 2; k <= 5; ++k)
                    {
                        if (ExistPoker(k, j) == null)
                        {
                            --universalSumClone;
                        }
                        if (universalSumClone >= 0)
                        {
                            //返回列表
                        }
                    }
                }
            }

            if (currStraightFlush > 0)
            {
                //找 23456 - 10JQKA
                for (int i = currStraightFlush + 1; i <= 10; ++i)
                {
                    //区分花色
                    for (int j = 1; j <= 4; ++j)
                    {
                        universalSumClone = universalSum;
                        //顺子长度
                        for (int k = 0; k < 5; ++k)
                        {
                            Poker poker = ExistPoker(i + k, j);
                            if (poker == null)
                            {
                                --universalSumClone;
                            }

                            if (universalSumClone >= 0)
                            {
                                //返回列表
                            }
                        }
                    }
                }
            }



            return(null);
        }