public void SolveAFile(string filePath) { string line; System.IO.StreamReader file = new System.IO.StreamReader(filePath); int currentLineIndex = 0; while ((line = file.ReadLine()) != null) { string[] sudokulineElements = line.Split(','); string inputProblem = sudokulineElements[0]; string expectedSolution = sudokulineElements[1]; Sudoku.Sudoku sudoku = new Sudoku.Sudoku(inputProblem); //RenderNewEntries(sudoku, Color.Black); //MessageBox.Show($"Problem {counter} loaded from DB. Click to Solve "); bool isSovled = sudoku.Solve(); string solution = sudoku.ToString(); if (isSovled) { if (!solution.Equals(expectedSolution)) { throw new Exception($"Sudoku solution does not match input solution excped: {expectedSolution}.\n Actual {solution}"); } Console.WriteLine("Solved a Problem. Rating=" + sudoku.DifficultyRating); } else { throw new Exception($"Sudoku could not be solved. Incompelete solution is {solution} expected solution was {expectedSolution}"); } currentLineIndex++; } file.Close(); }
static void Go(string puzzle) { var sudoku = new Sudoku(puzzle); var sw = Stopwatch.StartNew(); var solved = sudoku.Solve(); sw.Stop(); if (solved) { Console.WriteLine("{0} solved in {1:f2}ms", puzzle, sw.Elapsed.TotalMilliseconds); Console.WriteLine(sudoku.ToString()); } else { Console.WriteLine("No solution found."); } }