Table of Contents

Class NonogramBuilder

Namespace
NonoSharp
Assembly
NonoSharp.dll

Builder class to create a custom Nonogram puzzle, and can at the final stage be obtained as a Nonogram instance or be saved to a file.

public class NonogramBuilder
Inheritance
NonogramBuilder
Inherited Members

Constructors

NonogramBuilder(int, int, string?)

Creates a new PuzzleBuilder instance with a width of width and a height of height.

public NonogramBuilder(int width, int height, string? title = null)

Parameters

width int

Width for the puzzle to create with this PuzzleBuilder.

height int

Height for the puzzle to create with this PuzzleBuilder.

title string

Optional title to give the puzzle.

Exceptions

ArgumentOutOfRangeException

Thrown when width or height is non-positive (<= 0).

Properties

Height

Height of the puzzle that is being created.

public int Height { get; }

Property Value

int

this[int, int]

Gets or sets the CellType of the cell at (x, y). Note that a cell cannot be set to CellType.Cross.

public CellType this[int x, int y] { get; set; }

Parameters

x int

x-coordinate of cell to get/set.

y int

y-coordinate of cell to get/set.

Property Value

CellType

CellType of cell at (x, y) in this NonogramBuilder instance.

Solution

The solution that is being constructed with the builder. Cells contained in Solution are the cells that will have to be filled to complete the final puzzle.

public IReadOnlySet<CellPosition> Solution { get; }

Property Value

IReadOnlySet<CellPosition>

Title

Title of the puzzle. A null value means this puzzle has no title.

public string? Title { get; set; }

Property Value

string

Width

Width of the grid that is being created.

public int Width { get; }

Property Value

int

Methods

EmptyCell(CellPosition)

Marks the cell at position as expected to be empty in the solution.

public void EmptyCell(CellPosition position)

Parameters

position CellPosition

Position of cell to mark as empty

Exceptions

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

EmptyCell(int, int)

Marks the cell at (x, y) as expected to be empty in the solution.

public void EmptyCell(int x, int y)

Parameters

x int

x-coordinate of cell to mark as empty

y int

y-coordinate of cell to mark as empty

Exceptions

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

FillCell(CellPosition)

Marks the cell at position as expected to be filled in the solution.

public void FillCell(CellPosition position)

Parameters

position CellPosition

Position of cell to fill

Exceptions

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

FillCell(int, int)

Marks the cell at (x, y) as expected to be filled in the solution.

public void FillCell(int x, int y)

Parameters

x int

x-coordinate of cell to fill

y int

y-coordinate of cell to fill

Exceptions

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

FromString(string, string?)

Creates a NonogramBuilder instance constructed from puzzleString.

public static NonogramBuilder FromString(string puzzleString, string? title = null)

Parameters

puzzleString string

The string to convert to an instance.

title string

Optional title to give the puzzle.

Returns

NonogramBuilder

NonogramBuilder instance with dimensions and solution constructed from puzzleString.

Examples

The following code creates a 3x3 NonogramBuilder with all four corners filled in the solution.

NonogramBuilder builder = NonogramBuilder
    .FromString("O O\n   \nO O").

Alternatively, the same can be achieved as follows:

NonogramBuilder builder = NonogramBuilder
    .FromString("[O][ ][O]\n[ ][ ][ ]\n[O][ ][O]").

Remarks

Expected formats for puzzleString are of the following forms: "OO O", "[O][ ][O]", where 'O' is a filled cell in the solution, and ' ' an empty one. 'X' is also accepted for an empty cell in the solution.

Exceptions

FormatException

Thrown when parsing fails. See the error message for details.

ArgumentOutOfRangeException

Thrown when the width or height parsed from puzzleString is non-positive.

GetCell(CellPosition)

Gets the CellType of the cell at position.

public CellType GetCell(CellPosition position)

Parameters

position CellPosition

The position of the cell.

Returns

CellType

The CellType of the cell at (x, y).

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is not within the puzzle bounds.

GetCell(int, int)

Gets the CellType of the cell at (x, y).

public CellType GetCell(int x, int y)

Parameters

x int

x-coordinate of cell to get.

y int

y-coordinate of cell to get.

Returns

CellType

The CellType of the cell at (x, y).

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is not within the puzzle bounds.

GetNonogramAPI()

Converts this puzzle into a playable Nonogram instance.

[Obsolete("GetNonogramAPI() has been renamed and is deprecated. Use ToNonogram() instead. This method will be removed after v0.6.0")]
public Nonogram GetNonogramAPI()

Returns

Nonogram

Exceptions

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.

GetNonogramAPIAsync()

Converts this puzzle into a playable Nonogram asynchronously.

[Obsolete("GetNonogramAPIAsync() has been renamed and is deprecated. Use ToNonogramAsync() instead. This method will be removed after v0.6.0")]
public Task<Nonogram> GetNonogramAPIAsync()

Returns

Task<Nonogram>

Exceptions

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.

IsCellEmpty(CellPosition)

Checks if a cell at position is expected to be empty in the solution.

public bool IsCellEmpty(CellPosition position)

Parameters

position CellPosition

CellPosition to check.

Returns

bool

true if the cell is expected to be empty, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the coordinates of position are not within the puzzle bounds.

IsCellEmpty(int, int)

Checks if a cell at (x, y) is expected to be empty in the solution.

public bool IsCellEmpty(int x, int y)

Parameters

x int

x-coordinate of the cell to check.

y int

y-coordinate of the cell to check.

Returns

bool

true if the cell is expected to be empty, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is not within the puzzle bounds.

IsCellFilled(CellPosition)

Checks if a cell at position is expected to be filled in the solution.

public bool IsCellFilled(CellPosition position)

Parameters

position CellPosition

CellPosition to check.

Returns

bool

True if the cell is expected to be filled, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the coordinates of position are not within the puzzle bounds.

IsCellFilled(int, int)

Checks if the cell at (x, y) is expected to be filled in the solution.

public bool IsCellFilled(int x, int y)

Parameters

x int

x-coordinate of the cell to check.

y int

y-coordinate of the cell to check.

Returns

bool

True if the cell is expected to be filled, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is not within the puzzle bounds.

IsSolvable()

Determines whether the built puzzle is uniquely solvable.

public bool IsSolvable()

Returns

bool

true if it is uniquely solvable, false otherwise.

IsSolvableAsync()

Determines whether the built puzzle is uniquely solvable.

public Task<bool> IsSolvableAsync()

Returns

Task<bool>

True if it is uniquely solvable, false otherwise.

SaveAsFile(string)

Saves the built puzzle at path. Specifically, the expected solution and dimension are stored. The puzzle must be uniquely solvable.

public void SaveAsFile(string path)

Parameters

path string

The path to save the puzzle to.

Exceptions

PuzzleSerializationFailedException

Thrown when serialization fails. For example, when the given title is too long, or an I/O exception occurs. Usually, there is an inner exception giving more details.

PuzzleSavingFailedException

Thrown when saving files fails, e.g. because of an I/O Exception. See the inner exception for more details.

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.

SaveAsFileAsync(string)

Saves this puzzle asynchronously at path. Specifically, the expected solution and dimension are stored.

public Task SaveAsFileAsync(string path)

Parameters

path string

The path to save the puzzle to.

Returns

Task

Exceptions

PuzzleSerializationFailedException

Thrown when serialization fails. For example, when the given title is too long, or an I/O exception occurs. Usually, there is an inner exception giving more details.

PuzzleSavingFailedException

Thrown when saving files fails, e.g. because of an I/O Exception. See the inner exception for more details.

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.

SetCell(CellPosition, CellType)

Sets the cell at position to newCellType.

public void SetCell(CellPosition position, CellType newCellType)

Parameters

position CellPosition

The position of the cell to set.

newCellType CellType

The new CellType. Can not be Cross.

Exceptions

ArgumentException

Thrown when newCellType is CellType.Cross

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

SetCell(int, int, CellType)

Sets the cell at (x, y) to newCellType.

public void SetCell(int x, int y, CellType newCellType)

Parameters

x int

x-coordinate of cell to set.

y int

y-coordinate of cell to set.

newCellType CellType

The new CellType. Can not be Cross.

Exceptions

ArgumentException

Thrown when newCellType is CellType.Cross

ArgumentOutOfRangeException

Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively

SetDimensions(int, int)

Sets the dimensions of this PuzzleBuilder. This is done by adding new empty cells to the right and bottom. Cannot shrink the puzzle.

public void SetDimensions(int newWidth, int newHeight)

Parameters

newWidth int

New width for the puzzle

newHeight int

New height for the puzzle

Exceptions

ArgumentOutOfRangeException

newWidth or newHeight are less than their respective old value

ToNonogram()

Converts this puzzle into a playable Nonogram instance.

public Nonogram ToNonogram()

Returns

Nonogram

Exceptions

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.

ToNonogramAsync()

Converts this puzzle into a playable Nonogram asynchronously.

public Task<Nonogram> ToNonogramAsync()

Returns

Task<Nonogram>

Exceptions

PuzzleNotSolvableException

Thrown when the built puzzle is not uniquely solvable.