예제 #1
0
 public override bool TestNormalRon(SortedTilesEnumerator tiles)
 {
     if (mahjongTable.TryGetValue(BuildKey(tiles), out var info))
     {
         return(info.Syanten == -1);
     }
     else
     {
         throw new NotImplementedException("mahjong.table中不存在的项。可能是牌数除以3余数不等于2,或者BuildKey方法存在错误。");
     }
 }
예제 #2
0
 public override void NormalSyanten(SortedTilesEnumerator tiles, ref int result)
 {
     if (mahjongTable.TryGetValue(BuildKey(tiles), out var info))
     {
         if (info.Syanten < result)
         {
             result = info.Syanten;
         }
     }
     else
     {
         throw new NotImplementedException("mahjong.table中不存在的项。可能是牌数除以3余数不等于2,或者BuildKey方法存在错误。");
     }
 }
예제 #3
0
        public virtual void NormalSyanten(SortedTilesEnumerator tiles, ref int result)
        {
            if (tiles.Count % 3 == 0)
            {
                throw new ArgumentException("牌数量不能是3的倍数。", nameof(tiles));
            }

            var args = new SyantenArgs {
                Result   = result,
                MinValue = 1 - tiles.Count % 3
            };

            NormalSyantenCutPair(tiles.Tiles, tiles.Count, args);
            result = args.Result;
        }
예제 #4
0
        private static ulong BuildKey(SortedTilesEnumerator tiles)
        {
            ulong result    = 0xF;
            int   prevIndex = -3;

            for (int i = 0; i < 34; i++)
            {
                if (i % 9 == 0 || i >= 27)
                {
                    prevIndex = -3;
                }
                if (tiles.Tiles[i] == 0)
                {
                    continue;
                }
                int diffIndex = i - prevIndex - 1;
                result    = (result << 4) | (diffIndex >= 2 ? 8U : (uint)diffIndex << 2);
                result   |= (byte)(tiles.Tiles[i] - 1);
                prevIndex = i;
            }
            result = MahjongTable.Rebuild(result);
            return(result);
        }
 public BaseTileCollection(BaseTile[] baseTiles)
 {
     this.baseTiles = baseTiles;
     this.sorted    = new SortedTilesEnumerator(baseTiles);
 }
 public BaseTileCollection(IEnumerable <BaseTile> baseTiles)
 {
     this.baseTiles = baseTiles.ToArray();
     Array.Sort(this.baseTiles);
     this.sorted = new SortedTilesEnumerator(baseTiles);
 }