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 NonogramAPI 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
widthintWidth for the puzzle to create with this PuzzleBuilder
heightintHeight for the puzzle to create with this PuzzleBuilder
titlestringOptional title to give the puzzle
Exceptions
- ArgumentOutOfRangeException
Thrown when
widthorheightis non-positive (<= 0)
Properties
Height
Height of the puzzle that is being created
public int Height { get; }
Property Value
Title
Title of the puzzle. A null value means this puzzle has no title
public string? Title { get; set; }
Property Value
Width
Height of the grid that is being created
public int Width { get; }
Property Value
Methods
EmptyCell(CellPosition)
Marks the cell at position as expected to be empty in the solution.
public void EmptyCell(CellPosition position)
Parameters
positionCellPositionPosition 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
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
positionCellPositionPosition 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
Exceptions
- ArgumentOutOfRangeException
Thrown when x or y are less than 0 or are greater or equal to Width or Height respectively
GetNonogramAPI()
Converts this puzzle into a playable NonogramAPI.
public NonogramAPI GetNonogramAPI()
Returns
Exceptions
- PuzzleNotSolvableException
Thrown when the built puzzle is not uniquely solvable
GetNonogramAPIAsync()
Converts this puzzle into a playable NonogramAPI asynchronously.
public Task<NonogramAPI> GetNonogramAPIAsync()
Returns
Exceptions
- PuzzleNotSolvableException
Thrown when the built puzzle is not uniquely solvable
IsCellEmpty(CellPosition)
Checks if Cell at position is expected to be empty in the solution.
public bool IsCellEmpty(CellPosition position)
Parameters
positionCellPositionCellPosition to check
Returns
- bool
True if the cell is expected to be empty, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when the coordinates of
positionare not within the puzzle bounds
IsCellEmpty(int, int)
Checks if Cell at (x, y) is expected to be empty in the solution.
public bool IsCellEmpty(int x, int y)
Parameters
Returns
- bool
True if the cell is expected to be empty, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis not within the puzzle bounds
IsCellFilled(CellPosition)
Checks if Cell at position is expected to be filled in the solution.
public bool IsCellFilled(CellPosition position)
Parameters
positionCellPositionCellPosition to check
Returns
- bool
True if the cell is expected to be filled, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when the coordinates of
positionare not within the puzzle bounds
IsCellFilled(int, int)
Checks if Cell at (x, y) is expected to be filled in the solution.
public bool IsCellFilled(int x, int y)
Parameters
Returns
- bool
True if the cell is expected to be filled, false otherwise
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis 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
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
pathstringThe 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
pathstringThe path to save the puzzle to
Returns
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
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
Exceptions
- OverflowException
When
newWidth*newHeightcauses overflow- ArgumentOutOfRangeException
newWidthornewHeightare less than their respective old value