Пример #1
0
        /// <summary>
        /// Create grids objects from a file, init them and check if they are valid
        /// </summary>
        /// <param name="filename">The exact location of the file containing the grids</param>
        /// <returns>The list of parsed grids</returns>
        public static List<Grille> ParseGridsFromFile(string filename)
        {
            List<Grille> grids = new List<Grille>();
            var file = new StreamReader(filename);

            string line;

            while ((line = file.ReadLine()) != null)
            {
                var grid = new Grille(line, file.ReadLine(), file.ReadLine(), file.ReadLine().ToCharArray());

                string[] tempLines = new string[grid.Symbols.Length];
                for (int j = 0; j < grid.Symbols.Length; j++)
                {
                    tempLines[j] = file.ReadLine();
                }

                var validator = new SudokuValidator(grid.Symbols, tempLines, ref grid);
                validator.ExecuteTests();
                grids.Add(grid);
            }
            return grids;
        }
Пример #2
0
        /// <summary>
        /// Solve the current selected grid and display it 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SolveButton_OnClick(object sender, RoutedEventArgs e)
        {
            var solver = new Optibacktracker((Grille)GridListBox.SelectedItem);
            Stopwatch time = new Stopwatch();
            time.Start();
            bool res = solver.Solve();

            time.Stop();

            if (res)
            {
                Grille solving = solver.UnsolvedGrid;
                solving.IsSolved = true;
                GridListBox.SelectedItem = solver.UnsolvedGrid;
            }

            RefreshGridLayout();
            var validator = new SudokuValidator(solver.UnsolvedGrid);

            MessageLogBlock.Text += String.Format("Sudoku solved in : {0} ms -> {1} valid : {2}",time.ElapsedMilliseconds, ((Grille)GridListBox.SelectedItem).Name, validator.ExecuteTests());
        }