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
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
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
Property Value
- CellType
CellTypeof 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
Title
Title of the puzzle. A null value means this puzzle has no title.
public string? Title { get; set; }
Property Value
Width
Width 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
FromString(string, string?)
Creates a NonogramBuilder instance constructed from puzzleString.
public static NonogramBuilder FromString(string puzzleString, string? title = null)
Parameters
puzzleStringstringThe string to convert to an instance.
titlestringOptional title to give the puzzle.
Returns
- NonogramBuilder
NonogramBuilderinstance with dimensions and solution constructed frompuzzleString.
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
puzzleStringis non-positive.
GetCell(CellPosition)
Gets the CellType of the cell at position.
public CellType GetCell(CellPosition position)
Parameters
positionCellPositionThe position of the cell.
Returns
- CellType
The
CellTypeof the cell at (x,y).
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis 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
Returns
- CellType
The
CellTypeof the cell at (x,y).
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis 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
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
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
positionCellPositionCellPosition to check.
Returns
- bool
trueif the cell is expected to be empty,falseotherwise.
Exceptions
- ArgumentOutOfRangeException
Thrown when the coordinates of
positionare 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
Returns
- bool
trueif the cell is expected to be empty,falseotherwise.
Exceptions
- ArgumentOutOfRangeException
Thrown when
xoryis 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
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 the 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
trueif it is uniquely solvable,falseotherwise.
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.
SetCell(CellPosition, CellType)
Sets the cell at position to newCellType.
public void SetCell(CellPosition position, CellType newCellType)
Parameters
positionCellPositionThe position of the cell to set.
newCellTypeCellTypeThe new
CellType. Can not be Cross.
Exceptions
- ArgumentException
Thrown when
newCellTypeisCellType.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
xintx-coordinate of cell to set.
yinty-coordinate of cell to set.
newCellTypeCellTypeThe new
CellType. Can not be Cross.
Exceptions
- ArgumentException
Thrown when
newCellTypeisCellType.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
Exceptions
- ArgumentOutOfRangeException
newWidthornewHeightare less than their respective old value
ToNonogram()
Converts this puzzle into a playable Nonogram instance.
public Nonogram ToNonogram()
Returns
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
Exceptions
- PuzzleNotSolvableException
Thrown when the built puzzle is not uniquely solvable.