Пример #1
0
        public void BlockingPon()
        {
            var parser = new ShorthandParser("1223m112223z123M");
            var c      = new HandCalculator(parser);
            var m2     = TileType.FromSuitAndIndex(Suit.Manzu, 1);

            c.Pon(m2);
            var shaa = TileType.FromSuitAndIndex(Suit.Jihai, 2);

            c.Discard(shaa);

            var actual = c.Shanten;

            Assert.Equal(1, actual);
        }
Пример #2
0
        public void BlockingShouminkan()
        {
            var parser = new ShorthandParser("1223m112223337z");
            var c      = new HandCalculator(parser);
            var m2     = TileType.FromSuitAndIndex(Suit.Manzu, 1);
            var z7     = TileType.FromSuitAndIndex(Suit.Jihai, 6);

            c.Pon(m2);
            c.Discard(z7);
            c.Draw(m2);
            c.Shouminkan(m2);

            var actual = c.Shanten;

            Assert.Equal(1, actual);
        }
Пример #3
0
        public static bool IsTenpai(IHandAnalysis hand, IReadOnlyList <Tile> concealedTiles, int meldCount)
        {
            if (hand.Shanten <= 0)
            {
                return(true);
            }

            if (meldCount == 0)
            {
                return(false);
            }

            var usedTileTypeIds = new bool[34];
            var initialTiles    = new Stack <TileType>();

            foreach (var tile in concealedTiles)
            {
                usedTileTypeIds[tile.TileType.TileTypeId] = true;
                initialTiles.Push(tile.TileType);
            }

            TileType?draw = null;

            if (initialTiles.Count % 3 == 2)
            {
                draw = initialTiles.Pop();
            }

            var remainingMelds = meldCount;
            var toPon          = new List <TileType>();

            for (var i = 27; i < 34 && remainingMelds > 0; i++)
            {
                if (usedTileTypeIds[i])
                {
                    continue;
                }

                remainingMelds -= 1;
                var tileType = TileType.FromTileTypeId(i);
                initialTiles.Push(tileType);
                initialTiles.Push(tileType);
                initialTiles.Push(tileType);
                toPon.Add(tileType);
            }

            if (remainingMelds > 0)
            {
                return(false);
            }

            var tempHand = new HandCalculator();

            tempHand.Init(initialTiles);
            foreach (var tileType in toPon)
            {
                tempHand.Pon(tileType);
                tempHand.Discard(tileType);
            }

            if (draw != null)
            {
                tempHand.Draw(draw);
            }

            return(tempHand.Shanten <= 0);
        }