public void GenerateGame(int blanks) { //this.generateSudoku(); // Slow algorithm this.GenerateDiagonalPuzzle(); // Generate the diagonal squares for (int i = 0; i < size; i++) // Fill sudokupuzzle with SudokuFields { for (int j = 0; j < size; j++) { sudokuPuzzle[i, j] = new SudokuField(matrix[i, j], true); } } SolvePuzzle(); // Solve basing on the diagonal sudoku while (blanks > 0) { int i = GenerateRandom() - 1; int j = GenerateRandom() - 1; if (sudokuPuzzle[i, j].Value != 0) { sudokuPuzzle[i, j].Value = 0; sudokuPuzzle[i, j].IsLocked = false; blanks--; } } }
// metoda vytvori policka sudoku // pouziva ju konstruktor a generator noveho sudoku private void createFields() { fields = new SudokuField[9, 9]; int sq = 2; for (int i = 0; i < 9; i++) { if ((i != 0) && ((i % 3) == 0)) { sq++; } else { sq -= 2; } for (int j = 0; j < 9; j++) { if ((j != 0) && ((j % 3) == 0)) { sq++; } fields[i, j] = new SudokuField(sq); } } }
private SudokuField[,] deepCopy() { SudokuField[,] fi = new SudokuField[9, 9]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { fi[i, j] = fields[i, j].Clone(); } } return(fi); }