麻将算法(七)胡牌之对子判断

本文详细介绍了判断麻将手牌是否可以胡牌的具体算法。通过筛选并移除手中的对子,对手牌进行连牌与同牌的判断,最终实现胡牌状态的识别。文章特别区分了自摸与非自摸的不同胡牌情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

判断一手牌中的牌是否可以胡牌,思路是选出将手牌中的对子,将手牌中的对子牌“去掉”后(将这个牌添加到一个叫DUIZI的list里),将去掉对子的手牌进行连牌与同牌判断

,将“连牌与同牌”的list进行M选N操作,如果选出的种类不等于0那么可以判定出是普通胡牌,对于自摸与非自摸的区分在于传入的是在“接牌”后形成的胡牌,还是其他玩家

“出完”牌后形成的胡牌。

     static List<int> ReconsCards(int[] cbCardIndex, List<FrontageItem> Frontage)
        {
            List<int> DuiZi = new List<int>();
            List<int> DuiZi1 = new List<int>();
            DuiZi.Clear();
            DuiZi1.Clear();
            for (int i = 0; i < cbCardIndex.Length; i++)
            {
                if (cbCardIndex[i] == 2)
                {
                    DuiZi1.Add(i);
                }
            }
            int[] DuiZi2 = new int[DuiZi1.Count];
            for (int a = 0; a < DuiZi2.Length; a++)
            {
                DuiZi2[a] = DuiZi1[a];
            }






            for (int b = 1; b < DuiZi2.Length; b++)
            {
                if (DuiZi2[b - 1] != (DuiZi2[b] - 1) && cbCardIndex[DuiZi2[b] - 1] == 0)
                {
                    cbCardIndex[DuiZi2[b]] = 0;
                    DuiZi.Add(DuiZi2[b]);
                    break;
                }
                else
                {

                    cbCardIndex[DuiZi2[b - 1]] = 0;
                    DuiZi.Add(DuiZi2[b - 1]);

                    break;
                }
            }
            for (int b = 0; b < DuiZi2.Length; b++)
            {
                if(DuiZi.Count==0)
                {
                    int value = IndexSwitchToCard(DuiZi2[b]);


                    if ((value & MASK_VALUE) == 9 || (value & MASK_VALUE) == 1)
                    {
                        cbCardIndex[DuiZi2[b]] = 0;
                        DuiZi.Add(DuiZi2[b]);
                        DuiZi2[b] = 0;
                        break;
                    }
                }

            }
            if (DuiZi2.Length == 1)
            {
                if (DuiZi2[0] != 0)
                {
                    cbCardIndex[DuiZi2[0]] = 0;
                    DuiZi.Add(DuiZi2[0]);
                }
            }

            if (DuiZi.Count==0)
            {
                for (int i = 0; i < cbCardIndex.Length; i++)
                {
                    if (cbCardIndex[i] >= 3)
                    {
                        if ((i % 9) < 7)
                        {
                            if (cbCardIndex[i] + cbCardIndex[i + 1] + cbCardIndex[i + 2] >= 3 && cbCardIndex[i + 1] == 1 && cbCardIndex[i + 2] == 1)
                            {
                                cbCardIndex[i] = cbCardIndex[i] - 2;
                                DuiZi.Add(i);
                                break;
                            }

                        }
                          if ((i % 9) > 1 && (i % 9) < 7)
                        {
                            if ((cbCardIndex[i] + cbCardIndex[i - 1] + cbCardIndex[i + 1] >= 3 && cbCardIndex[i + 1] == 1 && cbCardIndex[i - 1] == 1 && cbCardIndex[i + 2] != 3) ||( cbCardIndex[i] + cbCardIndex[i - 1] + cbCardIndex[i + 1] >= 3 && cbCardIndex[i + 1] == 1 && cbCardIndex[i - 1] == 1 && cbCardIndex[i + 2] == 3 && cbCardIndex[i - 2] == 3))
                            {
                                cbCardIndex[i] = cbCardIndex[i] - 2;
                                DuiZi.Add(i);
                                break;
                            }
                        }
                          if ((i % 9) > 1)
                        {
                            if (cbCardIndex[i] + cbCardIndex[i - 1] + cbCardIndex[i -2] >= 3 && cbCardIndex[i-1] == 1 && cbCardIndex[i -2] == 1 )
                            {
                                cbCardIndex[i] = cbCardIndex[i] - 2;
                                DuiZi.Add(i);
                                break;
                            }
                        }
                    }
                }
            }


            return DuiZi;
        }

下一章胡牌之整体比较

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值