private bool IsSolvable(SudokuBoard board, Position position) { var availableNumbers = board.GetAllAvailableNumbersForCell(position); _isSolved = !board.ContainsZero() && IsFinalPosition(position); var nextAvailablePosition = Position.GetNextAvailablePosition(position); for (var num = 0; num < availableNumbers.Count; num++) { if (_isSolved) { break; } var number = availableNumbers[num]; if (IsNotValidNumber(board, position, nextAvailablePosition, number)) { continue; } board.Set(position, number); IsSolvable(board, nextAvailablePosition); SetCurrentPositionToZero(board, position); } return(_isSolved); }
private static bool NextCellCanHoldOnlyCurrentNumber(SudokuBoard board, Position nextAvailablePosition, int num) { return(board.GetAllAvailableNumbersForCell(nextAvailablePosition).Count == 1 && board.GetAllAvailableNumbersForCell(nextAvailablePosition)[0] == num); }