棋牌源码搭建-梭哈算法思路

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了棋牌源码搭建-梭哈算法思路相关的知识,希望对你有一定的参考价值。

 

 

梭哈游戏使用28张扑克牌,取黑桃、红桃、草花、方片四种花色的8、9、10、J、Q、K、A进行游戏,游戏人数可为2―4人。
游戏开始后,先发给各家2张牌,从第二张牌开始自动亮出,每发一张牌,从牌面较大者逆时针下注。优先下注者可选择下注、不加或放弃;当别人下注后,可考虑是否“跟”或“加”注。当发到第四张牌时,可以选择“梭”,即增加下注到允许的最大筹码值。 最后的胜利者获得本局桌面上的全部筹码,如果输家剩余的筹码数少于规定坐下的最小数额将被请出桌子。


牌型比较:
牌型:同花顺>铁支>葫芦>同花>顺子>三条>两对>对子>散牌
点数:A>K>Q>J>10>9>8
花色:黑桃>红桃>草花>方片

各牌型:

同花顺:拥有五张连续数字同花色的顺子,以黑桃A为首的同花顺最大;
铁支:四张相同数字的牌,外加一单张。比数字大小,「A」铁支最大;
葫芦:由「三条」加一个「对子」所组成的牌。若别家也有此牌型,则比三条数字大小;
同花:不构成顺子的五张同花色的牌。比花色后比大小;
顺子:五张连续数字不花色的牌组成。 以A为首的顺子最大,如果大家都是顺子,比最大的一张牌,如果大小还一样就比这张牌的花色,黑桃A顺子最大;
三条:牌型由三张相同的牌组成,以A为首的三条最大;
二对:牌型中五张牌由两组两张同数字的牌所组成。若遇相同则先比这副牌中最大的一对,如又相同再比第二对,如果还是一样,比大对子中的最大花色;
对子:牌型由两张相同的牌加上三张单张所组成。如果大家都是对子,比对子的大小,如果对子也一样,比这个对子中的最大花色
散牌:由单一型态,不构成上面的牌型的五张散牌组成,先比最大一张牌的大小,如果大小一样,比这张牌的花色

 (以下内容仅供参考,欢迎点评QQ2189563389 棋牌源码搭建 www.yasewl.com )

using System;
using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1
{
    public class Rule
    {
        #region ------------------------私有字段(牌的最大值,牌型,颜色,是否是同色)----------
        private PaiType paiType = PaiType.Not;  //牌型
        private int maxPai = 0;                //玩家手中的最大牌
        private PaiColor paicolor;           //玩家最大牌的颜色
        private bool isColor;                //玩家手中的牌的花色是否相同
        #endregion
        #region ----------------------------------玩家手中牌的 最大值,颜色,牌型的属性-----------------------
        public PaiType Paitype
        {
            get { return paiType; }
        }
        public int MaxPai
        {
            get { return maxPai; }
        }
        public PaiColor Paicolor
        {
            get { return paicolor; }
        }
        #endregion
        #region -------------------同花顺(拥有五张连续数字同花色的顺子,以黑桃A为首的同花顺最大)---------------------------------
        public int StraightFlush(int[] cards, bool isColor)//同花顺
        {
            if (cards.Length == 5)
            {
                if (isColor)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            return 0;
                        }
                    }
                    paiType = PaiType.isTHS;
                    maxPai = cards[4];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ------------------------------铁支(四张相同数字的牌,外加一单张,比数字大小,A铁支最大)----------------
        public int IronBranch(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                if ((cards[0] != cards[1] && cards[1] == cards[2] && cards[3] == cards[1] && cards[4] == cards[1]) || (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[1] && cards[4] != cards[1]))
                {
                    paiType = PaiType.isTZ;
                    maxPai = cards[2];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region -----------------------------葫芦(由「三条」加一个「对子」所组成的牌。若别家也有此牌型,则比三条数字大小)----------------
        public int Cucurbit(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                if ((cards[0] == cards[1] && cards[1] != cards[2] && cards[3] == cards[2] && cards[4] == cards[2]) || (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] != cards[2] && cards[4] == cards[3]))
                {
                    paiType = PaiType.isHL;
                    maxPai = cards[2];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------同花(不构成顺子的五张同花色的牌。比花色后比大小)
        public int SameColor(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            paiType = PaiType.isTH;
                            maxPai = cards[4];
                            return 1;
                        }
                    }
                    return 0;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ------------------顺子(五张连续数字不同花色的牌组成。 以A为首的顺子最大,如果大家都是顺子,比最大的一张牌,如果大小还一样就比这张牌的花色,黑桃A顺)
        public int Straight(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor == false)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            return 0;
                        }
                    }
                    paiType = PaiType.isSZ;
                    maxPai = cards[4];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------------三条(牌型由三张相同的牌组成,以A为首的三条最大)
        public int Three(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                int Count = 0;
                int _count = 0;
                int j = 0;
                Array.Sort(cards);
                for (int i = 0; i < cards.Length; i++)
                {
                    if (cards[2] == cards[i])
                    {
                        Count++;
                    }
                    else
                    {
                        j = i;
                        for (int n = 0; n < cards.Length; n++)
                        {
                            if (cards[j] == cards[n] && n != j)
                            {
                                _count++;
                            }
                        }
                    }
                }
                if (Count == 3 && _count == 0)
                {
                    paiType = PaiType.isSanTiao;
                    maxPai = cards[2];
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            return 0;
        }
        #endregion
        #region ----------------二对(牌型中五张牌由两组两张同数字的牌所组成。若遇相同则先比这副牌中最大的一对,如又相同再比第二对,如果还是一样,比大对子中的最大花色)
        public int TwoTwo(int[] cards, bool isColor)
        {
            int count = 0;
            int count2 = 0;
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                for (int i = 0; i < cards.Length; i++)
                {
                    if (cards[1] == cards[i])
                    {
                        count++;
                    }
                    if (cards[3] == cards[i])
                    {
                        count2++;
                    }
                }
                if (count == 2 && count2 == 2 && cards[1] != cards[3])
                {
                    paiType = PaiType.isTwoDui;
                    maxPai = cards[3];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ---------------------对子(牌型由两张相同的牌加上三张单张所组成。如果大家都是对子,比对子的大小,如果对子也一样,比这个对子中的最大花色)
        public int Two(int[] cards, bool isColor)
        {
            int count = 0;
            int num = 0;
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                for (int i = 1; i < cards.Length; i++)
                {
                    if (cards[i] == cards[i - 1])
                    {
                        count++;
                        num = cards[i];
                    }
                }
                if (count == 1)
                {
                    paiType = PaiType.isDui;
                    maxPai = num;
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------散牌(由单一型态,不构成上面的牌型的五张散牌组成,先比最大一张牌的大小,如果大小一样,比这张牌的花色)
        public int SP(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor == false)
                {
                    Array.Sort(cards);
                    if (Straight(cards, isColor) > 0)
                    {
                        return 0;
                    }
                    else
                    {
                        for (int i = 1; i < cards.Length; i++)
                        {
                            if (cards[i - 1] == cards[i])
                            {
                                return 0;
                            }
                        }
                        paiType = PaiType.isSP;
                        maxPai = cards[4];
                        return 1;
                    }
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------------------------------判断玩家手中的牌的牌型,最大值,和花色-----------------------
        public int PDTypeAndMaxAndColor(CardNum[] cards)
        {
            int[] num = PMZ(cards);
            //PDColor(cards, out isColor, out paicolor);//isColor :手中的牌是否同色。paicolor:手中最大的一张牌的颜色
            isColor = PDColor(cards);
            int max = 0;
            if (StraightFlush(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 1;
            }
            else if (IronBranch(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 2;
            }
            else if (Cucurbit(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 3;
            }
            else if (SameColor(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 4;
            }
            else if (Straight(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 5;
            }
            else if (Three(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 6;
            }
            else if (TwoTwo(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 7;
            }
            else if (Two(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 8;
            }
            else if (SP(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 9;
            }
            else
            {
                return 0;
            }

        }
        #endregion
        #region -----------------------找到对应的牌型中,牌的最大的花色---------------
        public PaiColor ColorIndex(CardNum[] cards, int max)//cards 牌的枚举数组,max 最大的牌
        {
            if (cards.Length == 5)
            {
                int[] num = new int[5] {0,0,0,0,0};
                for (int i = 0; i < cards.Length; i++)
                {
                    if (max==(int)cards[i]%100)
                    {
                        num[i] = (int)cards[i]/100;
                    }
                }
                Array.Sort(num);
                switch (num[4])
                {
                case 1:
                    return PaiColor.FP;
                case 2:
                    return PaiColor.CH;
                case 3:
                    return PaiColor.RedTao;
                case 4:
                    return PaiColor.BlackTao;
                default :
                    return PaiColor.Not;
                }

            }
            return PaiColor.Not;
        }
        #endregion
        #region --------------------------将枚举类型的牌转化成牌面值-----------------
        public int[] PMZ(CardNum[] cards)
        {
            int[] num = new int[cards.Length];
            for (int i = 0; i < cards.Length; i++)
            {
                num[i] = ((int)cards[i]) % 100;
            }
            return num;
        }
        #endregion
        #region -----------------------判断玩家手中的牌的花色是否相同和返回最大的一张牌的花色--------------
        //public void PDColor(CardNum[] cards, out bool isColors, out PaiColor paiColors)
        //{
        //    paiColors = PaiColor.Not;
        //    int[] num = new int[cards.Length];
        //    int[] num2 = new int[cards.Length];
        //    for (int i = 0; i < cards.Length; i++)
        //    {
        //        num[i] = (int)cards[i] % 100;
        //        num2[i] = ((int)cards[i]) / 100;
        //    }
        //    if (num2[0] == num2[1] && num2[2] == num2[3] && num2[1] == num2[4] && num2[2] == num2[4])
        //    {
        //        isColors = true;
        //    }
        //    else
        //    {
        //        isColors = false;
        //    }
        //    int maxColor = num.Max();
        //    int index = Array.IndexOf(num, maxColor);
        //    maxColor = (int)cards[index] / 100;
        //    switch (maxColor)
        //    {
        //        case 1:
        //            paiColors = PaiColor.BlackTao;
        //            break;
        //        case 2:
        //            paiColors = PaiColor.RedTao;
        //            break;
        //        case 3:
        //            paiColors = PaiColor.CH;
        //            break;
        //        case 4:
        //            paiColors = PaiColor.FP;
        //            break;
        //    }
        //}
        public bool PDColor(CardNum[] cards)
        {
            int[] num2 = new int[cards.Length];
            for (int i = 0; i < cards.Length; i++)
            {
                num2[i] = ((int)cards[i]) / 100;
            }
            if (num2[0] == num2[1] && num2[2] == num2[3] && num2[1] == num2[4] && num2[2] == num2[4])
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}

 

 

 

 

 

 public enum CardNum
    {
        A0 = 108, A1=109, A2=110, A3=111, A4=112, A5=113, A6=114,//黑桃
        B0 = 208, B1=209, B2=210, B3=211, B4=212, B5=213, B6=214,//红桃
        C0 =308, C1 =309, C2 =310,C3 =311, C4 =312,C5 = 313,C6 = 314,//草花
        D0 = 408, D1 = 409, D2 = 410, D3= 411, D4 = 412, D5 = 413, D6 = 414,//方片
        invalid =500
    }
    public enum PaiType
    {
        Not = 0,        //没有牌型
        isTHS,          //同花顺
        isTZ,           //铁支
        isHL,           //葫芦
        isTH,           //同花
        isSZ,           //顺子
        isSanTiao,      //三条
        isTwoDui,        //两对
        isDui,          //一对
        isSP,           //散牌

    }
    public enum PaiColor
    {
        Not = 0,       //没有颜色
        BlackTao,      //黑桃
        RedTao,        //红桃
        CH,            //草花
        FP,            //方片
    }

以上是关于棋牌源码搭建-梭哈算法思路的主要内容,如果未能解决你的问题,请参考以下文章

网狐棋牌源码搭建2017年最新网狐荣耀棋牌源码搭建下载

人人玩棋牌电玩城全套源码搭建下载教程

网狐棋牌源码搭建教程之棋牌平台服务器架构

棋牌搭建教程之最新傲玩至尊版手机棋牌源码架设技巧

网狐6603全部架设过程 棋牌源码下载搭建教程

新大番薯棋牌牛牛源码安装搭建 微信h5牛牛大厅开发选择方式