Ejemplo n.º 1
0
 /// <summary>
 ///     Returns a hash code for this instance.
 /// </summary>
 /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Leafs?.GetHashCode() ?? 0) * 397) ^ ((Name?.GetHashCode() ?? 0) * 23) ^ (Definition?.GetHashCode() ?? 0));
     }
 }
Ejemplo n.º 2
0
            // search if value added to dict and return amount of this value
            public int GetAmount(char currVal, string stringValue)
            {
                // if current char of word-to-insert compares to char into this leaf
                if (currVal != LeafVal)
                {
                    throw new Exception(); //todo()
                }

                if (stringValue.Length == 0)    // if this char is last in word-to-insert
                {
                    return(Amount);
                }
                else
                {
                    char nextVal = stringValue[0];
                    if (Leafs.ContainsKey(nextVal))    // if further path exist -> continue search deeper
                    {
                        return(Leafs[nextVal].GetAmount(nextVal, stringValue.Substring(1)));
                    }
                    else
                    {
                        return(0);   // there is no such word in dict
                    }
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        ///     Specific rule implementation of the match.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            if (!Leafs.Any())
            {
                Leafs.Add(RuleFunc());
            }

            return(FirstLeaf.MatchImpl(state));
        }
Ejemplo n.º 4
0
 public virtual bool RemoveLeaf(Q q)
 {
     if (Leafs.ContainsKey(q.Text))
     {
         Leafs.Remove(q.Text); return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
 public virtual ILeaf <T, Q> AddLeaf(Q q)
 {
     if (Leafs.ContainsKey(q.Text))
     {
         return(null);
     }
     else
     {
         ILeaf <T, Q> r = new LeafBase <T, Q>(q); Leafs.Add(q.Text, r); return(r);
     }
 }
Ejemplo n.º 6
0
 public virtual ILeaf <T, Q> Values(string key)
 {
     if (Leafs.ContainsKey(key))
     {
         return(Leafs[key]);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
 public static bool CompareLeafs(Leafs aLeafs, Leafs bLeafs)
 {
     for (int i = 0; i < 4; i++)
     {
         if (aLeafs.nums[i] != bLeafs.nums[i])
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 8
0
        /// <summary>
        ///     Specific rule implementation of the match. Which matches if all rules match.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns>
        protected internal override bool MatchImpl(ParserState state)
        {
            var oldState = state.Clone();

            if (Leafs.All(c => c.MatchImpl(state)))
            {
                return(true);
            }

            state.Assign(oldState);
            return(false);
        }
Ejemplo n.º 9
0
 public void Check()
 {
     if (Leafs.CompareLeafs(questionleafs, answerLeafs))
     {
         obstaclePanel.SetActive(true);
         Invoke("DisplayObstaclePanel", 3.0f);
         StartCoroutine(answerLeafs.ClearEffect());
         foreach (ValueLeafs leafs in leafses)
         {
             leafs.GoBack();
         }
         if (stageList.Count < 1)
         {
             currentLevel = stageData.Level + 1;
             PlayerPrefs.SetInt("Level" + currentLevel, 1);
         }
     }
 }
Ejemplo n.º 10
0
            // insert new value
            public void InsertValue(char currVal, string stringValue)
            {
                // if current char of word-to-insert compares to char into this leaf
                if (currVal != LeafVal)
                {
                    throw new Exception(); //todo()
                }


                if (stringValue.Length == 0)    // if this char is last in word-to-insert
                {
                    Amount++;
                }
                else
                {
                    char nextVal = stringValue[0];
                    if (!Leafs.ContainsKey(nextVal))    // if there wasnt such tree-way before (creating new path)
                    {
                        Leafs.Add(nextVal, new DictLeaf(nextVal));
                    }
                    Leafs[nextVal].InsertValue(nextVal, stringValue.Substring(1));  // pushing remaining part of word-to-insert further to path
                }
            }
Ejemplo n.º 11
0
 /// <summary>
 ///     Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns>
 protected bool Equals(Rule other)
 {
     return(Leafs.SequenceEqual(other.Leafs) && string.Equals(Name, other.Name) && string.Equals(Definition, other.Definition));
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     Gets the child leafs.
 /// </summary>
 /// <returns>IEnumerable&lt;Rule&gt;.</returns>
 public ReadOnlyCollection <Rule> GetLeafs() => Leafs.AsReadOnly();
Ejemplo n.º 13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SequenceRule" /> class.
 /// </summary>
 /// <param name="rules">The rules.</param>
 public SequenceRule(IEnumerable <Rule> rules)
 {
     Leafs.AddRange(rules.SelectMany(FlattenRules));
 }
Ejemplo n.º 14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SequenceRule" /> class.
        /// </summary>
        /// <param name="firstRule">The first rule.</param>
        /// <param name="secondRule">The second rule.</param>
        /// <param name="rules">The rules.</param>
        public SequenceRule(Rule firstRule, Rule secondRule, params Rule[] rules)
        {
            var allRules = Util.MergeArray(firstRule, secondRule, rules);

            Leafs.AddRange(allRules.SelectMany(FlattenRules));
        }
Ejemplo n.º 15
0
 public void AddLeaf(Leaf l)
 {
     Leafs.Add(l);
 }
Ejemplo n.º 16
0
 public void ApplyToLeafs(Leafs leafs)
 {
     leafs.nums = (int[])leafValue.Clone();
     leafs.DisplayNumbers();
 }