public List <string> AllRules() { List <string> rules = new List <string>(); foreach (Target target in Targets) { StringBuilder rule = new StringBuilder(); if (Lonely != null) { rule.Append($"{Lonely.ToString()} "); } rule.Append(target.ToString()).Append(' '); for (int i = 0; i < Extras.Count; i++) { ExtraRule extra = Extras[i]; rule.Append($"({extra.ToString()}) "); } for (int i = 0; i < Actions.Count; i++) { ExtraRule extra = Actions[i]; string currentRule = rule.ToString(); foreach (Target action in extra.Targets) { string not = extra.Not ? "not " : string.Empty; rules.Add($"{currentRule}{not}{extra.Extra.Name.Substring(5)} {action.ToString()}"); } } } return(rules); }
private void ParseAction(Rule rule, ExtraRule extra, bool not) { not = not || ParseNot(rule); if ((token != TextType.Noun || (!includeObjects && current.IsObject)) && (extra.Extra.Name != "text_is" || token != TextType.Action)) { return; } extra.Targets.Add(new Target(current, not, current.IsObject)); GetNext(); if (token == TextType.And) { rule.OtherItems.Add(current); GetNext(); not = ParseNot(rule); if (token == TextType.Link) { ParseLink(rule, not); } else { ParseAction(rule, extra, not); } } }
private void ParseLink(Rule rule, bool not) { not = not || ParseNot(rule); if (token != TextType.Link) { return; } ExtraRule extra = new ExtraRule(current); extra.Not = not; rule.Actions.Add(extra); GetNext(); ParseAction(rule, extra, false); }
private void ParseExtra(Rule rule, bool not) { not = not || ParseNot(rule); if (token != TextType.Extra) { return; } ExtraRule extra = new ExtraRule(current); extra.Not = not; rule.Extras.Add(extra); GetNext(); ParseTarget(rule, extra, false); }
private void ParseTarget(Rule rule, ExtraRule extra, bool not) { bool isFacingType = extra != null && extra.Extra.Name == "text_facing" && current != null && (current.Name == "text_up" || current.Name == "text_left" || current.Name == "text_right" || current.Name == "text_down"); if ((token != TextType.Noun || (!includeObjects && current.IsObject)) && token != TextType.Not && !isFacingType) { return; } not = not || ParseNot(rule); bool addedNoun = token == TextType.Noun || isFacingType; if (addedNoun) { List <Target> targets = extra != null ? extra.Targets : rule.Targets; targets.Add(new Target(current, not, current.IsObject)); not = false; GetNext(); } if (token == TextType.And) { rule.OtherItems.Add(current); GetNext(); not = ParseNot(rule); if (token == TextType.Extra) { ParseExtra(rule, not); } else { ParseTarget(rule, extra, not); } } else if (token == TextType.Not || token == TextType.Extra) { ParseExtra(rule, not); } else if (token == TextType.Link) { ParseLink(rule, false); } }
public override bool Equals(object obj) { if (obj == null || !(obj is Rule)) { return(false); } Rule rule = (Rule)obj; bool pass = (rule.Lonely == null && Lonely == null) || (Lonely != null && Lonely.Equals(rule.Lonely)); if (!pass || Targets.Count != rule.Targets.Count || Extras.Count != rule.Extras.Count || Actions.Count != rule.Actions.Count) { return(false); } for (int i = 0; i < Targets.Count; i++) { Target target = Targets[i]; if (!target.Equals(rule.Targets[i])) { return(false); } } for (int i = 0; i < Extras.Count; i++) { ExtraRule extra = Extras[i]; if (!extra.Equals(rule.Extras[i])) { return(false); } } for (int i = 0; i < Actions.Count; i++) { ExtraRule extra = Actions[i]; if (!extra.Equals(rule.Actions[i])) { return(false); } } return(true); }
public override bool Equals(object obj) { if (obj == null || !(obj is ExtraRule)) { return(false); } ExtraRule rule = (ExtraRule)obj; if (Extra.ID != rule.Extra.ID || Extra.Position != rule.Extra.Position || Not != rule.Not || rule.Targets.Count != Targets.Count) { return(false); } for (int i = 0; i < Targets.Count; i++) { Target target = Targets[i]; if (!target.Equals(rule.Targets[i])) { return(false); } } return(true); }