private bool _FillMissingNumbers(int[,] board) { UnfilledPosition position = new UnfilledPosition(-1, -1); position = _GetMissingPosition(board); //If there is no missing number, the problem is solved! if (!IndeedMissing(position)) { return(true); } for (int numberToBeFilled = 1; numberToBeFilled < 10; numberToBeFilled++) { if (CanThisNumberFilled(board, position.GetRowPosition(), position.GetColumnPosition(), numberToBeFilled)) { board[position.GetRowPosition(), position.GetColumnPosition()] = numberToBeFilled; //Recurse for other missing numbers if (_FillMissingNumbers(board)) { return(true); } else { //Backtrack -> Reset the filled number board[position.GetRowPosition(), position.GetColumnPosition()] = 0; } } } return(false); }
private bool IndeedMissing(UnfilledPosition unfilledPosition) { return(unfilledPosition.GetRowPosition() != -1 && unfilledPosition.GetColumnPosition() != -1); }