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

梭哈游戏使用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,            //方片
    }

时间: 2024-10-04 08:17:44

棋牌源码搭建-梭哈算法思路的相关文章

棋牌源码开发-牛牛算法思路

1.牌型大小  本牌型依次大小为: K.Q.J.10.9.8.7.6.5.4.3.2 .A 2.出牌顺序   每位玩家将牌型编排好之后可以出牌,庄家是最后一个亮牌的. 3.牌型,特殊牌型   J.Q.K都是当10点,然后A是当1点,其他的牌型当自身的点数. 4.牌型组合  牌局开始每个人手中都有五张牌,然后玩家需要将手中任意三张牌凑成10点或20点或30点都可以,这样是被称之为牛.接下来在将其余的两张的点数相加得出几点.去掉十位数,只留个位数来进行比较,如果接下来两张的相加点数也正好是整数的话,

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

一,棋牌类服务器的特点 1,棋牌类不分区不分服 一般来说,棋牌游戏都是不分区不分服的.所以棋牌类服务器要满足随着用户量的增加而扩展的需要. 2,房间模式 即在同一局游戏中就是在同一个房间中,同一个房间中的人可以接收到其他人的消息. 3,每个房间的操作必须是顺序性 这个特性类似与一般游戏的回合制,每个玩家的操作都是有顺序性的. 二,需要解决的技术点 1,数据共享 因为棋牌类游戏不分区不分服(棋牌源码搭建 www.yasewl.com),我们在设计服务器的时候,是按世界服的思想去设计,即服务器是一个

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

2017年最新网狐荣耀棋牌源码:含大厅全套源码+客户端+服务端+网站+后台+完整数据库 (更多详情网狐棋牌源码搭建 www.yasewl.com QQ:2189563389)

win7H5棋牌源码搭建修改mac地址的三种方法

H5棋牌源码搭建出租出售,都可联系Q1446595067官网: h5.haozibbs.com Win7修改MAC地址方法有以下三种: 方法一:使用Win7MAC地址修改工具 1,只适用于windows7系统的网卡MAC地址修改.XP的可以用,但没做什么测试. 2,部分windows7下的无线网卡地址无法修改,理论上也可以使用本软件修改. 3,修改MAC地址前,请先在开始菜单-运行,输入cmd打开控制台,输入getmac获取原来网卡MAC并记下来,用于以后可以改回来. 4,软件使用方法很简单,只

微信h5牛牛棋牌源码搭建架设详细教程

HTML的文件结构:html head网页头部信息(微信h5牛牛棋牌源码搭建架设Q_2189563389)/head body网页主体正文部分/body /html HTML的基本标记:定义网页背景色--bgcolor body bgcolor="背景颜色 " 设置背景图片--backgroung body background="图片的地址 " 设置文字颜色--text body text="文HTML的文件结构:<(h5牛牛棋牌平台开发www.y

棋牌源码搭建教程之棋牌游戏AI算法

棋牌游戏客户端实现采用Flash 9开发,服务端采用Win32+VC6开发(基于IOCP),数据库网关采用Win32+VC6开发(基于IOCP,MySQL5实现了处理线程池和数据库连接池).虽然服务器端去年就已经完成,但相应的机器人AI算法一直没有能力去实现.今天把它拿到Blog上来希望有机会和感兴趣的兄弟们探讨下. Kevin在他的Blog上给出了他的实现,其给出的算法思想是用宽度优先生成一棵搜索树,再根据玩牌的技巧进行剪枝与判权,机器人的AI能够像养成类游戏那样,实现在蹂躏下慢慢成长,水平逐

网狐棋牌源码搭建问题难点棋牌平台搭建下载教程

网狐框架虽然功能复杂繁多,但总体框架还是很清晰的.服务器端主要包裹: 1.登录服务器 唯一一个,启动时需要连接中心服务器.中转玩家的消息,相当于别的游戏服务器的gate. 2.中心服务器 全局服务器,登陆服务器和加载服务器都需要连接它. 3.加载服务器 游戏逻辑功能服务器,通过dll加载的方式加载具体游戏,每个游戏就是一个dll.它还调用另一个dll:游戏服务.该dll负责所有游戏统一都有的功能,例如桌子座位管理等. 内核引擎,看了下源代码,代码量还是很大的,采用了windows完成端口,soc

基于HTML5+WebSocket+JAVA的房卡棋牌源码搭建游戏,从入门到放弃(三)

Q1446595067官网:h5.haozibbs.com 之前我们已经完成了一个有房间的五指棋游戏,现在我们将进一步来完善这个东西.这一次我们打算新增的功能有: 之前我们增加了房间,但并没有限制房间只能进入2个人 增加一个守护线程,统计当前房间的数量,后面我们将继续完善这个守护线程的功能. 展示上一个棋子落在何处 离开房间后会减少房间的人数,并回收房间 思考 第一个功能应该是发生在建立连接的时候,如果房间里超过2人,则返回前端一个错误. 第二个我们需要创建一个新的线程. 第三个是一个纯粹的前端

网狐棋牌源码教程 -安装运营帮助文档

v6603游戏数据库文档.doc6603平台图形文件要求6603经验等级与经验值的关系.docv6603游戏数据库字典.docv6603网狐游戏升级.docv6603网狐游戏服务启动配置方法.docv6603网站数据库字典.doc6603棋牌管理系统操作手册.doc6603机器人操作说明.doc库存值的解释.doc大厅搭建填写.doc棋牌_服务器填写.doc地址规则说明.doc网狐6603棋牌游戏产品介绍.doc 为棋牌爱好者免费提供视频教程下载.棋牌打包工具.棋牌架设工具.棋牌帮助文档.棋牌源