示例#1
0
    private IEnumerator TryMatchCards(Card firstCard, Card secondCard)
    {
        yield return(new WaitForSecondsRealtime(_matchDelay));

        if (firstCard.Number != secondCard.Number)
        {
            foreach (var card in _openedCards)
            {
                card.Close();
            }
            Mistaken?.Invoke();
        }
        else
        {
            MatchFound?.Invoke();
            _totalOpened += 2;
            if (_totalOpened == _cardDistributer.Cards.Count)
            {
                _totalOpened = 0;
                AllMatchesFound?.Invoke();
            }
        }

        _openedCards.Clear();
    }
示例#2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            var invalid = false;
            var match   = false;
            var pattern = Pattern.Get <string>(executionContext);
            var text    = Text.Get <string>(executionContext);
            var format  = Format.Get <string>(executionContext);

            try
            {
                var regex = new Regex(pattern);
                match = regex.IsMatch(text);
                if (match)
                {
                    text = regex.Replace(text, format);
                }
            }
            catch (ArgumentException)
            {
                // Syntax error in the regular expression
                invalid = true;
            }

            InvalidRegularExpression.Set(executionContext, invalid);
            MatchFound.Set(executionContext, match);
            Result.Set(executionContext, text);
        }
示例#3
0
        /// <summary>
        ///	Adds a style classification to the StyleSheet.
        /// </summary>
        /// <param name="target">
        ///	The string to be styled.
        /// </param>
        /// <param name="color">
        ///	The color to be applied to the target.
        /// </param>
        /// <param name="matchHandler">
        ///	A delegate instance which describes a transformation that can be applied to the target.
        /// </param>
        public void AddStyle(
            string target,
            Color color,
            MatchFound matchHandler)
        {
            var styler = new Stylizer(target, color, matchHandler);

            Styles.Add(styler);
        }
示例#4
0
 public static StyleSheetBuilder WithStyle(
     this StyleSheetBuilder @this,
     [RegexPattern] string pattern,
     Color color,
     MatchFound matchTransformer)
 {
     @this._styleSheet.AddStyle(pattern, color, matchTransformer);
     return(@this);
 }
示例#5
0
 /// <summary>
 ///		Creates an instance of the <see cref="Stylizer"/> class.
 /// </summary>
 /// <param name="pattern">
 ///		The string to be styled.
 /// </param>
 /// <param name="color">
 ///		The color to be applied to the target.
 /// </param>
 /// <param name="matchHandler">
 ///		A delegate instance which describes a transformation that can be applied to the target.
 /// </param>
 public Stylizer(
     [RegexPattern] string pattern,
     Color color,
     MatchFound matchHandler)
 {
     Target            = new TextPattern(pattern);
     Color             = color;
     MatchFoundHandler = matchHandler;
 }
        protected override void Execute(CodeActivityContext executionContext)
        {
            var invalid     = false;
            var match       = false;
            var pattern     = Pattern.Get <string>(executionContext);
            var text        = Text.Get <string>(executionContext);
            var index       = Index.Get <int>(executionContext);
            var matchResult = string.Empty;

            try
            {
                var result = new StringBuilder();
                var regex  = new Regex(pattern);

                var results = regex.Match(text);
                var pos     = 1;

                match = results.Success;

                while (results.Success)
                {
                    if (pos == index)
                    {
                        result.Append(results.Value);
                        break;
                    }

                    if (pos == -1 && index >= 1)
                    {
                        result.Append(results);
                    }

                    results = results.NextMatch();
                    pos++;
                }

                if (result.Length > 0)
                {
                    matchResult = result.ToString();
                }
            }
            catch (ArgumentException)
            {
                invalid = true;
                // Syntax error in the regular expression
            }

            InvalidRegularExpression.Set(executionContext, invalid);
            MatchFound.Set(executionContext, match);
            Match.Set(executionContext, matchResult);
        }
示例#7
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            var invalid = false;
            var match   = false;
            var pattern = Pattern.Get <string>(executionContext);
            var text    = Text.Get <string>(executionContext);

            try
            {
                var regex  = new Regex(pattern);
                var result = regex.Match(text);
                match = result.Success;
            }
            catch (ArgumentException)
            {
                invalid = true;
                // Syntax error in the regular expression
            }

            InvalidRegularExpression.Set(executionContext, invalid);
            MatchFound.Set(executionContext, match);
        }
示例#8
0
        private async void AttemptToMatchPlayers()
        {
            _pollingCancellationToken = new CancellationTokenSource();
            while (!_pollingCancellationToken.IsCancellationRequested)
            {
                if (_queue.Count > 1)
                {
                    _queue.TryRemove(_queue.Keys.ElementAt(0), out var playerOne);
                    _queue.TryRemove(_queue.Keys.ElementAt(0), out var playerTwo);

                    var potentialMatch = new PotentialMatch(new List <PlayerWaitingForGame>
                    {
                        playerOne,
                        playerTwo
                    });
                    MatchFound?.Invoke(potentialMatch);
                    _matches.TryAdd(potentialMatch.Id, potentialMatch);
                    Task.Run(() => TimeToAcceptGame(potentialMatch));
                }

                await Task.Delay(5000);
            }
        }
示例#9
0
 /// <summary>
 /// A StyleClass instance that exposes a delegate instance which can be used for more
 /// customized styling.
 /// </summary>
 /// <param name="target">The string to be styled.</param>
 /// <param name="color">The color to be applied to the target.</param>
 /// <param name="matchHandler">A delegate instance which describes a transformation that
 /// can be applied to the target.</param>
 public Styler(string target, Color color, MatchFound matchHandler)
 {
     this.Target            = new TextPattern(target);
     this.Color             = color;
     this.MatchFoundHandler = matchHandler;
 }
示例#10
0
 private void OnMatchFound(MatchFoundEventArgs e)
 {
     MatchFound?.Invoke(this, e);
 }
示例#11
0
 public void OnMatchFound(MatchEventArgs matchEventArgs)
 {
     MatchFound?.Invoke(this, matchEventArgs);
 }
示例#12
0
 /// <summary>
 /// A StyleClass instance that exposes a delegate instance which can be used for more
 /// customized styling.
 /// </summary>
 /// <param name="target">The string to be styled.</param>
 /// <param name="color">The color to be applied to the target.</param>
 /// <param name="matchHandler">A delegate instance which describes a transformation that
 /// can be applied to the target.</param>
 /// <param name="filterMatchesByIndex">Allor matches filtering. Default return all matches. By specifying the index we get the equivalent match from the array</param>
 public Styler(string target, Color color, MatchFound matchHandler, params int[] filterMatchesByIndex)
 {
     Target            = new TextPattern(target, filterMatchesByIndex);
     Color             = color;
     MatchFoundHandler = matchHandler;
 }
        /// <summary>
        /// Searches for all matches and executes the callback method.
        /// </summary>
        /// <param name="search">List of instructions to search(this).</param>
        /// <param name="match">List of instructions w/ qualifiers to match to.</param>
        /// <param name="Found">Callback delegate for replacing matches.</param>
        /// <param name="log">Log item.</param>
        /// <returns>The instructions after all callbacks have completed.</returns>
        public static IEnumerable <CodeInstruction> SmartMatch(this IEnumerable <CodeInstruction> search, IEnumerable <KeyValuePair <CodeInstruction, Qualifier> > match, MatchFound Found, Log log)
        {
            log("[SmartTranspiler] Attempting smart match");
            var doLog  = log != null;
            var array1 = search.ToArray();             // Search
            var array2 = match.ToArray();              // Match
            var FINAL  = new List <CodeInstruction>(); // FINAL

            var found  = 0;
            var offset = 0;
            var stack  = new List <CodeInstruction>();

            // Do the scanning :D
            for (int i = 0; i < array1.Length; i++)
            {
                // Check if fully validated
                if (offset == array2.Length)
                {
                    log($"[SmartTranspiler] Found IL Match @ {i - stack.Count}.");
                    if (FINAL.Count > 0 && DEBUG)
                    {
                        log($"--{i - stack.Count - 1} \t{FINAL[FINAL.Count - 1]}");
                        for (var w = 0; w < stack.Count; w++)
                        {
                            log($"{i - stack.Count + w} \t{stack[w]}");
                        }
                    }
                    // It's a full match, call back and add the result to the FINAL
                    var replaces = Found(stack);
                    FINAL.AddRange(replaces);

                    if (DEBUG)
                    {
                        log("[SmartTranspiler] New IL Code");
                        for (var w = 0; w < replaces.ToArray().Length; w++)
                        {
                            log($"{i - replaces.ToArray().Length + w} \t{replaces.ToArray()[w]}");
                        }
                    }

                    // Reset for the next match
                    stack.Clear();
                    offset = 0;
                    found++;
                }

                var item1 = array1[i];      // Item From
                var item2 = array2[offset]; // Match To

                bool   qualifies           = true;
                Action BreaksQualification = () => qualifies = false;;

                // Validate all flags to ensure it qualifies
                foreach (Enum flag in item2.Value.GetFlags())
                {
                    switch (flag)
                    {
                    case Qualifier.OpCode:
                        // Special cases, soft break
                        if ((item1.opcode == OpCodes.Brfalse || item1.opcode == OpCodes.Brfalse_S) && (item2.Key.opcode == OpCodes.Brfalse || item2.Key.opcode == OpCodes.Brfalse_S))
                        {
                            break;
                        }
                        if ((item1.opcode == OpCodes.Brtrue || item1.opcode == OpCodes.Brtrue_S) && (item2.Key.opcode == OpCodes.Brtrue || item2.Key.opcode == OpCodes.Brtrue_S))
                        {
                            break;
                        }
                        // Heard break
                        if (item1.opcode != item2.Key.opcode)
                        {
                            BreaksQualification();
                        }
                        break;

                    case Qualifier.Operand:
                        if (item1.operand != item2.Key.operand)
                        {
                            BreaksQualification();
                        }
                        break;

                    case Qualifier.Labels:
                        var breaksLabels = false;
                        var i2           = 0;
                        foreach (var lab in item1.labels)
                        {
                            // Check if out of index
                            if (i2 >= item2.Key.labels.Count)
                            {
                                breaksLabels = true;
                                break;
                            }
                            // Check if Label matches
                            if (item1.labels[i2] != item2.Key.labels[i2])
                            {
                                breaksLabels = true;
                                break;
                            }

                            i2++;
                        }
                        if (breaksLabels)
                        {
                            BreaksQualification();
                        }
                        break;

                    case Qualifier.Blocks:
                        var breaksBlocks = false;
                        var i3           = 0;
                        foreach (var block in item1.blocks)
                        {
                            // Check if out of index
                            if (i3 >= item2.Key.blocks.Count)
                            {
                                breaksBlocks = true;
                                break;
                            }
                            // Check if Blocks matches
                            if (item1.blocks[i3].blockType != item2.Key.blocks[i3].blockType)
                            {
                                breaksBlocks = true;
                                break;
                            }
                            if (item1.blocks[i3].catchType != item2.Key.blocks[i3].catchType)
                            {
                                breaksBlocks = true;
                                break;
                            }

                            i3++;
                        }
                        if (breaksBlocks)
                        {
                            BreaksQualification();
                        }
                        break;
                    }
                }
                if (qualifies)
                {
                    // This does qualify so add it to the stack
                    stack.Add(item1);
                    offset++;
                }
                else
                {
                    // This didn't match so dump our stack, doesn't qualify
                    FINAL.AddRange(stack);
                    stack.Clear();
                    offset = 0;

                    // This one doesn't match so add it to the list
                    FINAL.Add(item1);
                }
            }

            if (found == 0)
            {
                log("[SmartTranspiler] Failed to find a match!");
                return(search);
            }
            else
            {
                log($"[SmartTranspiler] {found} match{(found > 1 ? "es" : "")} found & handled");
            }

            return(FINAL);
        }