Esempio n. 1
0
        protected bool isFieldDetermined(SudokuPuzzle sudoku, SudokuPuzzle solution, SudokuField field)
        {
            // get value from the first solution
            int solutionValue = solution.Fields[field.RowIndex, field.ColumnIndex].Value;

            // try to solve the sudoku again, but now without the value from the first solution
            field.Possibilities[solutionValue - 1] = false;
            var secondSolution = guessNextField(sudoku, field);

            // if there is no second solution, the sudoku has definitely a unique solution
            return(secondSolution == null || solution.Equals(secondSolution));
        }
Esempio n. 2
0
        protected bool isFieldDetermined(SudokuPuzzle sudoku, SudokuPuzzle solution, /*Field field,*/ int row, int column)
        {
            // get value from the first solution
            var field = sudoku.Fields[row, column];
            int value = solution.Fields[row, column].Value;

            // try to solve the sudoku again, but now without the value from the first solution
            field.Possibilities[value - 1] = false;
            var secondSolution = guessNextField(sudoku, field);

            // if there is no second solution, the sudoku has definitely a unique solution
            return(secondSolution == null || solution.Equals(secondSolution));
        }
        public void CreatedPuzzlesAreCorrect()
        {
            SudokuPuzzle expected = new SudokuPuzzle("Grid 01")
            {
                PuzzleMatrix = new int[][]
                {
                    new int[] { 0, 0, 3, 0, 2, 0, 6, 0, 0 },
                    new int[] { 9, 0, 0, 3, 0, 5, 0, 0, 1 },
                    new int[] { 0, 0, 1, 8, 0, 6, 4, 0, 0 },
                    new int[] { 0, 0, 8, 1, 0, 2, 9, 0, 0 },
                    new int[] { 7, 0, 0, 0, 0, 0, 0, 0, 8 },
                    new int[] { 0, 0, 6, 7, 0, 8, 2, 0, 0 },
                    new int[] { 0, 0, 2, 6, 0, 9, 5, 0, 0 },
                    new int[] { 8, 0, 0, 2, 0, 3, 0, 0, 9 },
                    new int[] { 0, 0, 5, 0, 1, 0, 3, 0, 0 },
                }
            };
            SudokuPuzzle actual = SudokuPuzzle.CreateFromStream(GetStreamFromFileName(GOODSINGLEPUZZLEFILE));

            Assert.IsTrue(actual.Equals(expected));
        }