public void print() { #if DEBUG || OVERRIDE for (int y = 0; y < this.dim; y++) { for (int x = 0; x < this.dim; x++) { AoCUtilities.DebugWrite("{0}", (char)this.pixels[y][x].type); } AoCUtilities.DebugWriteLine(); } AoCUtilities.DebugWriteLine(); #endif }
// This doesn't work, was an attempt to avoid using regex public int CheckMessage(string messageSubstring, int recursion = 0) { //for (int i = 0; i < recursion; i++) // Console.Write("\t"); //Console.WriteLine($"{this.id} {messageSubstring}"); int lengthOfMatch = 0; if (this.leaf) { if (messageSubstring.Length > 0 && messageSubstring[0] == this.value) { lengthOfMatch = 1; } } else { bool matchStr; foreach (StringOfRules strOfRules in this.alternatives) { for (int i = 0; i < recursion; i++) { AoCUtilities.DebugWrite("\t"); } AoCUtilities.DebugWriteLine($"{messageSubstring} must match {strOfRules}"); lengthOfMatch = 0; matchStr = true; foreach (Rule rule in strOfRules.rules) { for (int i = 0; i < recursion; i++) { AoCUtilities.DebugWrite("\t"); } AoCUtilities.DebugWriteLine($"{rule}"); string messageSubstringSection = messageSubstring.Substring(lengthOfMatch); int lengthOfSubMatch = rule.CheckMessage(messageSubstringSection, recursion + 1); if (lengthOfSubMatch == 0) { matchStr = false; break; } else { lengthOfMatch += lengthOfSubMatch; } } if (matchStr) { for (int i = 0; i < recursion; i++) { AoCUtilities.DebugWrite("\t"); } AoCUtilities.DebugWriteLine($"True"); break; } else { lengthOfMatch = 0; for (int i = 0; i < recursion; i++) { AoCUtilities.DebugWrite("\t"); } AoCUtilities.DebugWriteLine($"False"); } } } return(lengthOfMatch); }