예제 #1
0
        /// <summary>
        /// 順子(シュンツ)を抽出します。
        /// </summary>
        /// <param name="orgHands">抽出元の手牌</param>
        /// <param name="kind">牌の種類</param>
        /// <returns>順子(シュンツ)のリスト</returns>
        private IEnumerable <uint> ExtractChow(IEnumerable <uint> orgHands, Tile.Kind kind)
        {
            var workSets             = orgHands;
            var count                = 0;
            IEnumerable <uint> chows = new List <uint>();

            // 数牌(シューパイ)以外は処理終了
            if (kind.GetGroup() != Tile.Group.Suits)
            {
                return(chows);
            }

            while (count < 4)
            {
                var workChows = this.ExtractChowInternal(workSets, kind);
                if (workChows.Count() <= 0)
                {
                    break;
                }
                chows    = chows.Concat(workChows);
                workSets = this.RemoveExtractedChows(workSets, workChows);
                count++;
            }
            return(chows);
        }
 /// <summary>
 /// 風牌の風と指定した風が同一かどうか
 /// </summary>
 /// <param name="kind">牌の種類</param>
 /// <param name="wind">風</param>
 /// <returns>風牌の風と指定した風が同一かどうか</returns>
 private bool EqualsWind(Tile.Kind kind, Wind.Index wind)
 {
     return(kind == Tile.Kind.East && wind == Wind.Index.East ||
            kind == Tile.Kind.South && wind == Wind.Index.South ||
            kind == Tile.Kind.West && wind == Wind.Index.West ||
            kind == Tile.Kind.North && wind == Wind.Index.North);
 }
예제 #3
0
    public bool isMyNeighbourThisKind(UtilityTools.Directions dir, Tile.Kind k)
    {
        if (getNeighbourTile(dir) == null)
        {
            return(false);
        }

        return(getNeighbourTile(dir).GetKind() == k);
    }
예제 #4
0
    // get center tiles of specific Kind that have neighbours of the same type
    private List <Tile> GetCenterTiles(bool vertical, bool horizontal, Tile.Kind kind, bool diagonal = false)
    {
        //if(typeof(T) != typeof(Tile.Kind)) return null;

        List <Tile> allOfKinds = new List <Tile>();

        List <Tile> result = new List <Tile>();

        foreach (Tile k in grid)
        {
            if (k.GetKind() == Tile.Kind.spawn)
            {
                allOfKinds.Add(k);
            }
        }

        foreach (Tile t in allOfKinds)
        {
            Point neighbour1 = Point.zero;
            Point neighbour2 = Point.zero;
            if (vertical)
            {
                neighbour1 = t.GetPoint().getNeighbourPoint(UtilityTools.Directions.up);
                neighbour2 = t.GetPoint().getNeighbourPoint(UtilityTools.Directions.down);

                if (isPointOutOfBounds(neighbour1) || isPointOutOfBounds(neighbour2))
                {
                    continue;
                }

                if (GetTile(neighbour1).GetKind() == kind && GetTile(neighbour2).GetKind() == kind)
                {
                    result.Add(t);
                }
            }

            if (horizontal)
            {
                neighbour1 = t.GetPoint().getNeighbourPoint(UtilityTools.Directions.left);
                neighbour2 = t.GetPoint().getNeighbourPoint(UtilityTools.Directions.right);

                if (isPointOutOfBounds(neighbour1) || isPointOutOfBounds(neighbour2))
                {
                    continue;
                }

                if (GetTile(neighbour1).GetKind() == kind && GetTile(neighbour2).GetKind() == kind)
                {
                    result.Add(t);
                }
            }
        }

        return(result);
    }
예제 #5
0
    private void loadGridLayoutFromArray(int[,] map)
    {
        Tile.Kind[,] layout = new Tile.Kind[map.GetLength(0), map.GetLength(1)];

        for (int i = 0; i < map.GetLength(0) && i < layout.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(0) && j < layout.GetLength(0); j++)
            {
                layout[i, j] = (Tile.Kind)map[i, j];
            }
        }
        gridLayout = layout;
    }
예제 #6
0
 public static Color getKindColor(Tile.Kind k)
 {
     if (k == Kind.management)
     {
         return(new Color32(248, 174, 255, 255));
     }
     else if (k == Kind.spawn)
     {
         return(new Color32(196, 137, 205, 255));
     }
     else
     {
         return(Color.white);
     }
 }
예제 #7
0
 public bool areMyNeighboursThisKind(List <UtilityTools.Directions> dirList, Tile.Kind k)
 {
     if (!dirList.Any())
     {
         return(false);
     }
     foreach (UtilityTools.Directions d in dirList)
     {
         if (isMyNeighbourThisKind(d, k) == false)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #8
0
        /// <summary>
        /// 対子(トイツ)を抽出します。
        /// </summary>
        /// <param name="orgHands">抽出元の手牌</param>
        /// <param name="kind">牌の種類</param>
        /// <returns>対子(トイツ)のリスト</returns>
        private IEnumerable <uint> ExtractPair(IEnumerable <uint> orgHands, Tile.Kind kind)
        {
            var workSets             = orgHands;
            var count                = 0;
            IEnumerable <uint> pairs = new List <uint>();

            while (count < 2)
            {
                var workPairs = this.ExtractSameNumberHands(workSets, 2, kind);
                if (workPairs.Count() <= 0)
                {
                    break;
                }
                pairs    = pairs.Concat(workPairs);
                workSets = this.RemoveExtractedHands(workSets, 2, workPairs);
                count++;
            }
            return(pairs);
        }
예제 #9
0
        /// <summary>
        /// 順子(シュンツ)を抽出します。
        /// </summary>
        /// <param name="orgHands">抽出元の手牌</param>
        /// <param name="kind">牌の種類</param>
        /// <returns>順子(シュンツ)のリスト</returns>
        private IEnumerable <uint> ExtractChowInternal(IEnumerable <uint> orgHands, Tile.Kind kind)
        {
            var retChows  = new List <uint>();
            var workChows = new List <uint>();
            var hands     = orgHands.Where(h => h.GetKind() == kind);

            foreach (var h in hands)
            {
                if (workChows.Count() <= 0)
                {
                    workChows.Add(h);
                    continue;
                }
                var last = workChows.Last();
                // 同一数値の場合はスキップ
                if (last.GetNumber() == h.GetNumber())
                {
                    continue;
                }
                // 前回数値+1ならOK
                if (last.GetNumber() < Tile.MaxNumber && (last.GetNumber() + 1) == h.GetNumber())
                {
                    workChows.Add(h);
                }
                else
                {
                    workChows.Clear();
                    workChows.Add(h);
                }

                if (workChows.Count() == 3)
                {
                    retChows.Add(workChows.First());
                    workChows.Clear();
                }
            }
            return(retChows);
        }
예제 #10
0
        /// <summary>
        /// 同一数字の手牌を抽出します。
        /// </summary>
        /// <param name="orgHands">抽出元の手牌</param>
        /// <param name="minCount">抽出条件(最低牌数)</param>
        /// <param name="kind">抽出条件(種類)</param>
        /// <returns>同一数字の手牌</returns>
        private IEnumerable <uint> ExtractSameNumberHands(IEnumerable <uint> orgHands, int minCount, Tile.Kind kind = Tile.Kind.Undefined)
        {
            var hands = orgHands
                        .GroupBy(h => new { kind = h.GetKind(), num = h.GetNumber() })
                        .Select(h => new { Kind = h.Key.kind, Num = h.Key.num, Count = h.Count() })
                        .Where(h => (kind == Tile.Kind.Undefined || h.Kind == kind) && minCount <= h.Count)
                        .Select(h => Tile.BuildTile(h.Kind, h.Num));

            return(hands);
        }
예제 #11
0
 /// <summary>
 /// 槓子(カンツ)を抽出します。
 /// </summary>
 /// <param name="orgHands">抽出元の手牌</param>
 /// <param name="kind">牌の種類</param>
 /// <returns>槓子(カンツ)のリスト</returns>
 private IEnumerable <uint> ExtractKong(IEnumerable <uint> orgHands, Tile.Kind kind)
 {
     return(this.ExtractSameNumberHands(orgHands, 4, kind));
 }
예제 #12
0
        /// <summary>
        /// ファイル名を組み立てます。
        /// </summary>
        /// <returns>ファイル名</returns>
        /// <param name="kind">種類</param>
        /// <param name="number">数</param>
        /// <param name="isRed">赤ドラかどうか</param>
        private static string BuildTileFileName(Tile.Kind kind, int number = 0, bool isRed = false)
        {
            var _isRed = isRed ? 1 : 0;

            return($"{Tile.BuildTile(kind, number, isRed)}.png");
        }