Exemplo n.º 1
0
        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)
                {
                    Console.WriteLine($"{solutionsCount} solutions found.");
                    break;
                }
            }

            if (solutionsCount == 0)
            {
                Console.WriteLine("Solution not found:");
            }
        }
Exemplo n.º 2
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/words", _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/words", _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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public Program()
 {
     _commandStore = new CommandStore();
 }
Exemplo n.º 5
0
 public ReadInput(CommandStore aCommandStore)
 {
     _commandStore = aCommandStore;
 }