Esempio n. 1
0
            public SearchProperties(string name, MatchCriteria matchCriteria)
            {
                Match = new List <MatchProperties>();

                Name     = name;
                Criteria = matchCriteria;
            }
    public void Start()
    {
        List <ComboBoxItem> items = new List <ComboBoxItem>();

        ComboBoxItem selectItem = new ComboBoxItem("Select");

        selectItem.OnSelect += () =>
        {
            Debug.Log("info: click select. no-op.");
        };
        items.Add(selectItem);

        ComboBoxItem timedItem = new ComboBoxItem("Timed");

        timedItem.OnSelect += () =>
        {
            errorLabel.text = "Invalid selection.";
        };
        items.Add(timedItem);

        ComboBoxItem untimedItem = new ComboBoxItem("Untimed");

        untimedItem.OnSelect += () =>
        {
            GameManager.Instance.CurrentTimeFormat = "Untimed";
            MatchCriteria criteria = new MatchCriteria(GameManager.Instance.CurrentDeckId,
                                                       GameManager.Instance.CurrentOpponentType,
                                                       GameManager.Instance.CurrentTimeFormat);
            Debug.Log("RandomOnlineTimeFormatDropdown:SelectTime() - CurrentPlayerID: " + GameManager.Instance.CurrentPlayerId);
            Debug.Log("RandomOnlineTimeFormatDropdown:SelectTime() - match criteria: " + criteria.ToString());
            GameManager.Instance.QuickMatchCriteria = criteria;

            Action <bool, TurnBasedMatch, string> callback =
                (success, m, errors) =>
            {
                if (success)
                {
                    //Debug.Log("ArenaStartMatch:StartMatch success: " + m.Status);
                    GameManager.Instance.QuickMatchCriteria = criteria;
                    Application.LoadLevel("Arena");
                }
                else
                {
                    Debug.Log("ArenaStarMatch:StartMatch WARN!!!! failed to create match");
                }
            };

            StartCoroutine(Platform.Instance.CreateMatch(criteria, callback));
        };
        items.Add(untimedItem);

        comboBox.ClearItems();
        comboBox.AddItems(items.ToArray());
    }
Esempio n. 3
0
        /// <summary>
        /// Creates a suggestion field with a list of possible text inputs and the maximum number of
        /// suggested texts to display in the drop down box.
        /// </summary>
        /// <param name="suggestionList">A list of possible text inputs.</param>
        /// <param name="maxSuggestions">The maximum number of suggested texts to display in
        /// the drop down box.</param>
        public G2DSuggestField(List <String> suggestionList, int maxSuggestions)
            : base()
        {
            this.data           = suggestionList;
            this.maxSuggestions = maxSuggestions;

            suggestList         = new G2DList();
            suggestList.Visible = false;

            matches  = new List <string>();
            criteria = MatchCriteria.Contains;
            isPartOf = null;
            keepSuggestionListOpaque = true;

            suggestList.SelectionModel.ValueChangedEvent += new ValueChanged(ItemSelected);

            name = "G2DSuggestField";
        }
Esempio n. 4
0
        private double StringMatchInPercent(string string1, string string2, MatchCriteria matchType)
        {
            var list1 = Regex.Matches(string1, @"\w+").Cast<Match>().Select(m => m.Value).ToList();
            var list2 = Regex.Matches(string2, @"\w+").Cast<Match>().Select(m => m.Value).ToList();

            List<string> bigList;
            List<string> smallList;
            double matchSum = 0;

            if (list1.Count >= list2.Count)
            {
                bigList = list1;
                smallList = list2;
            }
            else
            {
                bigList = list2;
                smallList = list1;
            }

            foreach (var smallStr in smallList)
            {
                double wordMatch = 0;

                foreach (var bigStr in bigList)
                {
                    wordMatch = Math.Max(WordMatchInPercent(smallStr, bigStr), wordMatch);
                }

                matchSum += wordMatch;
            }

            if (matchType == MatchCriteria.Long)
            {
                return matchSum / bigList.Count;
            }
            else
            {
                return matchSum / smallList.Count;
            }
        }
Esempio n. 5
0
    public IEnumerator CreateMatch(MatchCriteria c, Action <bool, TurnBasedMatch, string> callback)
    {
        Action <bool, string, string> cb =
            (success, results, errors) =>
        {
            if (success)
            {
                callback(true, ParseMatch(results), "");
            }
            else
            {
                Debug.Log("WARN!!! Platform:CreateMatch failed");
                callback(false, null, errors);
            }
        };

        Hashtable data = new Hashtable();

        data.Add("deck_id", GameManager.Instance.CurrentDeckId);
        yield return(StartCoroutine(Network.Instance.Post(PLATFORM_HOST, "turnbasedmatches", "create", null, data, cb)));
    }
        Expression VisitCriteriaEqualsForFields(ConstantMemberPair constantMemberPair, bool equal = true)
        {
            if (Mapping.TryGetFieldName(SourceType, constantMemberPair.Expression, out string fieldName))
            {
                var propertyMappings = Mapping.ElasticPropertyMappings();

                ICriteria criteria;

                if (IsPropertyTypeText(fieldName, propertyMappings))
                {
                    if (propertyMappings.ContainsKey($"{fieldName}.keyword"))
                    {
                        fieldName = $"{fieldName}.keyword";
                        criteria  = new TermCriteria(fieldName,
                                                     constantMemberPair.GetMemberFromExpression(), constantMemberPair.ConstantExpression.Value);
                    }
                    else
                    {
                        criteria = new MatchCriteria(fieldName,
                                                     constantMemberPair.GetMemberFromExpression(), constantMemberPair.ConstantExpression.Value);
                    }
                }
                else
                {
                    criteria = new TermCriteria(fieldName,
                                                constantMemberPair.GetMemberFromExpression(), constantMemberPair.ConstantExpression.Value);
                }

                if (!equal)
                {
                    criteria = NotCriteria.Create(criteria);
                }
                return(new CriteriaExpression(criteria));
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Restricts the records that are visible to the cursor to those that
        /// match the given key by the given criteria.  The key may contain
        /// prefix or wildcard key segments which can be used to further
        /// qualify the desired matching records.
        /// </summary>
        /// <param name="criteria">The inequality used to specify which records to find on the current index</param>
        /// <param name="key">The partial or full key used to specify which records to find on the current index</param>
        /// <remarks>
        /// The restriction will remain in effect until explicitly reset or
        /// until implicitly reset by other methods as noted.
        /// <para>
        /// Any previously defined restriction will be cleared.
        /// </para>
        /// <para>
        /// The cursor will be positioned before the first record in the new
        /// restriction.
        /// </para>
        /// </remarks>
        public void FindRecords(MatchCriteria criteria, Key key)
        {
            switch (criteria)
            {
                case MatchCriteria.LessThan:
                this.FindRecordsBetween(Key.Start, BoundCriteria.Inclusive, key, BoundCriteria.Exclusive);
                    break;

                case MatchCriteria.LessThanOrEqualTo:
                    this.FindRecordsBetween(Key.Start, BoundCriteria.Inclusive, key, BoundCriteria.Inclusive);
                    break;

                case MatchCriteria.EqualTo:
                    this.FindRecordsBetween(key, BoundCriteria.Inclusive, key, BoundCriteria.Inclusive);
                    break;

                case MatchCriteria.GreaterThanOrEqualTo:
                    this.FindRecordsBetween(key, BoundCriteria.Inclusive, Key.End, BoundCriteria.Inclusive);
                    break;

                case MatchCriteria.GreaterThan:
                    this.FindRecordsBetween(key, BoundCriteria.Exclusive, Key.End, BoundCriteria.Inclusive);
                    break;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a suggestion field with a list of possible text inputs and the maximum number of 
        /// suggested texts to display in the drop down box.
        /// </summary>
        /// <param name="suggestionList">A list of possible text inputs.</param>
        /// <param name="maxSuggestions">The maximum number of suggested texts to display in
        /// the drop down box.</param>
        public G2DSuggestField(List<String> suggestionList, int maxSuggestions) 
            : base()
        {
            this.data = suggestionList;
            this.maxSuggestions = maxSuggestions;

            suggestList = new G2DList();
            suggestList.Visible = false;

            matches = new List<string>();
            criteria = MatchCriteria.Contains;
            isPartOf = null;
            keepSuggestionListOpaque = true;

            suggestList.SelectionModel.ValueChangedEvent += new ValueChanged(ItemSelected);

            name = "G2DSuggestField";
        }
Esempio n. 9
0
 public static T[] Search <T>(IEnumerable <T> arr, MatchCriteria criteria, Func <T, string> source)
 {
     return(arr.Where(item => criteria.IsMatch(source(item))).ToArray());
 }
Esempio n. 10
0
 public static T[] SearchByName <T>(IEnumerable <T> arr, MatchCriteria criteria) where T : INamed
 {
     return(Search(arr, criteria, item => item.Name.GetContentRaw()));
 }
Esempio n. 11
0
    private IEnumerator RefreshMatches()
    {
        while (true)
        {
            List <string> matches = null;

            Action <bool, List <string>, string> callback =
                (success, result, errorMessage) =>
            {
                if (success)
                {
                    matches = result;
                }
            };

            yield return(StartCoroutine(Platform.Instance.ListMatches(callback)));

            if (matches != null)
            {
                List <ComboBoxItem> newItems = new List <ComboBoxItem>();

                ComboBoxItem selectItem = new ComboBoxItem("Select");
                newItems.Add(selectItem);

                ComboBoxItem newMatchItem = new ComboBoxItem("New Match");
                newMatchItem.OnSelect += () =>
                {
                    Debug.Log("Start new match");
                    Application.LoadLevel("DeckSelection");
                };
                newItems.Add(newMatchItem);

                ComboBoxItem quickMatchItem = new ComboBoxItem("Quick Match");
                quickMatchItem.OnSelect += () =>
                {
                    Debug.Log("Start quick match");
                    MatchCriteria criteria = GameManager.Instance.QuickMatchCriteria;
                    if (criteria != null)
                    {
                        Debug.Log("ArenaStartMatch:StartMatch() - criteria: " + criteria);
                        // TODO: Platform.JoinQueue
                    }
                    else
                    {
                        Debug.Log("ArenaStartMatch:StartMatch() - no quick match criteria to load");
                    }
                };
                newItems.Add(quickMatchItem);

                foreach (string m in matches)
                {
                    Debug.Log("found match: " + m);

                    Action <bool, TurnBasedMatch, string> cb =
                        (success, matchInfo, errors) =>
                    {
                        if (success)
                        {
                            string matchId = matchInfo.MatchId;
                            string status  = matchInfo.Status;

                            Debug.Log("ArenaStartMatch:RefreshMatches() status: " + status);
                            if (status == "MATCH_ACTIVE" || status == "MATCH_AUTO_MATCHING")
                            {
                                try
                                {
                                    matchData.Remove(matchId);
                                    matchData.Add(matchId, matchInfo);
                                    ComboBoxItem newItem = new ComboBoxItem(matchId + " " + status);
                                    newItem.OnSelect += () =>
                                    {
                                        Debug.Log("item " + matchId);
                                        string[] stringSeparators = new string[] { " " };
                                        string[] data;
                                        string   matchCaption = newItem.Caption;
                                        data = matchCaption.Split(stringSeparators, StringSplitOptions.None);
                                        string selectedMatch = data[0];

                                        if (matchId == selectedMatch)
                                        {
                                            Debug.Log("ArenaStartMatch:StartMatch() - starting: " + matchCaption);
                                            GameManager.Instance.CurrentMatchId = matchId;
                                            // TODO: Platform:JoinMatch ??? not needed with current architecture
                                            Application.LoadLevel("Match");
                                        }
                                    };
                                    newItems.Add(newItem);
                                } catch (ArgumentException e) {
                                    // 6nothing
                                    Debug.Log("warn!!! " + e);
                                }
                            }
                        }
                        else
                        {
                            Debug.Log("WARN!!! match info null");
                        }
                    };
                    yield return(StartCoroutine(Platform.Instance.GetMatchInfo(m, cb)));
                }
                comboBox.ClearItems();
                comboBox.AddItems(newItems.ToArray());
            }
            yield return(new WaitForSeconds(MATCH_REFRESH_RATE));
        }
    }
Esempio n. 12
0
 JObject Build(MatchCriteria criteria)
 {
     return(new JObject(
                new JProperty(criteria.Name, new JObject(
                                  new JProperty(criteria.Field, mapping.FormatValue(criteria.Member, criteria.Value))))));
 }