/// <summary>
        /// 设置宝牌
        /// </summary>
        /// <param name="card"></param>
        public void SetTreasureCard(MahjongCardName cardName)
        {
            // 手牌中的宝牌
            for (int i = 0; i < card_onhand.Count; i++)
            {
                if (card_onhand[i].name == cardName)
                {
                    card_onhand[i].AddTreasure();
                }
            }

            // 副露里的宝牌
            for (int i = 0; i < card_furu.Count; i++)
            {
                for (int j = 0; j < card_furu[i].cards.Count; j++)
                {
                    if (card_furu[i].cards[j].name == cardName)
                    {
                        card_furu[i].cards[j].AddTreasure();
                    }
                }
            }
        }
 public static MahjongCard GetCard(MahjongCardName cardName) => (from c in CardInfo where c.name == cardName select c).First();
Ejemplo n.º 3
0
        /// <summary>
        /// 能够鸣牌计算
        /// </summary>
        private List <FuruAble> isCanFuru()
        {
            // 获得刚刚打牌的玩家的牌河和打出的牌
            List <MahjongCard> played_cards = GetPlayerCardPlayed(Playing);
            MahjongCard        last_played  = played_cards.Last(); // 最后一张

            // 比对其他三家的手牌
            List <FuruAble> furuAbles = new List <FuruAble>();

            // 记录是否有玩家可以碰或者杠以减少不必要的计算
            bool hasPongKong = false;

            // 遍历所有其它玩家
            for (int player = 0; player < 4; player++)
            {
                if (player == Playing)
                {
                    continue; // 跳过自己
                }

                // 获得手牌
                List <MahjongCard> player_hand = GetPlayerCardOnHand(player);

                // 记录可副露牌组
                FuruAble furuAble = new FuruAble(player);

                // 如果已经有别的玩家可以碰杠,则不可能再有玩家可以碰杠
                if (hasPongKong == false)
                {
                    // 优先找出杠子和刻子
                    IEnumerable <MahjongCard> PongKong = from card in player_hand where card == last_played select card;
                    if (PongKong.Count() >= 2)
                    {
                        hasPongKong = true;

                        // 可以碰
                        furuAble.FuruableList.Add(new MahjongCardFuru()
                        {
                            cards  = Enumerable.Repeat(last_played, 2).ToList(),
                            target = Playing,
                            type   = FuruType.Pong,
                        });

                        if (PongKong.Count() == 3)
                        {
                            // 可以杠
                            furuAble.FuruableList.Add(new MahjongCardFuru()
                            {
                                cards  = Enumerable.Repeat(last_played, 3).ToList(),
                                target = Playing,
                                type   = FuruType.Kong,
                            });
                            hasPongKong = true;
                        }
                    }
                }


                if (last_played.type == MahjongCardType.Char)
                {
                    // 年级和小组顺子(吃)
                    // 年级顺子
                    MahjongCardName      name  = last_played.name;
                    MahjongCardGradeType grade = last_played.grade;
                    MahjongCardGroupType group = last_played.group;
                    IEnumerable <IGrouping <MahjongCardName, MahjongCard> > grade_chi = from card in player_hand
                                                                                        where (card.grade == grade) && (card.name != name) &&
                                                                                        (card.type == MahjongCardType.Char) && (card.@group == @group)
                                                                                        group card by card.name into g
                                                                                        select g;
                    if (grade_chi.Count() == 2)
                    {
                        // 至少要有两种同年级的牌才可以吃
                        // 获得要吃的牌
                        List <MahjongCard> chi = new List <MahjongCard>();
                        foreach (IGrouping <MahjongCardName, MahjongCard> cards in grade_chi)
                        {
                            chi.Add(cards.First());
                        }

                        // 加入可副露列表
                        furuAble.FuruableList.Add(new MahjongCardFuru()
                        {
                            cards  = chi,
                            target = Playing,
                            type   = FuruType.ChiGrade,
                        });
                    }

                    // 小组顺子
                    MahjongCardSquadType squad = last_played.squad;
                    IEnumerable <IGrouping <MahjongCardName, MahjongCard> > squad_chi = from card in player_hand
                                                                                        where (card.squad == squad) && (card.name != name) && (card.type == MahjongCardType.Char)
                                                                                        group card by card.name into g
                                                                                        select g;
                    if (squad_chi.Count() == 2)
                    {
                        // 至少要有两种同小组的牌才可以吃
                        // 获得要吃的牌
                        List <MahjongCard> chi = new List <MahjongCard>();
                        foreach (IGrouping <MahjongCardName, MahjongCard> cards in squad_chi)
                        {
                            chi.Add(cards.First());
                        }

                        // 加入可副露列表
                        furuAble.FuruableList.Add(new MahjongCardFuru()
                        {
                            cards  = chi,
                            target = Playing,
                            type   = FuruType.ChiSquad,
                        });
                    }
                }
                furuAbles.Add(furuAble);
            }

            return(furuAbles);
        }