Example #1
0
        public void CalculatePossibleWaitingTiles()
        {
            if (LocalPlayerHandTiles == null)
            {
                return;
            }
            if (!GameSetting.AllowHint)
            {
                PossibleWaitingTiles = null;
                return;
            }

            var handTiles = new List <Tile>(LocalPlayerHandTiles);
            var lastDraw  = GetLastDraw(0);

            PossibleWaitingTiles = MahjongLogic.DiscardForReady(LocalPlayerHandTiles, lastDraw);
            if (PossibleWaitingTiles == null)
            {
                Debug.Log("WaitingTiles: null");
            }
            else
            {
                Debug.Log(
                    $"WaitingTiles: {string.Join(";", PossibleWaitingTiles.Select(x => x.Key + ": " + string.Join(",", x.Value)))}");
            }
            NotifyObservers();
        }
Example #2
0
    public static void Test3Dragons()
    {
        var handTiles = new List <Tile> {
            new Tile(Suit.S, 4), new Tile(Suit.S, 5), new Tile(Suit.S, 6),
            new Tile(Suit.Z, 2), new Tile(Suit.Z, 2),
            new Tile(Suit.Z, 5), new Tile(Suit.Z, 5)
        };
        var openMelds = new List <Meld> {
            new Meld(false, new Tile(Suit.Z, 6), new Tile(Suit.Z, 6), new Tile(Suit.Z, 6), new Tile(Suit.Z, 6)),
            new Meld(true, new Tile(Suit.Z, 7), new Tile(Suit.Z, 7), new Tile(Suit.Z, 7))
        };
        var settings    = new GameSetting();
        var handStatus  = HandStatus.Tsumo;
        var roundStatus = new RoundStatus
        {
            PlayerIndex    = 0,
            OyaPlayerIndex = 1,
            FieldCount     = 0,
            TotalPlayer    = 2
        };
        var pointInfo = MahjongLogic.GetPointInfo(handTiles.ToArray(), openMelds.ToArray(), new Tile(Suit.Z, 2),
                                                  handStatus, roundStatus, settings, false);

        Debug.Log($"Point: {pointInfo}");
    }
Example #3
0
        private void TestPongs(IList <Tile> handTiles, Tile discardTile, MeldSide side,
                               IList <OutTurnOperation> operations)
        {
            if (!gameSettings.AllowPongs)
            {
                return;
            }
            var pongs = MahjongLogic.GetPongs(handTiles, discardTile, side);

            if (pongs.Any())
            {
                foreach (var pong in pongs)
                {
                    operations.Add(new OutTurnOperation
                    {
                        Type           = OutTurnOperationType.Pong,
                        Tile           = discardTile,
                        Meld           = pong,
                        ForbiddenTiles = gameSettings.AllowDiscardSameAfterOpen
                                                        ? null
                                                        : pong.GetForbiddenTiles(discardTile)
                    });
                }
            }
        }
Example #4
0
        private void TestRong(int playerIndex, Tile discardTile, IList <OutTurnOperation> operations)
        {
            var baseHandStatus = HandStatus.Nothing;

            // test haidi
            if (MahjongSet.Data.TilesDrawn == gameSettings.MountainReservedTiles)
            {
                baseHandStatus |= HandStatus.Haidi;
            }
            // test lingshang -- not gonna happen
            var allTiles  = MahjongSet.AllTiles;
            var doraTiles = MahjongSet.DoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var uraDoraTiles = MahjongSet.UraDoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var beiDora = CurrentRoundStatus.GetBeiDora(playerIndex);
            var point   = ServerMahjongLogic.GetPointInfo(
                playerIndex, CurrentRoundStatus, discardTile, baseHandStatus,
                doraTiles, uraDoraTiles, beiDora, gameSettings);

            // test if enough
            if (gameSettings.CheckConstraint(point))
            {
                operations.Add(new OutTurnOperation
                {
                    Type     = OutTurnOperationType.Rong,
                    Tile     = discardTile,
                    HandData = CurrentRoundStatus.HandData(playerIndex)
                });
            }
        }
Example #5
0
        private void TestTsumo(int playerIndex, Tile tile, IList <InTurnOperation> operations)
        {
            var baseHandStatus = HandStatus.Tsumo;

            // test haidi
            if (MahjongSet.TilesRemain == gameSettings.MountainReservedTiles)
            {
                baseHandStatus |= HandStatus.Haidi;
            }
            // test lingshang
            if (IsLingShang)
            {
                baseHandStatus |= HandStatus.Lingshang;
            }
            var allTiles  = MahjongSet.AllTiles;
            var doraTiles = MahjongSet.DoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var uraDoraTiles = MahjongSet.UraDoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var beiDora = CurrentRoundStatus.GetBeiDora(playerIndex);

            tsumoPointInfo = ServerMahjongLogic.GetPointInfo(
                playerIndex, CurrentRoundStatus, tile, baseHandStatus,
                doraTiles, uraDoraTiles, beiDora, gameSettings);
            // test if enough
            if (gameSettings.CheckConstraint(tsumoPointInfo))
            {
                operations.Add(new InTurnOperation
                {
                    Type = InTurnOperationType.Tsumo,
                    Tile = justDraw
                });
            }
        }
Example #6
0
        private void TestChows(IList <Tile> handTiles, Tile discardTile, MeldSide side,
                               IList <OutTurnOperation> operations)
        {
            if (!gameSettings.AllowChows)
            {
                return;
            }
            if (side != MeldSide.Left)
            {
                return;
            }
            var chows = MahjongLogic.GetChows(handTiles, discardTile, side);

            if (chows.Any())
            {
                foreach (var chow in chows)
                {
                    operations.Add(new OutTurnOperation
                    {
                        Type           = OutTurnOperationType.Chow,
                        Tile           = discardTile,
                        Meld           = chow,
                        ForbiddenTiles = gameSettings.AllowDiscardSameAfterOpen
                                                        ? null
                                                        : chow.GetForbiddenTiles(discardTile)
                    });
                }
            }
        }
Example #7
0
        private void TestRichi(int playerIndex, Tile[] handTiles, Meld[] openMelds, IList <InTurnOperation> operations)
        {
            var alreadyRichied = CurrentRoundStatus.RichiStatus(playerIndex);

            if (alreadyRichied)
            {
                return;
            }
            var availability = gameSettings.AllowRichiWhenPointsLow || CurrentRoundStatus.GetPoints(playerIndex) >= gameSettings.RichiMortgagePoints;

            if (!availability)
            {
                return;
            }
            IList <Tile> availableTiles;

            if (MahjongLogic.TestRichi(handTiles, openMelds, justDraw, gameSettings.AllowRichiWhenNotReady, out availableTiles))
            {
                operations.Add(new InTurnOperation
                {
                    Type = InTurnOperationType.Richi,
                    RichiAvailableTiles = availableTiles.ToArray()
                });
            }
        }
Example #8
0
        private PointInfo GetRongInfo(int playerIndex, Tile discard)
        {
            var baseHandStatus = HandStatus.Nothing;

            // test haidi
            if (MahjongSet.TilesRemain == gameSettings.MountainReservedTiles)
            {
                baseHandStatus |= HandStatus.Haidi;
            }
            // test rob kong
            if (IsRobKong)
            {
                baseHandStatus |= HandStatus.RobKong;
            }
            // test lingshang -- not gonna happen
            var allTiles  = MahjongSet.AllTiles;
            var doraTiles = MahjongSet.DoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var uraDoraTiles = MahjongSet.UraDoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var beiDora = CurrentRoundStatus.GetBeiDora(playerIndex);
            var point   = ServerMahjongLogic.GetPointInfo(
                playerIndex, CurrentRoundStatus, discard, baseHandStatus,
                doraTiles, uraDoraTiles, beiDora, gameSettings);

            Debug.Log($"TurnEndState: pointInfo: {point}");
            return(point);
        }
Example #9
0
        public void StartNewGame()
        {
            mahjongLogic = new MahjongLogic();
            mahjongLogic.StartGamingThread();
            mahjongLogic.NewGame_Handle(25000, 4);
            mahjongLogic.NextScene();

            // Set callback
            mahjongLogic.PlayerActionResponseCallback += PlayerActionResponseCallback;
            mahjongLogic.PlayerActionAcceptedCallback += PlayerActionAcceptedCallback;

            // Initialize the players
            grdsHandcard     = new Grid[] { grdHandcardSelf, grdHandcardDownwind, grdHandcardOppositewind, grdHandcardUpwind };
            grdsRivercard    = new Grid[] { grdRiverSelf, grdRiverDownwind, grdRiverOppositewind, grdRiverUpwind };
            lblsPlayerPoint  = new Label[] { lblPointSelf, lblPointDownwind, lblPointOppsitewind, lblPointUpwind };
            lblsPlayerWind   = new Label[] { lblWindSelf, lblWindDownwind, lblWindOppositewind, lblWindUpwind };
            grdsPlayerAction = new Grid[] { grdActionSelf, grdActionDownwind, grdActionOppositewind, grdActionUpwind };
            grdsFuru         = new Grid[] { grdFuruEast, grdFuruSouth, grdFuruWest, grdFuruNorth };

            // Clear
            foreach (Grid panel in grdsPlayerAction)
            {
                panel.Children.Clear();
            }
        }
Example #10
0
        private void TestKongs(int playerIndex, Tile[] handTiles, IList <InTurnOperation> operations)
        {
            if (CurrentRoundStatus.KongClaimed == MahjongConstants.MaxKongs)
            {
                return;                 // no more kong can be claimed after 4 kongs claimed
            }
            var alreadyRichied = CurrentRoundStatus.RichiStatus(playerIndex);

            if (alreadyRichied)
            {
                // test kongs in richied player hand
                var richiKongs = MahjongLogic.GetRichiKongs(handTiles, justDraw);
                if (richiKongs.Any())
                {
                    foreach (var kong in richiKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }
            }
            else
            {
                // 1. test self kongs, aka four same tiles in hand and lastdraw
                var selfKongs = MahjongLogic.GetSelfKongs(handTiles, justDraw);
                if (selfKongs.Any())
                {
                    foreach (var kong in selfKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }

                // 2. test add kongs, aka whether a single tile in hand and lastdraw is identical to a pong in open melds
                var addKongs = MahjongLogic.GetAddKongs(
                    CurrentRoundStatus.HandTiles(playerIndex), CurrentRoundStatus.OpenMelds(playerIndex), justDraw);
                if (addKongs.Any())
                {
                    foreach (var kong in addKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }
            }
        }
Example #11
0
        public static bool TestRichi(string tileString, string lastDraw)
        {
            var          tiles = ParseTiles(tileString);
            var          tile  = ParseTiles(lastDraw)[0];
            IList <Tile> availables;
            var          result = MahjongLogic.TestRichi(tiles, new List <Meld>(), tile, false, out availables);

            Debug.Log($"Candidates: {string.Join(",", availables)}");
            return(result);
        }
Example #12
0
        public override void OnClientStateEnter()
        {
            CurrentRoundStatus.UpdatePoints(Points);
            Debug.Log($"Current points: {string.Join(",", CurrentRoundStatus.Points)}");
            var pointAndPlace = MahjongLogic.SortPointsAndPlaces(Points);
            var places        = pointAndPlace.Select(v => v.Value).ToArray();

            controller.PointTransferManager.SetTransfer(CurrentRoundStatus, places, PointTransfers,
                                                        () => { ClientBehaviour.Instance.NextRound(); });
        }
Example #13
0
 public void UpdateRichiZhenting(int playerIndex, Tile discardTile)
 {
     if (!RichiStatus(playerIndex) || richiZhenting[playerIndex])
     {
         return;
     }
     if (MahjongLogic.HasWin(handTiles[playerIndex], null, discardTile))
     {
         richiZhenting[playerIndex] = true;
     }
 }
Example #14
0
    public static void TestCombinations()
    {
        var list = new List <int> {
            1, 2, 3, 4, 5, 6, 7, 8
        };
        var result = MahjongLogic.Combination(list, 1);

        Debug.Log($"Total results: {result.Count}");
        for (int i = 0; i < result.Count; i++)
        {
            Debug.Log($"{i}: {string.Join(",", result[i])}");
        }
    }
Example #15
0
    public static void TestDiscard()
    {
        var handTiles = new List <Tile> {
            new Tile(Suit.M, 1), new Tile(Suit.M, 2), new Tile(Suit.M, 3), new Tile(Suit.M, 4), new Tile(Suit.M, 4),
            new Tile(Suit.M, 5), new Tile(Suit.M, 5, true)
        };
        var dict = MahjongLogic.DiscardForReady(handTiles, new Tile(Suit.Z, 1));

        foreach (var item in dict)
        {
            Debug.Log($"{item.Key}, {string.Join(",", item.Value)}");
        }
    }
Example #16
0
        /// <summary>
        /// Note: lingshang and haidi should be obtained in baseHandStatus
        /// </summary>
        /// <param name="playerIndex"></param>
        /// <param name="CurrentRoundStatus"></param>
        /// <param name="winningTile"></param>
        /// <param name="baseHandStatus"></param>
        /// <returns></returns>
        public static PointInfo GetPointInfo(int playerIndex, ServerRoundStatus CurrentRoundStatus, Tile winningTile,
                                             HandStatus baseHandStatus, Tile[] doraTiles, Tile[] uraDoraTiles, int beiDora, GameSetting yakuSettings)
        {
            var zhenting = CurrentRoundStatus.IsZhenting(playerIndex);

            if (zhenting && !baseHandStatus.HasFlag(HandStatus.Tsumo))
            {
                return(new PointInfo());
            }
            var handData   = CurrentRoundStatus.HandData(playerIndex);
            var handStatus = baseHandStatus;

            if (MahjongLogic.TestMenqing(handData.Melds))
            {
                handStatus |= HandStatus.Menqing;
            }
            // test richi
            if (CurrentRoundStatus.RichiStatus(playerIndex))
            {
                handStatus |= HandStatus.Richi;
                // test one-shot
                if (yakuSettings.HasOneShot && CurrentRoundStatus.OneShotStatus(playerIndex))
                {
                    handStatus |= HandStatus.OneShot;
                }
                // test WRichi
                if (CurrentRoundStatus.FirstTurn)
                {
                    handStatus |= HandStatus.WRichi;
                }
            }

            // test first turn
            if (CurrentRoundStatus.FirstTurn)
            {
                handStatus |= HandStatus.FirstTurn;
            }
            var roundStatus = new RoundStatus
            {
                PlayerIndex       = playerIndex,
                OyaPlayerIndex    = CurrentRoundStatus.OyaPlayerIndex,
                CurrentExtraRound = CurrentRoundStatus.Extra,
                RichiSticks       = CurrentRoundStatus.RichiSticks,
                FieldCount        = CurrentRoundStatus.Field,
                TotalPlayer       = CurrentRoundStatus.TotalPlayers
            };
            var isQTJ = CurrentRoundStatus.GameSettings.GameMode == GameMode.QTJ;

            return(MahjongLogic.GetPointInfo(handData.HandTiles, handData.Melds, winningTile,
                                             handStatus, roundStatus, yakuSettings, isQTJ, doraTiles, uraDoraTiles, beiDora));
        }
Example #17
0
        public override string Verify(string data, string fallback)
        {
            Debug.Log($"Verifying {data}");
            int value;

            if (int.TryParse(data, out value))
            {
                if (value > 0)
                {
                    return(MahjongLogic.ToNextUnit(value, 100).ToString());
                }
            }
            return(fallback);
        }
Example #18
0
 public void CalculateWaitingTiles()
 {
     if (LocalPlayerHandTiles == null)
     {
         return;
     }
     if (!GameSetting.AllowHint)
     {
         WaitingTiles = null;
         return;
     }
     WaitingTiles = MahjongLogic.WinningTiles(LocalPlayerHandTiles, null);
     NotifyObservers();
 }
Example #19
0
        public override void OnServerStateEnter()
        {
            var pointsAndPlaces = MahjongLogic.SortPointsAndPlaces(CurrentRoundStatus.Points);
            var names           = CurrentRoundStatus.PlayerNames.ToArray();
            var points          = CurrentRoundStatus.Points.ToArray();
            var places          = pointsAndPlaces.Select(v => v.Value).ToArray();
            var info            = new EventMessages.GameEndInfo
            {
                PlayerNames = names,
                Points      = points,
                Places      = places
            };

            ClientBehaviour.Instance.photonView.RPC("RpcGameEnd", RpcTarget.AllBufferedViaServer, info);
        }
Example #20
0
        private PointInfo GetRongInfo(int playerIndex, Tile tile)
        {
            var baseHandStatus = HandStatus.RobKong;
            var allTiles       = MahjongSet.AllTiles;
            var doraTiles      = MahjongSet.DoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var uraDoraTiles = MahjongSet.UraDoraIndicators.Select(
                indicator => MahjongLogic.GetDoraTile(indicator, allTiles)).ToArray();
            var beiDora = CurrentRoundStatus.GetBeiDora(playerIndex);
            var point   = ServerMahjongLogic.GetPointInfo(
                playerIndex, CurrentRoundStatus, tile, baseHandStatus,
                doraTiles, uraDoraTiles, beiDora, gameSettings);

            return(point);
        }
Example #21
0
 public void UpdateTempZhenting(int discardPlayerIndex, Tile discardTile)
 {
     // test temp zhenting
     for (int playerIndex = 0; playerIndex < GameSettings.MaxPlayer; playerIndex++)
     {
         if (playerIndex == discardPlayerIndex)
         {
             continue;
         }
         if (MahjongLogic.HasWin(handTiles[playerIndex], null, discardTile))
         {
             tempZhenting[playerIndex] = true;
         }
     }
 }
Example #22
0
    public static void TestChows()
    {
        var handTiles = new List <Tile> {
            new Tile(Suit.M, 1), new Tile(Suit.M, 2), new Tile(Suit.M, 3), new Tile(Suit.M, 4), new Tile(Suit.M, 4),
            new Tile(Suit.M, 5), new Tile(Suit.M, 5), new Tile(Suit.M, 5, true), new Tile(Suit.M, 6)
        };
        var result = MahjongLogic.GetChows(handTiles, new Tile(Suit.M, 4), MeldSide.Left);

        Debug.Log($"Melds: {string.Join(",", result)}");
        handTiles = new List <Tile> {
            new Tile(Suit.M, 1), new Tile(Suit.M, 2), new Tile(Suit.M, 3), new Tile(Suit.M, 4), new Tile(Suit.M, 4),
            new Tile(Suit.M, 5), new Tile(Suit.M, 5), new Tile(Suit.M, 5), new Tile(Suit.M, 6)
        };
        result = MahjongLogic.GetChows(handTiles, new Tile(Suit.M, 5, true), MeldSide.Opposite);
        Debug.Log($"Melds: {string.Join(",", result)}");
    }
        public void TestYaku()
        {
            LoveLive_MahjongClass.InitializeMahjongClass();

            // 设置一些要和的牌
            List <MahjongCard>     Hand_Cards;
            List <MahjongCardFuru> Furu_Cards;

            Hand_Cards = new List <MahjongCard>()
            {
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Rin - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Rin - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Maki - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Maki - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Nico - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Nico - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Nozomi - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Nozomi - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Hanayo - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Hanayo - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Eli - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Eli - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Kotori - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Kotori - 1],
            };

            Furu_Cards = new List <MahjongCardFuru>()
            {
            };

            MahjongLogic logic = new MahjongLogic();

            bool Hu = logic.utIsHu(Hand_Cards, Furu_Cards, out List <HuCard> huCards);

            Assert.IsTrue(Hu);

            List <MahjongYaku> yakus = logic.utCalcYaku(huCards);

            foreach (MahjongYaku yaku in yakus)
            {
                Trace.WriteLine(yaku);
            }

            Trace.WriteLine($"点数:{logic.utCalcHuPoints(huCards)}");
        }
Example #24
0
 private void Test9Orphans(Tile[] handTiles, IList <InTurnOperation> operations)
 {
     if (!gameSettings.Allow9OrphanDraw)
     {
         return;
     }
     if (!CurrentRoundStatus.FirstTurn)
     {
         return;
     }
     if (MahjongLogic.Test9KindsOfOrphans(handTiles, justDraw))
     {
         operations.Add(new InTurnOperation
         {
             Type = InTurnOperationType.RoundDraw
         });
     }
 }
Example #25
0
    public static void TestRichiKongs()
    {
        var handTiles = new List <Tile> {
            new Tile(Suit.M, 3), new Tile(Suit.M, 3), new Tile(Suit.M, 4), new Tile(Suit.M, 4),
            new Tile(Suit.M, 5), new Tile(Suit.M, 5, true), new Tile(Suit.M, 5)
        };
        var kongs = MahjongLogic.GetRichiKongs(handTiles, new Tile(Suit.M, 5));

        Debug.Log($"Kongs: {string.Join(",", kongs)}");
        handTiles = new List <Tile> {
            new Tile(Suit.M, 3), new Tile(Suit.M, 3), new Tile(Suit.M, 6), new Tile(Suit.M, 6),
            new Tile(Suit.M, 5), new Tile(Suit.M, 5, true), new Tile(Suit.M, 5)
        };
        kongs = MahjongLogic.GetRichiKongs(handTiles, new Tile(Suit.M, 5));
        Debug.Log($"Kongs: {string.Join(",", kongs)}");
        kongs = MahjongLogic.GetRichiKongs(handTiles, new Tile(Suit.M, 3));
        Debug.Log($"Kongs: {string.Join(",", kongs)}");
    }
Example #26
0
        public static PointInfo GetPointInfo(string handString, string winningString, bool richi, bool tsumo, bool isQTJ)
        {
            var handStatus = HandStatus.Menqing;

            if (richi)
            {
                handStatus |= HandStatus.Richi;
            }
            if (tsumo)
            {
                handStatus |= HandStatus.Tsumo;
            }
            var roundStatus  = new RoundStatus();
            var tiles        = ParseTiles(handString);
            var winningTiles = ParseTiles(winningString);
            var gameSettings = new GameSetting();
            var point        = MahjongLogic.GetPointInfo(tiles.ToArray(), new Meld[0], winningTiles[0],
                                                         handStatus, roundStatus, gameSettings, isQTJ);

            return(point);
        }
Example #27
0
        private void HandleFourRichis()
        {
            // Get waiting tiles for each player
            var waitingDataArray = new WaitingData[players.Count];

            for (int playerIndex = 0; playerIndex < players.Count; playerIndex++)
            {
                var hand = CurrentRoundStatus.HandTiles(playerIndex);
                var open = CurrentRoundStatus.Melds(playerIndex);
                waitingDataArray[playerIndex] = new WaitingData
                {
                    HandTiles    = hand,
                    WaitingTiles = MahjongLogic.WinningTiles(hand, open).ToArray()
                };
            }

            // Get messages
            for (int i = 0; i < players.Count; i++)
            {
                infos[i] = new EventMessages.RoundDrawInfo
                {
                    RoundDrawType = RoundDrawType,
                    WaitingData   = waitingDataArray
                };
            }

            next  = waitingDataArray[CurrentRoundStatus.OyaPlayerIndex].WaitingTiles.Length > 0;
            extra = true;
            // Get point transfers
            for (int playerIndex = 0; playerIndex < players.Count; playerIndex++)
            {
                var waitingTiles = waitingDataArray[playerIndex].WaitingTiles;
                if (waitingTiles.Length > 0)
                {
                    continue;
                }
                GetTransfersForFalseRichi(playerIndex, transfers);
            }
        }
        public void TestLisiten()
        {
            LoveLive_MahjongClass.InitializeMahjongClass();

            // 设置一些要和的牌
            List <MahjongCard>     Hand_Cards;
            List <MahjongCardFuru> Furu_Cards;

            Hand_Cards = new List <MahjongCard>()
            {
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Hanayo - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Rin - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Maki - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Hanamaru - 1 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Yoshiko - 1 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Ruby - 1 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Shizuku - 2 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Rina - 2 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Kasumi - 2 - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Nico - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Eli - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Maki - 1],
                LoveLive_MahjongClass.CardInfo[(int)MahjongCardName.Aqours - 5 - 1],
            };

            Furu_Cards = new List <MahjongCardFuru>()
            {
            };

            MahjongLogic logic = new MahjongLogic();

            List <MahjongCard> waiting = logic.utIsWaiting(Hand_Cards, Furu_Cards);

            Trace.WriteLine($"You are waiting for {waiting.Count} cards.");
            foreach (MahjongCard card in waiting)
            {
                Trace.WriteLine(card);
            }
        }
Example #29
0
    public static void TestDora()
    {
        var allTiles  = MahjongConstants.TwoPlayerTiles;
        var indicator = new Tile(Suit.Z, 2);

        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.Z, 7);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.Z, 4);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.S, 7);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.S, 9);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.S, 1);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.M, 1);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.M, 4);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
        indicator = new Tile(Suit.M, 9);
        Debug.Log($"When indicator is {indicator}, dora is {MahjongLogic.GetDoraTile(indicator, allTiles)}");
    }
Example #30
0
        private void HandleRoundDraw()
        {
            // Get waiting tiles for each player
            var waitingDataArray = new WaitingData[players.Count];

            for (int playerIndex = 0; playerIndex < players.Count; playerIndex++)
            {
                var hand = CurrentRoundStatus.HandTiles(playerIndex);
                var open = CurrentRoundStatus.Melds(playerIndex);
                waitingDataArray[playerIndex] = new WaitingData
                {
                    HandTiles    = hand,
                    WaitingTiles = MahjongLogic.WinningTiles(hand, open).ToArray()
                };
            }

            // Get messages
            for (int i = 0; i < players.Count; i++)
            {
                infos[i] = new EventMessages.RoundDrawInfo
                {
                    RoundDrawType = RoundDrawType,
                    WaitingData   = waitingDataArray
                };
            }

            // Get point transfers
            // get player indices of those are ready and not
            var readyIndices    = new List <int>();
            var notReadyIndices = new List <int>();

            for (int playerIndex = 0; playerIndex < players.Count; playerIndex++)
            {
                if (waitingDataArray[playerIndex].WaitingTiles.Length > 0)
                {
                    readyIndices.Add(playerIndex);
                }
                else
                {
                    notReadyIndices.Add(playerIndex);
                }
            }

            next  = notReadyIndices.Contains(CurrentRoundStatus.OyaPlayerIndex);
            extra = true;
            // no one is ready or every one is ready
            if (readyIndices.Count == 0 || notReadyIndices.Count == 0)
            {
                return;
            }
            // get transfers according to total count of players
            switch (players.Count)
            {
            case 2:
                GetTransfersFor2(readyIndices, notReadyIndices, transfers);
                break;

            case 3:
                GetTransfersFor3(readyIndices, notReadyIndices, transfers);
                break;

            case 4:
                GetTransfersFor4(readyIndices, notReadyIndices, transfers);
                break;

            default:
                Debug.LogError("This should not happen");
                break;
            }

            // test for false richi
            foreach (var playerIndex in notReadyIndices)
            {
                if (CurrentRoundStatus.RichiStatus(playerIndex))
                {
                    GetTransfersForFalseRichi(playerIndex, transfers);
                }
            }
        }