public void Process(SudokuBoard sudokuBoard) { int i, j, k, squareIndex, squareSequenceIndex; totalNumberOfItemsPossibleToSetWithoutCausingConflict = 0; for (i = 0; i < 9; i++) { for (j = 0; j < 9; j++) { numberOfPossibleItemsRows[i, j] = -1; numberOfPossibleItemsColumns[i, j] = -1; numberOfPossibleItemsSquares[i, j] = -1; } } for (i = 0; i < 9; i++) { for (j = 0; j < 9; j++) { squareIndex = (3 * (i / 3)) + (j / 3); squareSequenceIndex = (3 * (i % 3)) + (j % 3); if (!sudokuBoard.ItemIsSet(i, j)) { numberOfPossibleItemsRows[i, j] = 0; numberOfPossibleItemsColumns[j, i] = 0; numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex] = 0; for (k = 1; k <= 9; k++) { if (sudokuBoard.CanSetItem(i, j, k)) { rows[i, j, numberOfPossibleItemsRows[i, j]] = k; numberOfPossibleItemsRows[i, j]++; columns[j, i, numberOfPossibleItemsColumns[j, i]] = k; numberOfPossibleItemsColumns[j, i]++; squares[squareIndex, squareSequenceIndex, numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex]] = k; numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex]++; totalNumberOfItemsPossibleToSetWithoutCausingConflict++; } } } } } CheckProcess(); }
public void Update(SudokuBoard sudokuBoard, int rowIndex, int columnIndex) { int n, i, j, k, squareIndex, squareSequenceIndex; TwoTupleOfIntegers[] arrayOfTwoTupleOfIntegers = Utility.ReturnArrayOfTwoTupleOfIntegers(rowIndex, columnIndex); for (n = 0; n < arrayOfTwoTupleOfIntegers.Length; n++) { i = arrayOfTwoTupleOfIntegers[n].rowIndex; j = arrayOfTwoTupleOfIntegers[n].columnIndex; squareIndex = (3 * (i / 3)) + (j / 3); squareSequenceIndex = (3 * (i % 3)) + (j % 3); if (!sudokuBoard.ItemIsSet(i, j)) { totalNumberOfItemsPossibleToSetWithoutCausingConflict -= numberOfPossibleItemsRows[i, j]; numberOfPossibleItemsRows[i, j] = 0; numberOfPossibleItemsColumns[j, i] = 0; numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex] = 0; for (k = 1; k <= 9; k++) { if (sudokuBoard.CanSetItem(i, j, k)) { rows[i, j, numberOfPossibleItemsRows[i, j]] = k; numberOfPossibleItemsRows[i, j]++; columns[j, i, numberOfPossibleItemsColumns[j, i]] = k; numberOfPossibleItemsColumns[j, i]++; squares[squareIndex, squareSequenceIndex, numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex]] = k; numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex]++; totalNumberOfItemsPossibleToSetWithoutCausingConflict++; } } } else if (sudokuBoard.ItemIsSet(i, j) && (numberOfPossibleItemsRows[i, j] != -1)) { totalNumberOfItemsPossibleToSetWithoutCausingConflict -= numberOfPossibleItemsRows[i, j]; numberOfPossibleItemsRows[i, j] = -1; numberOfPossibleItemsColumns[j, i] = -1; numberOfPossibleItemsSquares[squareIndex, squareSequenceIndex] = -1; } } }