Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            DateTime startTime = DateTime.Now;

            _commandStore = new CommandStore();
            var generators = new List<CrossGenerator>
                {
                    CreateGenerator("../templates/Template1.txt", "../dict/cz", _commandStore),
                    CreateGenerator("../templates/Template2.txt", "../dict/words", _commandStore),
                    CreateGenerator("../templates/Template3.txt", "../dict/cz", _commandStore),
                    CreateGenerator("../templates/Template4.txt", "../dict/cz", _commandStore),
                    CreateGenerator("../templates/american.txt", "../dict/words", _commandStore),
                    CreateGenerator("../templates/british.txt", "../dict/words", _commandStore),
                    CreateGenerator("../templates/japanese.txt", "../dict/cz", _commandStore)
                };
            //command reader
            const int maxSolutionsCount = 3;
            var ri = new ReadInput(_commandStore);
            Task.Run(() => ri.Run());

            var tasks =
                generators.Select(gen1 => Task.Factory.StartNew(() =>
                GenerateAndOutput(gen1, _commandStore, maxSolutionsCount))).ToArray();
            Task.WaitAll(tasks);
            ri.ShouldStop = true;

            TimeSpan timeSpan = DateTime.Now - startTime;
            Console.WriteLine("Time elapsed: {0}", timeSpan);
        }
Пример #2
0
 public static void GenerateAndOutput(CrossGenerator generator, CommandStore commands, int maxSolutionsCount)
 {
     int solutionsCount = 0;
     foreach (var solution in generator.Generate())
     {
         lock (commands.Lock)
         {
             Console.WriteLine($"Solution {solutionsCount} found:");
             using (var w = OpenConsoleWriter())
                 solution.WriteTo(w);
         }
         if (++solutionsCount == maxSolutionsCount)
             break;
     }
     if (solutionsCount == 0)
         Console.WriteLine("Solution not found:");
 }
Пример #3
0
 static CrossGenerator CreateGenerator(string file, string dictFile, CommandStore commands)
 {
     DateTime startTime = DateTime.Now;
     var cb = CrossBoardCreator.CreateFromFile(file);
     var dict = new Dictionary(dictFile, cb.MaxWordLength);
     cb.Preprocess(dict);
     var gen = new CrossGenerator(dict, cb);
     gen.Watcher += GeneratorWatcher;
     return gen;
 }