public MatchInfo(BlockType _blockType, MatchType _matchType, MatchDirection _matchDir, List <Vector2Int> _coords)
 {
     blockType = _blockType;
     matchType = _matchType;
     matchDir  = _matchDir;
     coords    = _coords;
 }
Example #2
0
    private List <GamePiece> FindMatches(int startX, int startY, MatchDirection matchDirection)
    {
        List <GamePiece> matches = new List <GamePiece>();

        GamePiece startPiece = board.GamePieceGrid.GetPieceAt(startX, startY);

        if (startPiece != null)
        {
            Vector2 searchDirection = GetSearchDirection(matchDirection);
            matches.Add(startPiece);

            int maxValue = ComputeTotalSearchCount(board.GamePieceGrid.Width, board.GamePieceGrid.Height, startX, startY, matchDirection);
            for (int i = 0; i < maxValue; i++)
            {
                int nextX = startX + (int)Mathf.Clamp(searchDirection.x, -1, 1) * (i + 1);
                int nextY = startY + (int)Mathf.Clamp(searchDirection.y, -1, 1) * (i + 1);
                if (!board.GamePieceGrid.IsWithinBounds(nextX, nextY))
                {
                    break;
                }

                GamePiece nextPiece = board.GamePieceGrid.GetPieceAt(nextX, nextY);
                if (nextPiece != null && nextPiece.MatchType == startPiece.MatchType) // do we really need contains??  && !matches.Contains(nextPiece)
                {
                    matches.Add(nextPiece);
                }
                else
                {
                    break;
                }
            }
        }

        return(matches);
    }
Example #3
0
 private MatchContent(string text, int startIndex, MatchDirection direction, Dictionary <string, KeyValuePair <int, int> > group)
 {
     Text = text ?? throw new ArgumentNullException(nameof(text));
     if (startIndex < 0 || startIndex > text.Length)
     {
         throw new ArgumentOutOfRangeException(nameof(startIndex), "Out of range.");
     }
     StartIndex = startIndex;
     Direction  = direction;
     _group     = group;
 }
Example #4
0
 /// <summary>
 /// Matches the specified structure to a pattern string in the specified direction.
 /// </summary>
 public static bool Match(MatchDirection Direction, string PatternString, Structure Structure, Structure[] Variables)
 {
     int si = 0;
     int vi = 0;
     if (Direction == MatchDirection.Left)
     {
         return Match(PatternString, ref si, Structure, false, Variables, ref vi);
     }
     else
     {
         return Match(PatternString, ref si, Structure, true, Variables, ref vi);
     }
 }
    /// <summary>
    /// 직선 검사를 해서 결과를 반환합니다. (없을경우 Null)
    /// </summary>
    /// <param name="block">기준 블록</param>
    /// <param name="matchDir">체크 방향</param>
    /// <returns>매치결과 </returns>
    private MatchInfo CheckStraight(Block block, MatchDirection matchDir)
    {
        var       originType = block.type;
        var       firstBlock = GetFirstBlock(block, matchDir);
        Direction dir        = MatchUtil.LookAtEnd(matchDir);
        var       result     = CheckDir(firstBlock, dir);

        if (result.Count == 0)
        {
            return(null);
        }
        var matchInfo = new MatchInfo(originType, MatchType.Straight, matchDir, result);

        return(matchInfo);
    }
    /// <summary>
    /// 매치 검사를 시작할 첫번째 블록을 가져옵니다.
    /// </summary>
    /// <param name="block">기준 블록</param>
    /// <param name="matchDir">체크 방향</param>
    /// <returns>첫번째 블록</returns>
    private Block GetFirstBlock(Block block, MatchDirection matchDir)
    {
        Block     firstBlock = block;
        Block     nextBlock  = block;
        Direction dir        = MatchUtil.LookAtStart(matchDir);

        while (true)
        {
            nextBlock = BlockManager.instance.GetNeighbor(nextBlock, dir);
            if (nextBlock == null || nextBlock.type != block.type)
            {
                break;
            }
            firstBlock = nextBlock;
        }
        return(firstBlock);
    }
Example #7
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="matchDirection"></param>
    /// <returns></returns>
    public static Vector2 GetSearchDirection(MatchDirection matchDirection)
    {
        switch (matchDirection)
        {
        case MatchDirection.Up:
            return(new Vector2(0, 1));

        case MatchDirection.Down:
            return(new Vector2(0, -1));

        case MatchDirection.Left:
            return(new Vector2(-1, 0));

        case MatchDirection.Right:
            return(new Vector2(1, 0));
        }
        throw new System.ArgumentException("Received unhandled matchDirection " + matchDirection);
    }
Example #8
0
    public static Direction LookAtStart(MatchDirection matchDir)
    {
        Direction dir = Direction.None;

        if (matchDir == MatchDirection.Vertical)
        {
            dir = Direction.Down;
        }
        else if (matchDir == MatchDirection.ForwardSlash)
        {
            dir = Direction.LeftDown;
        }
        else if (matchDir == MatchDirection.BackSlash)
        {
            dir = Direction.LeftUp;
        }
        return(dir);
    }
Example #9
0
    public static Direction LookAtEnd(MatchDirection matchDir)
    {
        Direction dir = Direction.None;

        if (matchDir == MatchDirection.Vertical)
        {
            dir = Direction.Up;
        }
        else if (matchDir == MatchDirection.ForwardSlash)
        {
            dir = Direction.RightUp;
        }
        else if (matchDir == MatchDirection.BackSlash)
        {
            dir = Direction.RightDown;
        }
        return(dir);
    }
Example #10
0
    /// <summary>
    /// Determine the number of searches needed according to the given direction and coordinates.  By doing this
    /// we can compute the exact amount of searches to make.
    /// </summary>
    /// <param name="height"></param>
    /// <param name="width"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="matchDirection"></param>
    /// <returns></returns>
    public static int ComputeTotalSearchCount(int width, int height, int x, int y, MatchDirection matchDirection)
    {
        switch (matchDirection)
        {
        case MatchDirection.Up:
            return(height - y);

        case MatchDirection.Down:
            return(y);

        case MatchDirection.Left:
            return(x);

        case MatchDirection.Right:
            return(width - x);
        }
        throw new System.ArgumentException("Received unhandled matchDirection " + matchDirection);
    }
Example #11
0
 /// <summary>
 /// Matches the specified structure to a pattern string in either direction.
 /// </summary>
 public static bool Match(string PatternString, Structure Structure, Structure[] Variables, out MatchDirection Direction)
 {
     int si = 0;
     int vi = 0;
     if (Match(PatternString, ref si, Structure, false, Variables, ref vi))
     {
         Direction = MatchDirection.Left;
         return true;
     }
     si = 0;
     vi = 0;
     if (Match(PatternString, ref si, Structure, true, Variables, ref vi))
     {
         Direction = MatchDirection.Right;
         return true;
     }
     Direction = MatchDirection.Left;
     return false;
 }
    //직선 블록 검사

    /// <summary>
    /// 해당 블록의 모든 직선 검사를 합니다. (없을경우 빈 List)
    /// </summary>
    /// <param name="block">기준 블록</param>
    /// <returns>매치결과 </returns>
    private List <MatchInfo> CheckStraightAll(Block block)
    {
        var       matchInfos = new List <MatchInfo>();
        BlockType originType = block.type;

        foreach (var it in Enum.GetValues(typeof(MatchDirection)))
        {
            MatchDirection matchDir = (MatchDirection)it;
            if (matchDir == MatchDirection.None)
            {
                continue;
            }
            var matchInfo = CheckStraight(block, matchDir);
            if (matchInfo != null)
            {
                matchInfos.Add(matchInfo);
            }
        }
        return(matchInfos);
    }
Example #13
0
        private void CreateRuleReferencingSet(string setName, MatchDirection direction = MatchDirection.SOURCE, MatchAction action = MatchAction.DROP)
        {
            string dirStr = direction == MatchDirection.DEST ? "daddr" : "saddr";
            string actStr = string.Empty;

            switch (action)
            {
            case MatchAction.ACCEPT:
                actStr = "accept";
                break;

            case MatchAction.DROP:
            default:
                actStr = "drop";
                break;
            }

            string cmd    = $@"sudo nft add rule {HostConfig.Table} {HostConfig.Chain} ip {dirStr} @{setName} {actStr}";
            bool   result = Connector.ExecuteCommand(cmd);
        }
Example #14
0
        // Helper method that performs a recursive, depth-first search of children starting at the specified parent,
        // looking for any children that conform to the specified Type and are marked with a SelectionStop
        //
        private static T FindChildSelectionStop <T>(DependencyObject parent, int leftIndex, int rightIndex, SearchDirection iterationDirection, int maxDepth, MatchDirection matchDirection)
            where T : DependencyObject
        {
            if (parent == null || maxDepth <= 0)
            {
                return(null);
            }

            int step  = iterationDirection == SearchDirection.Next ? 1 : -1;
            int index = iterationDirection == SearchDirection.Next ? leftIndex : rightIndex;

            for (; index >= leftIndex && index <= rightIndex; index = index + step)
            {
                DependencyObject child = VisualTreeHelper.GetChild(parent, index);

                // If MatchDirection is set to Down, do an eligibility match BEFORE we dive down into
                // more children.
                //
                if (matchDirection == MatchDirection.Down && IsEligibleSelectionStop <T>(child))
                {
                    return((T)child);
                }

                // If this child is not an eligible SelectionStop because it is not visible,
                // there is no point digging down to get to more children.
                //
                if (!VisualTreeUtils.IsVisible(child as UIElement))
                {
                    continue;
                }

                int grandChildrenCount = VisualTreeHelper.GetChildrenCount(child);
                if (grandChildrenCount > 0 && IsExpanded(child))
                {
                    T element = FindChildSelectionStop <T>(child, 0, grandChildrenCount - 1, iterationDirection, maxDepth - 1, matchDirection);

                    if (element != null)
                    {
                        return(element);
                    }
                }

                // If MatchDirection is set to Up, do an eligibility match AFTER we tried diving into
                // more children and failed to find something we could return.
                //
                if (matchDirection == MatchDirection.Up && IsEligibleSelectionStop <T>(child))
                {
                    return((T)child);
                }
            }

            return(null);
        }
Example #15
0
 public MatchContent(string text, int startIndex, MatchDirection direction = MatchDirection.Forward)
     : this(text, startIndex, direction, new Dictionary <string, KeyValuePair <int, int> >())
 {
 }
Example #16
0
 /// <summary>
 /// Matches a chain of primitives. The pattern string should include one variable indicating where it should continue. Gets the amount of patterns that appear
 /// before the termination string.
 /// </summary>
 public static bool MatchTerminatedChain(MatchDirection Direction, string PatternString, string TerminationString, Structure Structure, out int Amount)
 {
     Amount = 0;
     while (true)
     {
         Structure[] vars = new Structure[1];
         if (Match(Direction, PatternString, Structure, vars))
         {
             Amount++;
             Structure = vars[0];
         }
         else
         {
             return Match(Direction, TerminationString, Structure, null);
         }
     }
 }
Example #17
0
        public static bool MatchWithRegex(this string input, string toMatch, string regexString, MatchDirection matchDirection)
        {
            var regex = new Regex(regexString);

            var normalizedInput  = regex.Replace(input, "").ToUpper();
            var normalizedOutput = regex.Replace(toMatch, "").ToUpper();

            switch (matchDirection)
            {
            case MatchDirection.InputContainsOutput:
                if (normalizedInput.Contains(normalizedOutput))
                {
                    return(true);
                }
                break;

            case MatchDirection.OutputContainsInput:
                if (normalizedOutput.Contains(normalizedInput))
                {
                    return(true);
                }
                break;

            case MatchDirection.Equals:
                if (normalizedInput == normalizedOutput)
                {
                    return(true);
                }
                break;

            default:
                return(false);
            }

            return(false);
        }