private static void RunPuzzle(Puzzle puzzle, int maxExecution = 100)
        {
            var engine = new SolverEngine();

            //engine.WriteLog = (message) => { Console.WriteLine(message); };
            engine.LoadPuzzle(puzzle);

            long elapsed = engine.TrySolveToEnd();

            Console.WriteLine(puzzle.Name.PadRight(19) + " : " +
                              "e " + elapsed.ToString().PadRight(3) + ", " +
                              "g " + engine.GuessedMoves().ToString().PadRight(3) + ", " +
                              "u " + engine.Undos.ToString().PadRight(3));

            bool solved = engine.IsFullySolved();

            Assert.IsTrue(solved, "Could not solve puzzle " + puzzle.Name);
            Assert.LessOrEqual(elapsed, maxExecution, "Elapsed milliseconds must be less than " + maxExecution);
        }
示例#2
0
        private void GenerateRandomPuzzle_Click(object sender, RoutedEventArgs e)
        {
            var empty = PredefinedPuzzles.EmptyPuzzle;

            engine.LoadPuzzle(empty);
            engine.TrySolveToEnd();
            engine.ClearXMoves(50);

            var puzzle = new Puzzle(engine.CopyValues())
            {
                Name = "Random " + Guid.NewGuid().ToString()
            };

            InitializeEngine();
            InitializeGrid();

            engine.LoadPuzzle(puzzle);
            PuzzleName.Content = puzzle.Name;
            PopulateUIWithValues();
            DrawAllPossibles();
        }