Beispiel #1
0
        //对比扑克
        int CompareCard(int[] cbFirstData, int[] cbNextData, int cbCardCount)
        {
            //获取类型
            int cbNextType  = GetCardType(cbNextData, cbCardCount);
            int cbFirstType = GetCardType(cbFirstData, cbCardCount);

            //类型判断
            //大
            if (cbFirstType > cbNextType)
            {
                return(2);
            }

            //小
            if (cbFirstType < cbNextType)
            {
                return(1);
            }

            int i = 0;

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

                    //大
                    if (cbFirstValue > cbNextValue)
                    {
                        return(2);
                    }
                    //小
                    else if (cbFirstValue < cbNextValue)
                    {
                        return(1);
                    }
                    //等
                    else
                    {
                        continue;
                    }
                }
                //平
                if (i == cbCardCount)
                {
                    return(0);
                }
                //ASSERT(FALSE);
            }
            break;

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

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

                    //比较四条
                    if (cbFirstValue != cbNextValue)
                    {
                        return((cbFirstValue > cbNextValue)?2:1);
                    }

                    //比较单牌
                    //ASSERT(AnalyseResultFirst.cbSignedCount==1 && AnalyseResultNext.cbSignedCount==1);
                    cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[0];
                    cbNextValue  = AnalyseResultNext.cbSignedLogicVolue[0];
                    if (cbFirstValue != cbNextValue)
                    {
                        return((cbFirstValue > cbNextValue)?2:1);
                    }
                    else
                    {
                        return(0);
                    }
                }

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

                    //比较三条
                    if (cbFirstValue != cbNextValue)
                    {
                        return((cbFirstValue > cbNextValue)?2:1);
                    }

                    //葫芦牌型
                    if (CT_HU_LU == cbFirstType)
                    {
                        //比较对牌
                        //ASSERT(AnalyseResultFirst.cbLONGCount==1 && AnalyseResultNext.cbLONGCount==1);
                        cbFirstValue = AnalyseResultFirst.cbLONGLogicVolue[0];
                        cbNextValue  = AnalyseResultNext.cbLONGLogicVolue[0];
                        if (cbFirstValue != cbNextValue)
                        {
                            return((cbFirstValue > cbNextValue)?2:1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else                     //三条带单
                    {
                        //比较单牌
                        //ASSERT(AnalyseResultFirst.cbSignedCount==2 && AnalyseResultNext.cbSignedCount==2);

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

                            //大
                            if (cbFirstValue > cbNextValue)
                            {
                                return(2);
                            }
                            //小
                            else if (cbFirstValue < cbNextValue)
                            {
                                return(1);
                            }
                            //等
                            else
                            {
                                continue;
                            }
                        }
                        if (i == AnalyseResultFirst.cbSignedCount)
                        {
                            return(0);
                        }
                        //ASSERT(FALSE);
                    }
                }

                //对子数值
                i = 0;
                for (i = 0; i < AnalyseResultFirst.cbLONGCount; i++)
                {
                    int cbNextValue  = AnalyseResultNext.cbLONGLogicVolue[i];
                    int cbFirstValue = AnalyseResultFirst.cbLONGLogicVolue[i];
                    //大
                    if (cbFirstValue > cbNextValue)
                    {
                        return(2);
                    }
                    //小
                    else if (cbFirstValue < cbNextValue)
                    {
                        return(1);
                    }
                    //平
                    else
                    {
                        continue;
                    }
                }

                //比较单牌
                //ASSERT( i == AnalyseResultFirst.cbLONGCount);
                {
                    //ASSERT(AnalyseResultFirst.cbSignedCount==AnalyseResultNext.cbSignedCount && AnalyseResultNext.cbSignedCount>0);
                    //散牌数值
                    for (i = 0; i < AnalyseResultFirst.cbSignedCount; i++)
                    {
                        int cbNextValue  = AnalyseResultNext.cbSignedLogicVolue[i];
                        int cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[i];
                        //大
                        if (cbFirstValue > cbNextValue)
                        {
                            return(2);
                        }
                        //小
                        else if (cbFirstValue < cbNextValue)
                        {
                            return(1);
                        }
                        //等
                        else
                        {
                            continue;
                        }
                    }
                    //平
                    if (i == AnalyseResultFirst.cbSignedCount)
                    {
                        return(0);
                    }
                }
                break;
            }

            case CT_SHUN_ZI:            //顺子
            case CT_TONG_HUA_SHUN:      //同花顺
            {
                //数值判断
                int cbNextValue  = GetCardLogicValue(cbNextData[0]);
                int cbFirstValue = GetCardLogicValue(cbFirstData[0]);

                bool bFirstmin = (cbFirstValue == (GetCardLogicValue(cbFirstData[1]) + 9));
                bool bNextmin  = (cbNextValue == (GetCardLogicValue(cbNextData[1]) + 9));

                //大小顺子
                if ((bFirstmin == true) && (bNextmin == false))
                {
                    return(1);
                }

                //大小顺子
                else if ((bFirstmin == false) && (bNextmin == true))
                {
                    return(2);
                }

                //等同顺子
                else
                {
                    //平
                    if (cbFirstValue == cbNextValue)
                    {
                        return(0);
                    }
                    return((cbFirstValue > cbNextValue)?2:1);
                }
            }
            break;

            case CT_TONG_HUA:                   //同花
            {
                //散牌数值
                for (i = 0; i < cbCardCount; i++)
                {
                    int cbNextValue  = GetCardLogicValue(cbNextData[i]);
                    int cbFirstValue = GetCardLogicValue(cbFirstData[i]);
                    if (cbFirstValue == cbNextValue)
                    {
                        continue;
                    }
                    return((cbFirstValue > cbNextValue)?2:1);
                }
                //平
                if (i == cbCardCount)
                {
                    return(0);
                }
            }
            break;
            }

            return(0);
        }
Beispiel #2
0
        //分析扑克
        void AnalysebCardData(int[] cbCardData, int cbCardCount, tagAnalyseResult AnalyseResult)
        {
            //设置结果
            //AnalyseResult = new tagAnalyseResult();

            //扑克分析
            for (int i = 0; i < cbCardCount; i++)
            {
                //变量定义
                int   cbSameCount    = 1;
                int[] cbSameCardData = new int[] { cbCardData[i], 0, 0, 0 };
                int   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;
                    Array.Copy(cbSameCardData, 0, AnalyseResult.cbSignedCardData, (AnalyseResult.cbSignedCount++) * cbSameCount, cbSameCount);
                    break;
                }

                case 2:                 //两张
                {
                    AnalyseResult.cbLONGLogicVolue[AnalyseResult.cbLONGCount] = cbLogicValue;
                    Array.Copy(cbSameCardData, 0, AnalyseResult.cbLONGCardData, (AnalyseResult.cbLONGCount++) * cbSameCount, cbSameCount);
                    break;
                }

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

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

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

            return;
        }
Beispiel #3
0
        //获取类型
        int GetCardType(int[] cbCardData, int cbCardCount)
        {
            //数据校验
            //ASSERT(cbCardCount == DzCardDefine.MAX_CENTERCOUNT);
            if (cbCardCount != DzCardDefine.MAX_CENTERCOUNT)
            {
                return(0);
            }

            //变量定义
            bool cbSameColor = true, bLineCard = true;
            int  cbFirstColor = GetCardColor(cbCardData[0]);
            int  cbFirstValue = GetCardLogicValue(cbCardData[0]);

            //牌形分析
            for (int 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 ((bLineCard == false) && (cbFirstValue == 14))
            {
                int i = 1;
                for (i = 1; i < cbCardCount; i++)
                {
                    int cbLogicValue = GetCardLogicValue(cbCardData[i]);
                    if ((cbFirstValue != (cbLogicValue + i + 8)))
                    {
                        break;
                    }
                }
                if (i == cbCardCount)
                {
                    bLineCard = true;
                }
            }

            //皇家同花顺
            if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
            {
                return(CT_KING_TONG_HUA_SHUN);
            }

            //顺子类型
            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, AnalyseResult);

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

            return(CT_SINGLE);
        }