Esempio n. 1
0
 /// <summary>
 /// 没脑子的AI
 /// </summary>
 private void DoNormalAI()
 {
     if (RoomMaJiangProxy.Instance.AskPokerGroup != null)
     {
         for (int i = 0; i < RoomMaJiangProxy.Instance.AskPokerGroup.Count; ++i)
         {
             if ((OperatorType)RoomMaJiangProxy.Instance.AskPokerGroup[i].CombinationType == OperatorType.Hu)
             {
                 MaJiangGameCtrl.Instance.ClientSendOperate(OperatorType.Hu, null);
                 return;
             }
         }
         MaJiangGameCtrl.Instance.ClientSendOperate(OperatorType.Pass, null);
     }
     if (RoomMaJiangProxy.Instance.CurrentState == MahjongGameState.DrawPoker || RoomMaJiangProxy.Instance.CurrentState == MahjongGameState.Operate)
     {
         if (RoomMaJiangProxy.Instance.CurrentRoom.CurrentOperator == RoomMaJiangProxy.Instance.PlayerSeat)
         {
             Poker poker = RoomMaJiangProxy.Instance.PlayerSeat.HitPoker;
             if (poker == null || MahJongHelper.CheckUniversal(poker, RoomMaJiangProxy.Instance.PlayerSeat.UniversalList))
             {
                 for (int i = 0; i < RoomMaJiangProxy.Instance.PlayerSeat.PokerList.Count; ++i)
                 {
                     poker = RoomMaJiangProxy.Instance.PlayerSeat.PokerList[i];
                     if (!MahJongHelper.CheckUniversal(poker, RoomMaJiangProxy.Instance.PlayerSeat.UniversalList))
                     {
                         break;
                     }
                 }
             }
             MaJiangGameCtrl.Instance.ClientSendPlayPoker(poker);
         }
     }
 }
Esempio n. 2
0
    /// <summary>
    /// 和牌算法效率测试
    /// </summary>
    private void EfficiencyTest()
    {
        long before  = TimeUtil.GetTimestampMS();
        int  huTimes = 0;

        for (int i = 0; i < 100000; ++i)
        {
            List <Poker> lst = new List <Poker>();
            for (int j = 0; j < 13; ++j)
            {
                int color = UnityEngine.Random.Range(1, 6);
                int size  = color > 3 ? UnityEngine.Random.Range(1, 4) : UnityEngine.Random.Range(1, 10);
                lst.Add(new Poker(0, color, size));
            }
            List <List <CardCombination> > result = MahJongHelper.CheckTing(lst, new List <Poker>()
            {
                new Poker(0, 5, 1)
            }, true, true, true);
            if (result != null && result.Count > 0)
            {
                ++huTimes;
            }
        }
        long after = TimeUtil.GetTimestampMS();

        Debug.Log("计算之前时间戳=" + before);
        Debug.Log("计算之后时间戳=" + after);
        Debug.Log("计算所需时间=" + (after - before) + "毫秒");
        Debug.Log("胡了" + huTimes + "次");
    }
Esempio n. 3
0
    /// <summary>
    /// 检测亮喜单元测试
    /// </summary>
    private void CheckXiUnitTest()
    {
        bool result = MahJongHelper.CheckLiangXi(new List <Poker>()
        {
            new Poker(3, 9),
            new Poker(5, 1),
            new Poker(5, 2),
            new Poker(5, 3),
        });

        Debug.Log(result);
    }
Esempio n. 4
0
    /// <summary>
    /// 手牌排序
    /// </summary>
    /// <param name="lst"></param>
    public void Sort(List <MaJiangCtrl> lst, List <Poker> universal)
    {
        if (lst == null || lst.Count == 0 || lst[0].Poker.size == 0)
        {
            return;
        }

        string temp = "排序后的手牌为:";

        for (int i = 0; i < lst.Count; ++i)
        {
            temp += lst[i].Poker.ToString() + "  ";
        }

        List <Poker> pokers = new List <Poker>();

        for (int i = 0; i < lst.Count; ++i)
        {
            pokers.Add(lst[i].Poker);
        }
        MahJongHelper.Sort(pokers, universal, RoomMaJiangProxy.Instance.Rule.UniversalSortType);

        for (int i = 0; i < pokers.Count; ++i)
        {
            for (int j = lst.Count - 1; j >= 0; --j)
            {
                if (lst[j].Poker == pokers[i])
                {
                    MaJiangCtrl majiang = lst[j];
                    lst.Remove(majiang);
                    lst.Insert(i, majiang);
                    break;
                }
            }
        }
#if DEBUG_LOG
        string log = "排序后的手牌为:";
        for (int i = 0; i < lst.Count; ++i)
        {
            log += lst[i].Poker.ToString() + "  ";
        }
        Debug.Log(log);
#endif
    }
Esempio n. 5
0
    /// <summary>
    /// 生成麻将
    /// </summary>
    /// <param name="seatPos">座位号</param>
    /// <param name="poker">牌</param>
    /// <param name="layer">层级</param>
    /// <returns></returns>
    public MaJiangCtrl SpawnMaJiang(int seatPos, Poker poker, string layer)
    {
        MaJiangCtrl ctrl = m_WallPool.Spawn((poker == null || poker.color == 0) ? Poker.DefaultName : poker.ToString()).gameObject.GetOrCreatComponent <MaJiangCtrl>();

        ctrl.Color = m_CurrentColor;

        SeatEntity seat        = RoomMaJiangProxy.Instance.GetSeatBySeatId(seatPos);
        bool       isUniversal = false;

        if (seat != null)
        {
            isUniversal = MahJongHelper.CheckUniversal(poker, seat.UniversalList);
        }
        ctrl.Init(poker, isUniversal);
        ctrl.gameObject.SetLayer(LayerMask.NameToLayer(layer));

        m_AllPoker.Add(ctrl);
        return(ctrl);
    }
Esempio n. 6
0
        public void Show(MaJiangCtrl ctrl, List <Poker> lst)
        {
#if IS_HONGHU || IS_LEPING
            return;
#endif
#if IS_TAILAI
            if (!RoomMaJiangProxy.Instance.PlayerSeat.IsTing)
            {
                return;
            }
#endif
            if (RoomMaJiangProxy.Instance.CurrentRoom.Status == RoomEntity.RoomStatus.Ready)
            {
                return;
            }
            if (RoomMaJiangProxy.Instance.CurrentRoom.isReplay)
            {
                return;
            }
            if (RoomMaJiangProxy.Instance.CurrentRoom.Status == RoomEntity.RoomStatus.Settle)
            {
                return;
            }
            if (RoomMaJiangProxy.Instance.CurrentRoom.CurrentOperator != RoomMaJiangProxy.Instance.PlayerSeat && ctrl != null)
            {
                return;
            }
            if (RoomMaJiangProxy.Instance.CurrentState == MahjongGameState.PlayPoker && ctrl != null)
            {
                return;
            }
            if (lst == null || lst.Count == 0)
            {
                Close();
                return;
            }
            gameObject.SetActive(true);
            MahJongHelper.SimpleSort(lst);
            for (int i = 0; i < m_HuList.Count; ++i)
            {
                m_HuList[i].SetActive(false);
            }
            if (lst.Count < SHOW_ALL_HU)
            {
                m_ImageAllHu.gameObject.SetActive(false);
                m_ImageHu.gameObject.SetActive(true);
                for (int i = 0; i < lst.Count; ++i)
                {
                    GameObject go = null;

                    if (i < m_HuList.Count)
                    {
                        go = m_HuList[i];
                        go.SetActive(true);
                    }
                    else
                    {
                        go = new GameObject();
                        m_HuList.Add(go);
                        go.SetParent(m_Container);
                    }
                    Image img = go.GetOrCreatComponent <Image>();
                    img.overrideSprite = MahJongManager.Instance.LoadPokerSprite(lst[i], false);
                    img.SetNativeSize();

                    //AssetBundleManager.Instance.LoadSpriteAsync(path, imgName,(Sprite sprite)=>
                    //{
                    //    img.overrideSprite = sprite;
                    //    img.SetNativeSize();
                    //});
                }
                m_BG.SafeSetActive(true);
                m_BG.rectTransform.sizeDelta = new Vector2(lst.Count * 100 + 100, m_BG.rectTransform.sizeDelta.y);
            }
            else
            {
                m_ImageAllHu.gameObject.SetActive(true);
                m_ImageHu.gameObject.SetActive(false);
                m_BG.SafeSetActive(false);
            }
        }
Esempio n. 7
0
    public void SetUI(int seatPos, bool isPlayer, string avatar, string nickName, int gold,
                      int settle, bool isBanker, List <Poker> handList, Poker hitPoker,
                      List <PokerCombinationEntity> pengList, List <IncomeDetailEntity> settleInfo,
                      List <IncomeDetailEntity> huScoreInfo, bool isWiner, List <Poker> prob, int probTimes,
                      bool isLoser, bool isZimo, List <Poker> universal, int totalHuScore, Poker luckPoker,
                      bool isTing, List <List <Poker> > zhidui, int bankerPos, bool hasFeng, List <Poker> desktopPoker,
                      int direction)
    {
        if (m_HuType != null)
        {
            if (isLoser)
            {
                m_HuType.SafeSetText("点炮");
            }
            if (isZimo && isWiner)
            {
                m_HuType.SafeSetText("自摸");
            }
            if (isWiner && !isZimo)
            {
                m_HuType.SafeSetText("胡");
            }
        }

        if (m_ImgTing != null)
        {
            m_ImgTing.gameObject.SetActive(isTing);
        }

        m_Bg.overrideSprite = m_SpriteBG[isWiner ? 1 : 0];
        TextureManager.Instance.LoadHead(avatar, OnAvatarLoadFinish);
        m_TextNickName.SafeSetText(nickName);
        m_GetGold.SafeSetText(settle.ToString(ConstDefine.STRING_FORMAT_SIGN));
        m_ImageBanker.gameObject.SetActive(isBanker);
        string strInfo = string.Empty;

        bool isLaZi = false;

        int taiCount = 0;

        if (settleInfo != null)
        {
            for (int i = 0; i < settleInfo.Count; ++i)
            {
                cfg_configEntity entity = cfg_configDBModel.Instance.Get(settleInfo[i].typeId);
                if (entity != null)
                {
#if IS_LONGGANG//龙港算台数
                    strInfo += entity.name + (settleInfo[i].poker == null? "": "(" + settleInfo[i].poker.ToChinese() + ")") + settleInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                    strInfo += "台  ";
#elif IS_LEPING || IS_HONGHU || IS_TAILAI
                    strInfo += entity.name;
                    if (entity.name.Equals("打宝"))
                    {
                        strInfo += isWiner ? "+" : "-";
                        strInfo += settleInfo[i].times.ToString();
                    }
                    if (entity.name.Equals("亮喜"))
                    {
                        strInfo += "×";
                        strInfo += settleInfo[i].times.ToString();
                    }
                    strInfo += "  ";
#elif IS_WANGQUE
                    if (entity.name.Equals("辣子"))
                    {
                        isLaZi = true;
                        continue;
                    }

                    if (huScoreInfo != null && huScoreInfo.Count > 0)
                    {
                        strInfo += entity.name + (settleInfo[i].poker == null ? "" : "(" + settleInfo[i].poker.ToChinese() + ")") + settleInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                        strInfo += "台  ";
                    }
                    else
                    {
                        strInfo += entity.name + (settleInfo[i].times == 0 ? "" : settleInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN));
                        strInfo += "  ";
                    }
#elif IS_LAOGUI
                    strInfo += entity.name + settleInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                    strInfo += "  ";
#else
                    strInfo += entity.name + (settleInfo[i].times == 0 ? "" : settleInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN));
                    strInfo += "  ";
#endif
                }
                taiCount += settleInfo[i].times;
            }
        }
#if IS_LONGGANG
        if (taiCount > 3)
        {
            taiCount = 3;
        }
#endif

        int huScore = 0;
        if (huScoreInfo != null)
        {
            for (int i = 0; i < huScoreInfo.Count; ++i)
            {
                Debug.Log(huScoreInfo[i].typeId);
                cfg_configEntity entity = cfg_configDBModel.Instance.Get(huScoreInfo[i].typeId);
                if (entity != null)
                {
#if IS_LONGGANG//龙港算胡数
                    strInfo += entity.name + (huScoreInfo[i].poker == null ? "" : "(" + huScoreInfo[i].poker.ToChinese() + ")") + huScoreInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                    strInfo += "胡  ";
#elif IS_WANGQUE
                    strInfo += entity.name + (huScoreInfo[i].poker == null ? "" : "(" + huScoreInfo[i].poker.ToChinese() + ")") + huScoreInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                    strInfo += "胡  ";
#else
                    strInfo += entity.name + huScoreInfo[i].times.ToString(ConstDefine.STRING_FORMAT_SIGN);
                    strInfo += "  ";
#endif
                }
                huScore += huScoreInfo[i].times;
            }
        }
#if IS_LONGGANG//龙港算总胡数
        strInfo += string.Format("{0}台{1}胡={2}", taiCount, huScore, totalHuScore);
#elif IS_WANGQUE
        if (totalHuScore > 0)
        {
            strInfo += string.Format("{0}台{1}胡={2}", taiCount, huScore, totalHuScore);
        }
#endif
#if !IS_LAOGUI
        if (prob != null && probTimes != 0)
        {
            strInfo += "抓马" + probTimes.ToString(ConstDefine.STRING_FORMAT_SIGN);
        }
#endif


        m_TextHuInfo.SafeSetText(strInfo);

        if (hitPoker != null)
        {
            handList.Add(hitPoker);
        }

        MahJongHelper.Sort(handList, universal, RoomMaJiangProxy.Instance.Rule.UniversalSortType);

        Vector2 handCellSize = m_HandPokerContainer.GetComponent <GridLayoutGroup>().cellSize;

        UIViewManager.Instance.LoadItemAsync("UIItemMahjong", (GameObject prefab) =>
        {
            if (this == null)
            {
                return;
            }

            for (int i = 0; i < handList.Count; ++i)
            {
                GameObject go      = Instantiate(prefab);
                UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                bool isDim         = false;
                bool isHu          = false;
                bool isBao         = false;
                bool isMa          = false;
                bool isUniversal   = false;
                bool isPeng        = false;
                for (int j = 0; j < zhidui.Count; ++j)
                {
                    if (MahJongHelper.ContainPoker(handList[i], zhidui[j]))
                    {
                        isDim = true;
                        break;
                    }
                }
                if (handList[i] == hitPoker && isWiner)
                {
                    isHu = true;
                }
                if (MahJongHelper.CheckUniversal(handList[i], universal))
                {
                    isUniversal = true;
                }
                item.SetUI(handList[i], isHu, isBao, isMa, isUniversal, isPeng, isDim);
                go.SetParent(m_HandPokerContainer);
            }

            float currentX = 0f;
            if (pengList != null)
            {
                m_PengPokerContainer.transform.position = new Vector3(m_HandPokerContainer.transform.position.x + (handList.Count * (handCellSize.x / 2)), m_PengPokerContainer.transform.position.y, m_PengPokerContainer.transform.position.z);
                for (int i = 0; i < pengList.Count; ++i)
                {
                    if (pengList[i].CombinationType == OperatorType.BuXi)
                    {
                        continue;
                    }
                    for (int j = 0; j < pengList[i].PokerList.Count; ++j)
                    {
                        GameObject go      = Instantiate(prefab);
                        UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                        bool isDim         = false;
                        bool isHu          = false;
                        bool isBao         = false;
                        bool isMa          = false;
                        bool isUniversal   = false;
                        bool isPeng        = true;
                        item.SetSize(handCellSize);
                        if (pengList[i].PokerList[j].pos != seatPos)
                        {
                            isDim = true;
                        }
                        go.SetParent(m_PengPokerContainer);
                        go.transform.localPosition = new Vector3(currentX, 0f, 0f);
                        currentX += handCellSize.x;
                        item.SetUI(pengList[i].PokerList[j], isHu, isBao, isMa, isUniversal, isPeng, isDim);
                    }
                    currentX += 10f;
                }
            }

#if IS_GUGENG
            List <Poker> jin = new List <Poker>();
            for (int i = 0; i < desktopPoker.Count; ++i)
            {
                if (MahJongHelper.CheckUniversal(desktopPoker[i], universal))
                {
                    jin.Add(desktopPoker[i]);
                }
            }

            for (int i = 0; i < jin.Count; ++i)
            {
                GameObject go      = Instantiate(prefab);
                UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                bool isDim         = false;
                bool isHu          = false;
                bool isBao         = false;
                bool isMa          = false;
                bool isUniversal   = true;
                bool isPeng        = true;
                item.SetSize(handCellSize);
                go.SetParent(m_PengPokerContainer);
                go.transform.localPosition = new Vector3(currentX, 0f, 0f);
                currentX += handCellSize.x;
                item.SetUI(jin[i], isHu, isBao, isMa, isUniversal, isPeng, isDim);
            }
#endif

#if IS_HONGHU || IS_TAILAI//鸿鹄 赢家在抓马位置上显示宝牌
            if (isWiner && luckPoker != null && luckPoker.color != 0)
            {
                GameObject go      = Instantiate(prefab);
                UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                item.SetUI(luckPoker, false, true, false, false, false, false);
                go.SetParent(m_ProbContainer);
            }
#endif
            if (isWiner && prob != null)
            {
                if (prob.Count == 1)
                {
                    GameObject go      = Instantiate(prefab);
                    UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                    item.SetUI(prob[0], false, false, true, false, false, false);
                    go.SetParent(m_ProbContainer);
                }
                else if (prob.Count > 1)
                {
                    for (int i = 0; i < prob.Count; ++i)
                    {
                        Poker p = prob[i];
#if IS_LAOGUI
                        if ((hasFeng && (((seatPos == bankerPos && ((p.color < 4 && (p.size == 1 || p.size == 5 || p.size == 9)) || (p.color == 4 && p.size == 1) || (p.color == 5 && p.size == 1)))) ||
                                         ((seatPos - bankerPos == 1 || seatPos - bankerPos == -3) && ((p.color < 4 && (p.size == 2 || p.size == 6)) || (p.color == 4 && p.size == 2) || (p.color == 5 && p.size == 2))) ||
                                         ((seatPos - bankerPos == 2 || seatPos - bankerPos == -2) && ((p.color < 4 && (p.size == 3 || p.size == 7)) || (p.color == 4 && p.size == 3) || (p.color == 5 && p.size == 3))) ||
                                         ((seatPos - bankerPos == 3 || seatPos - bankerPos == -1) && ((p.color < 4 && (p.size == 4 || p.size == 8)) || (p.color == 4 && p.size == 4))))) ||
                            (!hasFeng && (p.color < 4 && ((p.size == 1 || p.size == 5 || p.size == 9)) || (p.color == 5 && p.size == 1))))
#else
                        if ((p.color < 4 && (p.size == 1 || p.size == 5 || p.size == 9)) || (p.color == 5 && p.size == 1))
#endif
                        {
                            GameObject go      = Instantiate(prefab);
                            UIItemMahjong item = go.GetComponent <UIItemMahjong>();
                            item.SetUI(p, false, false, true, false, false, false);
                            go.SetParent(m_ProbContainer);
                        }
                    }
                }
            }
        });


        if (m_ImgLaZi != null)
        {
            m_ImgLaZi.gameObject.SetActive(isLaZi);
        }

        if (m_ArrDirection != null && m_ArrDirection.Length > 0)
        {
            for (int i = 0; i < m_ArrDirection.Length; ++i)
            {
                m_ArrDirection[i].gameObject.SetActive(i + 1 == direction);
            }
        }
    }