示例#1
0
        //比牌
        public static bool CompareCard(byte[] cbFirstData, byte[] cbNextData, byte cbCardCount)
        {
            //获取类型
            byte cbNextType  = GetCardType(cbNextData, cbCardCount);
            byte cbFirstType = GetCardType(cbFirstData, cbCardCount);

            //类型判断
            if (cbFirstType != cbNextType)
            {
                return(cbFirstType > cbNextType?true:false);
            }

            //简单类型
            switch (cbFirstType)
            {
            case CT_SINGLE:          //单牌
            {
                //对比数值
                for (byte i = 0; i < cbCardCount; i++)
                {
                    byte cbNextValue  = GetCardLogicValue(cbNextData[i]);
                    byte cbFirstValue = GetCardLogicValue(cbFirstData[i]);
                    if (cbFirstValue != cbNextValue)
                    {
                        return(cbFirstValue > cbNextValue);
                    }
                }

                //对比花色
                return(GetCardColor(cbFirstData[0]) > GetCardColor(cbNextData[0]));
            }

            case CT_HU_LU:           //葫芦
            case CT_TIE_ZHI:         //铁支
            case CT_ONE_DOUBLE:      //对子
            case CT_TWO_DOUBLE:      //两对
            case CT_THREE_TIAO:      //三条
            {
                //分析扑克
                tagAnalyseResult AnalyseResultNext  = new tagAnalyseResult();
                tagAnalyseResult AnalyseResultFirst = new tagAnalyseResult();
                AnalysebCardData(cbNextData, cbCardCount, ref AnalyseResultNext);
                AnalysebCardData(cbFirstData, cbCardCount, ref AnalyseResultFirst);

                //四条数值
                if (AnalyseResultFirst.cbFourCount > 0)
                {
                    byte cbNextValue  = AnalyseResultNext.cbFourLogicVolue[0];
                    byte cbFirstValue = AnalyseResultFirst.cbFourLogicVolue[0];
                    return(cbFirstValue > cbNextValue);
                }

                //三条数值
                if (AnalyseResultFirst.cbThreeCount > 0)
                {
                    byte cbNextValue  = AnalyseResultNext.cbThreeLogicVolue[0];
                    byte cbFirstValue = AnalyseResultFirst.cbThreeLogicVolue[0];
                    return(cbFirstValue > cbNextValue);
                }

                //对子数值
                for (byte i = 0; i < AnalyseResultFirst.cbDoubleCount; i++)
                {
                    byte cbNextValue  = AnalyseResultNext.cbDoubleLogicVolue[i];
                    byte cbFirstValue = AnalyseResultFirst.cbDoubleLogicVolue[i];
                    if (cbFirstValue != cbNextValue)
                    {
                        return(cbFirstValue > cbNextValue);
                    }
                }

                //散牌数值
                for (byte i = 0; i < AnalyseResultFirst.cbSignedCount; i++)
                {
                    byte cbNextValue  = AnalyseResultNext.cbSignedLogicVolue[i];
                    byte cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[i];
                    if (cbFirstValue != cbNextValue)
                    {
                        return(cbFirstValue > cbNextValue);
                    }
                }

                //对子花色
                if (AnalyseResultFirst.cbDoubleCount > 0)
                {
                    byte cbNextColor  = GetCardColor(AnalyseResultNext.cbDoubleCardData[0]);
                    byte cbFirstColor = GetCardColor(AnalyseResultFirst.cbDoubleCardData[0]);
                    return(cbFirstColor > cbNextColor);
                }

                //散牌花色
                if (AnalyseResultFirst.cbSignedCount > 0)
                {
                    byte cbNextColor  = GetCardColor(AnalyseResultNext.cbSignedCardData[0]);
                    byte cbFirstColor = GetCardColor(AnalyseResultFirst.cbSignedCardData[0]);
                    return(cbFirstColor > cbNextColor);
                }

                break;
            }

            case CT_SHUN_ZI:         //顺子
            case CT_TONG_HUA:        //同花
            case CT_TONG_HUA_SHUN:   //同花顺
            {
                //数值判断
                byte cbNextValue  = GetCardLogicValue(cbNextData[0]);
                byte cbFirstValue = GetCardLogicValue(cbFirstData[0]);
                if (cbFirstValue != cbNextValue)
                {
                    return(cbFirstValue > cbNextValue);
                }

                //花色判断
                byte cbNextColor  = GetCardColor(cbNextData[0]);
                byte cbFirstColor = GetCardColor(cbFirstData[0]);

                return(cbFirstColor > cbNextColor);
            }
            }

            return(false);
        }
示例#2
0
        //获取牌型
        public static byte GetCardType(byte[] cardData, byte cardCount)
        {
            byte[] cbCardData  = new byte[5];
            byte   cbCardCount = cardCount;

            Buffer.BlockCopy(cardData, 0, cbCardData, 0, cardCount);

            SortCardList(ref cbCardData, cbCardCount);
            //简单牌形
            switch (cbCardCount)
            {
            case 1:  //单牌
            {
                return(CT_SINGLE);
            }

            case 2:  //对牌
            {
                return((GetCardLogicValue(cbCardData[0]) == GetCardLogicValue(cbCardData[1]))?CT_ONE_DOUBLE:CT_SINGLE);
            }
            }

            //五条类型
            if (cbCardCount == 5)
            {
                //变量定义
                bool cbSameColor = true, bLineCard = true;
                byte cbFirstColor = GetCardColor(cbCardData[0]);
                byte cbFirstValue = GetCardLogicValue(cbCardData[0]);

                //牌形分析
                for (byte i = 1; i < cbCardCount; i++)
                {
                    //数据分析
                    if (GetCardColor(cbCardData[i]) != cbFirstColor)
                    {
                        cbSameColor = false;
                    }
                    if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
                    {
                        bLineCard = false;
                    }

                    //结束判断
                    if ((cbSameColor == false) && (bLineCard == false))
                    {
                        break;
                    }
                }

                //顺子类型
                if ((cbSameColor == false) && (bLineCard == true))
                {
                    return(CT_SHUN_ZI);
                }

                //同花类型
                if ((cbSameColor == true) && (bLineCard == false))
                {
                    return(CT_TONG_HUA);
                }

                //同花顺类型
                if ((cbSameColor == true) && (bLineCard == true))
                {
                    return(CT_TONG_HUA_SHUN);
                }
            }

            //扑克分析
            tagAnalyseResult AnalyseResult = new tagAnalyseResult();

            AnalysebCardData(cbCardData, cbCardCount, ref AnalyseResult);

            //类型判断
            if (AnalyseResult.cbFourCount == 1)
            {
                return(CT_TIE_ZHI);
            }
            if (AnalyseResult.cbDoubleCount == 2)
            {
                return(CT_TWO_DOUBLE);
            }
            if ((AnalyseResult.cbDoubleCount == 1) && (AnalyseResult.cbThreeCount == 1))
            {
                return(CT_HU_LU);
            }
            if ((AnalyseResult.cbThreeCount == 1) && (AnalyseResult.cbDoubleCount == 0))
            {
                return(CT_THREE_TIAO);
            }
            if ((AnalyseResult.cbDoubleCount == 1) && (AnalyseResult.cbSignedCount == 3))
            {
                return(CT_ONE_DOUBLE);
            }

            return(CT_SINGLE);
        }
示例#3
0
        //分析扑克
        public static void AnalysebCardData(byte[] cbCardData, byte cbCardCount, ref tagAnalyseResult AnalyseResult)
        {
            //设置结果
            //ZeroMemory(&AnalyseResult,sizeof(AnalyseResult));

            //扑克分析
            for (byte i = 0; i < cbCardCount; i++)
            {
                //变量定义
                byte   cbSameCount    = 1;
                byte[] cbSameCardData = new byte[4] {
                    cbCardData[i], 0, 0, 0
                };
                byte cbLogicValue = GetCardLogicValue(cbCardData[i]);

                //获取同牌
                for (int j = i + 1; j < cbCardCount; j++)
                {
                    //逻辑对比
                    if (GetCardLogicValue(cbCardData[j]) != cbLogicValue)
                    {
                        break;
                    }

                    //设置扑克
                    cbSameCardData[cbSameCount++] = cbCardData[j];
                }

                //保存结果
                switch (cbSameCount)
                {
                case 1:      //单张
                {
                    AnalyseResult.cbSignedLogicVolue[AnalyseResult.cbSignedCount] = cbLogicValue;
                    //CopyMemory(&AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount++)*cbSameCount],cbSameCardData,cbSameCount);
                    Buffer.BlockCopy(cbSameCardData, 0, AnalyseResult.cbSignedCardData, (AnalyseResult.cbSignedCount++) * cbSameCount, cbSameCount);
                    break;
                }

                case 2:      //两张
                {
                    AnalyseResult.cbDoubleLogicVolue[AnalyseResult.cbDoubleCount] = cbLogicValue;
                    //CopyMemory(&AnalyseResult.cbDoubleCardData[(AnalyseResult.cbDoubleCount++)*cbSameCount],cbSameCardData,cbSameCount);
                    Buffer.BlockCopy(cbSameCardData, 0, AnalyseResult.cbDoubleCardData, (AnalyseResult.cbDoubleCount++) * cbSameCount, cbSameCount);
                    break;
                }

                case 3:      //三张
                {
                    AnalyseResult.cbThreeLogicVolue[AnalyseResult.cbThreeCount] = cbLogicValue;
                    //CopyMemory(&AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount++)*cbSameCount],cbSameCardData,cbSameCount);
                    Buffer.BlockCopy(cbSameCardData, 0, AnalyseResult.cbThreeCardData, (AnalyseResult.cbThreeCount++) * cbSameCount, cbSameCount);
                    break;
                }

                case 4:      //四张
                {
                    AnalyseResult.cbFourLogicVolue[AnalyseResult.cbFourCount] = cbLogicValue;
                    //CopyMemory(&AnalyseResult.cbFourCardData[(AnalyseResult.cbFourCount++)*cbSameCount],cbSameCardData,cbSameCount);
                    Buffer.BlockCopy(cbSameCardData, 0, AnalyseResult.cbFourCardData, (AnalyseResult.cbFourCount++) * cbSameCount, cbSameCount);
                    break;
                }
                }

                //设置递增
                i += (byte)(cbSameCount - 1);
            }

            return;
        }