Ejemplo n.º 1
0
        private void Confirm()
        {
            var sudokuArray1 = GetSudokuGrid(CurrentSudoku);
            var sudokuArray2 = CurrentSudoku.GetCopyOfCompleteSudokuArray();

            if (Solver.CheckIfComplete(sudokuArray2))
            {
                ConfirmIfSolutionIsCorrect(sudokuArray1, sudokuArray2);
            }
            if (!Solver.CheckIfComplete(sudokuArray2))
            {
                sudokuArray2 = Solver.CopySudoku(CurrentSudoku.SudokuIncompleteArray);

                if (Solver.SolveSudokuGrid(CurrentSudoku, sudokuArray2))
                {
                    CurrentSudoku.SetCompleteSudokuArray(sudokuArray2);
                    ConfirmIfSolutionIsCorrect(sudokuArray1, sudokuArray2);
                }
                else
                {
                    MessageBox.Show("This grid doesn't have a solution and couldn't be solved by the application's algorithm.", "No solution given");
                }
            }
        }
Ejemplo n.º 2
0
        public static string ConvertSudokuIntoSeed(Sudoku sudoku)
        {
            var completeArray   = sudoku.GetCopyOfCompleteSudokuArray();
            var incompleteArray = sudoku.SudokuIncompleteArray;
            var fieldSeedList   = new List <string>();

            for (int x = 0; x < completeArray.GetLength(0); x++)
            {
                for (int y = 0; y < completeArray.GetLength(1); y++)
                {
                    var s = $"{Convert.ToChar(64 + incompleteArray[x, y])}{Convert.ToChar(64 + completeArray[x, y])}{Convert.ToChar(64 + sudoku.GetBoxNumberOfCoordinate(new int[2] { x, y }))}";
                    fieldSeedList.Add(s);
                }
            }

            var fieldSeed = String.Join(".", fieldSeedList);
            var gridSeed  = $"{sudoku.rating}";

            return($"{gridSeed}|{fieldSeed}");
        }