Пример #1
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);
     }
 }
Пример #2
0
 public override DriftoidConstructor GetProduct(Structure Structure)
 {
     Structure[] vars = new Structure[2];
     MatchDirection dir;
     if (Recipe.Match("C(O(?)?)", Structure, vars, out dir))
     {
         int el;
         if (Recipe.MatchTerminatedChain(dir, "C(N?N(OO))", "H", vars[1], out el))
         {
             return MobileDriftoid.GetConstructor(el);
         }
     }
     return null;
 }
Пример #3
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;
 }
Пример #4
0
 /// <summary>
 /// Gets if the specified structure matches the pattern string (which defines a relation of primitive kinds in a structure).
 /// </summary>
 public static bool Match(string PatternString, ref int StringIndex, Structure Structure, bool ReverseStructure, Structure[] Variables, ref int VariableIndex)
 {
     PrimitiveDriftoid pd = Structure.Root as PrimitiveDriftoid;
     if (pd != null)
     {
         PrimitiveType type = pd.Type;
         string sym = PrimitiveDriftoid.GetSymbol(type);
         if (PatternString[StringIndex] == '?')
         {
             Variables[VariableIndex] = Structure;
             VariableIndex++;
             StringIndex++;
             return true;
         }
         for (int t = 0; t < sym.Length; t++)
         {
             if (StringIndex >=  PatternString.Length || PatternString[StringIndex] != sym[t])
             {
                 return false;
             }
             StringIndex++;
         }
         if (StringIndex < PatternString.Length && PatternString[StringIndex] == '(')
         {
             StringIndex++;
             Structure[] subs = Structure.Substructures;
             if (ReverseStructure)
             {
                 for (int t = subs.Length - 1; t >= 0; t--)
                 {
                     if (!Match(PatternString, ref StringIndex, subs[t], true, Variables, ref VariableIndex))
                     {
                         return false;
                     }
                 }
             }
             else
             {
                 for (int t = 0; t < subs.Length; t++)
                 {
                     if (!Match(PatternString, ref StringIndex, subs[t], false, Variables, ref VariableIndex))
                     {
                         return false;
                     }
                 }
             }
             if (PatternString[StringIndex] != ')')
             {
                 return false;
             }
             StringIndex++;
             return true;
         }
         return Structure.SubstructureAmount == 0;
     }
     else
     {
         return false;
     }
 }
Пример #5
0
 public override DriftoidConstructor GetProduct(Structure Structure)
 {
     if (this._Recipes == null)
     {
         this._Recipes = new List<Recipe>();
         Assembly asm = Assembly.GetAssembly(typeof(Reaction));
         foreach (Module m in asm.GetModules())
         {
             foreach (Type t in m.GetTypes())
             {
                 MethodInfo me = t.GetMethod("RegisterRecipes", BindingFlags.Static | BindingFlags.Public);
                 if (me != null)
                 {
                     me.Invoke(null, new object[] { this._Recipes });
                 }
             }
         }
     }
     foreach (Recipe r in this._Recipes)
     {
         DriftoidConstructor prod = r.GetProduct(Structure);
         if (prod != null)
         {
             return prod;
         }
     }
     return null;
 }
Пример #6
0
 /// <summary>
 /// Gets the product this recipe would produce given the specified structure. Returns null if this recipe has no product for the structure.
 /// </summary>
 public abstract DriftoidConstructor GetProduct(Structure Structure);
Пример #7
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);
         }
     }
 }
Пример #8
0
 public override DriftoidConstructor GetProduct(Structure Structure)
 {
     int l;
     if (Recipe.MatchTerminatedChain(MatchDirection.Left, "Fe?Fe", "H", Structure, out l))
     {
         if (l > 0)
         {
             return WeightedDriftoid.GetConstructor(l - 1);
         }
         else
         {
             return null;
         }
     }
     else
     {
         return null;
     }
 }