public void Iterate(RulesSet rules) { // Get the step int steps = 3; if (_fractal.Length % 2 == 0) { steps = 2; } // Prepare the new fractal at the correct size string[] after = new string[(steps + 1) * _fractal.Length / steps]; for (int i = 0; i < (steps + 1) * _fractal.Length / steps; ++i) { after[i] = ""; } // Process it in column for (int i = 0; i < _fractal.Length / steps; ++i) { for (int j = 0; j < _fractal.Length / steps; ++j) { // Extract the hash string hash = ""; for (int k = 0; k < steps; ++k) { hash += _fractal[(j * steps) + k].Substring(i * steps, steps); } // Get the matchine rule in the rules set string rule = rules[hash]; // Apply rule for (int k = 0; k < steps + 1; ++k) { after[j * (steps + 1) + k] += rule.Substring(k * (steps + 1), steps + 1); } } } // All done _fractal = after; }
private void AddRules() { _rulesSet = new RulesSet(); _rulesSet.AddRule(new RuleOne()); }
static int Main(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options)) { return(1); } var cars = options.Cars.Count > 0 ? string.Join(",", options.Cars).Split(',').Select(x => x.Trim()) : Directory.GetDirectories(options.Directory).Select(Path.GetFileName); var rulesSets = string.Join(",", options.RulesFile).Split(',').Select(x => RulesSet.FromFile(x.Trim())).ToList(); var databasesFiles = string.Join(",", options.DatabaseFile).Split(',').Select(x => x.Trim()).ToArray(); var hashStorage = options.Mode == ProgramMode.TestCars ? HashStorage.FromFile(databasesFiles) : new HashStorage(); foreach (var carId in cars) { if (options.Verbose) { Console.Error.WriteLine(carId); } var carDir = Path.Combine(options.Directory, carId); if (!Directory.Exists(carDir)) { Console.Error.WriteLine("! directory '{0}' not found", carDir); continue; } if (options.Mode == ProgramMode.CollectDatabase) { var entry = new StringBuilder(); entry.Append(carId); entry.Append(":"); foreach (var rulesSet in rulesSets) { if (rulesSet != rulesSets[0]) { entry.Append(","); } var hashValue = rulesSet.GetHash(carDir); foreach (var simular in hashStorage.FindSimular(carId, rulesSet.Id, hashValue, options.Threshold, options.Information ? rulesSet : null)) { Console.Error.WriteLine("! {0}: {1} and {2}, {3:F1}%", rulesSet.Id, carId, simular.CarId, simular.Value * 100); if (options.Information) { Console.Error.WriteLine(" " + string.Join(", ", simular.WorkedRules.Select(x => x.ToString()))); } } entry.Append(rulesSet.Id); entry.Append("="); entry.Append(hashValue); hashStorage.Add(carId, rulesSet.Id, hashValue); } Console.WriteLine(entry.ToString()); } else if (options.Mode == ProgramMode.TestCars) { if (hashStorage.HasCar(carId)) { continue; } foreach (var rulesSet in rulesSets) { var hashValue = rulesSet.GetHash(carDir); foreach (var simular in hashStorage.FindSimular(carId, rulesSet.Id, hashValue, options.Threshold, options.Information ? rulesSet : null)) { Console.WriteLine("{0}: {1} and {2}, {3:F1}%", rulesSet.Id, carId, simular.CarId, simular.Value * 100); if (options.Information) { Console.Error.WriteLine(" " + string.Join(", ", simular.WorkedRules.Select(x => x.ToString()))); } } } } } return(0); }