Table of Contents

Class Nonogram

Namespace
NonoSharp
Assembly
NonoSharp.dll

Class for a Nonogram puzzle. Can be initialised with static methods such as CreateRandomPuzzle(int, int, NonogramOptions?) or LoadPuzzle(string, NonogramOptions?), or by using the constructor with your own solution, Nonogram(int, int, ISet<CellPosition>, NonogramOptions?).

public class Nonogram
Inheritance
Nonogram
Inherited Members

Constructors

Nonogram(int, int, Clues[], Clues[], NonogramOptions?)

Creates a Nonogram with a solution based on columnClues and rowClues.

public Nonogram(int width, int height, Clues[] columnClues, Clues[] rowClues, NonogramOptions? options = null)

Parameters

width int

Width of the puzzle.

height int

Height of the puzzle.

columnClues Clues[]

Array of Clues instances, one for each column of the puzzle.

rowClues Clues[]

Array of Clues instances, one for each row of the puzzle.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Remarks

The puzzle must be uniquely solvable.

Exceptions

ArgumentException

Thrown when the lengths of columnClues and rowClues do not match width or height respectively.

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

PuzzleNotSolvableException

Thrown when the puzzle constructed from the clues and dimensions is not uniquely solvable.

Nonogram(int, int, ISet<CellPosition>, NonogramOptions?)

Creates a Nonogram instance with a width of width, height of height and sets the solution to solution.

public Nonogram(int width, int height, ISet<CellPosition> solution, NonogramOptions? options = null)

Parameters

width int

The width of the puzzle.

height int

The height of the puzzle.

solution ISet<CellPosition>

The solution of the puzzle.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Remarks

It is not checked whether the created puzzle can be solved. As such, using this constructor with an improper solution can lead to the puzzle being unsolvable. To create puzzles that are guaranteed to be uniquely solvable, use NonogramBuilder or create a random solvable puzzle with methods such as CreateRandomPuzzle(int, int, NonogramOptions?).

Exceptions

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

IndexOutOfRangeException

Thrown when at least one of the CellPositions found in solution is out of the bounds set by width and height.

Properties

CanRedo

A boolean indicating whether a redo via Redo() is possible.

public bool CanRedo { get; }

Property Value

bool

CanUndo

A boolean indicating whether an undo via Undo() is possible.

public bool CanUndo { get; }

Property Value

bool

ColumnClues

The clues, i.e. the numbers on the side of a grid, for the columns of the grid. In Nonogram puzzles these are usually shown at the top of the grid.

public Clues[] ColumnClues { get; }

Property Value

Clues[]

Columns

The columns of this instance's puzzle grid.

public Line[] Columns { get; }

Property Value

Line[]

Height

The height of the game grid.

public int Height { get; }

Property Value

int

this[int, int]

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

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 the cell located at (x, y).

Options

The NonogramOptions for this instance.

public NonogramOptions Options { get; set; }

Property Value

NonogramOptions

RowClues

The clues, i.e. the numbers on the side of a grid, for the rows of the grid. In Nonogram puzzles these are usually shown at the left side of the grid.

public Clues[] RowClues { get; }

Property Value

Clues[]

Rows

The rows of this instance's puzzle grid.

public Line[] Rows { get; }

Property Value

Line[]

Solution

The solution for the current puzzle, i.e. the cells (and only those cells) that must be filled for the puzzle to be solved.

public FrozenSet<CellPosition> Solution { get; }

Property Value

FrozenSet<CellPosition>

Width

The width of the game grid.

public int Width { get; }

Property Value

int

Methods

CreateRandomPuzzle(int, int, NonogramOptions?)

Creates a Nonogram instance with a random puzzle. See CreateRandomPuzzleAsync(int, int, NonogramOptions?) for the asynchronous method.

public static Nonogram CreateRandomPuzzle(int width, int height, NonogramOptions? options = null)

Parameters

width int

Width of the grid for the game.

height int

Height of the grid for the game.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Nonogram

Nonogram instance as described above.

Remarks

Generating solvable puzzles is computationally expensive and the runtime increases drastically with width and height. To ensure a fast runtime, try to keep puzzle dimensions small. The library has no (theoretical) restrictions on width or height, but it is not recommend to generate large puzzles.

Exceptions

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

CreateRandomPuzzle(int, int, int, NonogramOptions?)

Creates a Nonogram instance with a random puzzle. See CreateRandomPuzzleAsync(int, int, NonogramOptions?) for the asynchronous method.

public static Nonogram CreateRandomPuzzle(int width, int height, int seed, NonogramOptions? options = null)

Parameters

width int

Width of the grid for the game.

height int

Height of the grid for the game.

seed int

The seed to use for randomisation when generating a puzzle.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Nonogram

Nonogram instance as described above.

Remarks

Generating solvable puzzles is computationally expensive and the runtime increases drastically with width and height. To ensure a fast runtime, try to keep puzzle dimensions small. The library has no (theoretical) restrictions on width or height, but it is not recommend to generate large puzzles.

Exceptions

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

CreateRandomPuzzleAsync(int, int, NonogramOptions?)

Creates a Nonogram instance with a random puzzle asynchronously by running CreateRandomPuzzle(int, int, NonogramOptions?) on the ThreadPool as it is computionally expensive.

public static Task<Nonogram> CreateRandomPuzzleAsync(int width, int height, NonogramOptions? options = null)

Parameters

width int

Width of the grid for the game.

height int

Height of the grid for the game.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Task<Nonogram>

Nonogram instance as described above.

Remarks

Generating solvable puzzles is computationally expensive and the runtime increases drastically with width and height. To ensure a fast runtime, try to keep puzzle dimensions small. The library has no (theoretical) restrictions on width or height, but it is not recommend to generate large puzzles.

Exceptions

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

CreateRandomPuzzleAsync(int, int, int, NonogramOptions?)

Creates a Nonogram instance with a random puzzle asynchronously by running CreateRandomPuzzle(int, int, NonogramOptions?) on the ThreadPool as it is computionally expensive.

public static Task<Nonogram> CreateRandomPuzzleAsync(int width, int height, int seed, NonogramOptions? options = null)

Parameters

width int

Width of the grid for the game.

height int

Height of the grid for the game.

seed int

The seed to use for randomisation when generating a puzzle.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Task<Nonogram>

Nonogram instance as described above.

Remarks

Generating solvable puzzles is computationally expensive and the runtime increases drastically with width and height. To ensure a fast runtime, try to keep puzzle dimensions small. The library has no (theoretical) restrictions on width or height, but it is not recommend to generate large puzzles.

Exceptions

ArgumentOutOfRangeException

Thrown when width or height are non-positive.

CrossCell(CellPosition)

Marks the cell at position as crossed.

public void CrossCell(CellPosition position)

Parameters

position CellPosition

The position of the cell to cross.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

CrossCell(int, int)

Marks the cell at (x, y) as crossed.

public void CrossCell(int x, int y)

Parameters

x int

x-coordinate of the cell, zero-indexed from the left.

y int

y-coordinate of the cell, zero-indexed from the top.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

EmptyCell(CellPosition)

Clears the cell at position, returning it to blank.

public void EmptyCell(CellPosition position)

Parameters

position CellPosition

The position of the cell to empty.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

EmptyCell(int, int)

Clears the cell at (x, y), returning it to blank.

public void EmptyCell(int x, int y)

Parameters

x int

x-coordinate of the cell, zero-indexed from the left.

y int

y-coordinate of the cell, zero-indexed from the top.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

FillCell(CellPosition)

Fills the cell at position.

public void FillCell(CellPosition position)

Parameters

position CellPosition

The position of the cell to fill.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

FillCell(int, int)

Fills the cell at (x, y).

public void FillCell(int x, int y)

Parameters

x int

x-coordinate of the cell, zero-indexed from the left.

y int

y-coordinate of the cell, zero-indexed from the top.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

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

CellType of the cell at position.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is out of bounds of the grid.

GetCell(int, int)

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

public CellType GetCell(int x, int y)

Parameters

x int

x-coordinate of the cell.

y int

y-coordinate of the cell.

Returns

CellType

CellType of the cell at (x, y).

Exceptions

ArgumentOutOfRangeException

Thrown when x or y is out of bounds of the grid.

IsCellCorrect(CellPosition)

Determines whether the cell at position is correctly placed according to the solution.

public bool IsCellCorrect(CellPosition position)

Parameters

position CellPosition

The position to check.

Returns

bool

true if the cell is placed correctly, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellCorrect(int, int)

Determines whether the cell at (x, y) is correctly placed according to the solution.

public bool IsCellCorrect(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 placed correctly, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellCrossed(CellPosition)

Determines whether the cell at position is crossed.

public bool IsCellCrossed(CellPosition position)

Parameters

position CellPosition

Position to check.

Returns

bool

true if the cell is crossed, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellCrossed(int, int)

Determines whether the cell at (x, y) is crossed.

public bool IsCellCrossed(int x, int y)

Parameters

x int

x-coordinate of cell to check.

y int

y-coordinate of cell to check.

Returns

bool

true if the cell is crossed, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellEmpty(CellPosition)

Determines whether the cell at position is empty.

public bool IsCellEmpty(CellPosition position)

Parameters

position CellPosition

Position to check.

Returns

bool

true if the cell is empty, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellEmpty(int, int)

Determines whether the cell at (x, y) is empty.

public bool IsCellEmpty(int x, int y)

Parameters

x int

x-coordinate of cell to check.

y int

y-coordinate of cell to check.

Returns

bool

true if the cell is empty, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellFilled(CellPosition)

Determines whether the cell at position is filled.

public bool IsCellFilled(CellPosition position)

Parameters

position CellPosition

Position to check.

Returns

bool

true if the cell is filled, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsCellFilled(int, int)

Determines whether the cell at (x, y) is filled.

public bool IsCellFilled(int x, int y)

Parameters

x int

x-coordinate of cell to check.

y int

y-coordinate of cell to check.

Returns

bool

true if the cell is filled, false otherwise.

Exceptions

ArgumentOutOfRangeException

Thrown when the cell to check is out of the grid bounds.

IsPuzzleSolved()

Determines whether the puzzle is solved, i.e. the filled cells match the solution exactly.

public bool IsPuzzleSolved()

Returns

bool

true if the puzzle is solved, false otherwise.

LoadPuzzle(Stream, NonogramOptions?)

Loads the puzzle in stream and returns a new Nonogram instance.

public static Nonogram LoadPuzzle(Stream stream, NonogramOptions? options = null)

Parameters

stream Stream

Stream to read the puzzle from. To avoid false positives on InvalidFileFormatException exceptions, the stream must consist of ONLY one valid puzzle, such as one provided by SavePuzzle(string).

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Nonogram

Nonogram instance of the puzzle.

Remarks

stream is left open. Do not forget to close it.

Exceptions

InvalidFileFormatException

Thrown when the given file format is not supported.

NotSupportedException

Thrown when the version of the save system is not supported.

ArgumentNullException

Thrown when stream is null.

LoadPuzzle(string, NonogramOptions?)

Loads the puzzle at path and returns a new Nonogram instance.

public static Nonogram LoadPuzzle(string path, NonogramOptions? options = null)

Parameters

path string

Puzzle to load.

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options.

Returns

Nonogram

Nonogram instance of the puzzle located at the given path.

Exceptions

InvalidFileFormatException

Thrown when the given file format is not supported.

NotSupportedException

Thrown when the version of the save system is not supported.

PuzzleLoadingFailedException

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

ArgumentNullException

Thrown when path is null or empty.

LoadPuzzleAsync(Stream, NonogramOptions?)

Loads the puzzle in stream and then asynchronously converts the read data into a usable Nonogram.

public static Task<Nonogram> LoadPuzzleAsync(Stream stream, NonogramOptions? options = null)

Parameters

stream Stream

Stream to read the puzzle from. To avoid false positives on InvalidFileFormatException exceptions, the stream must consist of ONLY one valid puzzle, such as one provided by SavePuzzle(string).

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options

Returns

Task<Nonogram>

A Nonogram instance of the puzzle loaded from the stream

Remarks

Contents of stream are expected to be relatively small and is read synchronously. Larger stream contents might cause noticeable blocking.
stream is left open. Do not forget to close it.

Exceptions

InvalidFileFormatException

Thrown when the given file format is not supported

NotSupportedException

Thrown when the version of the save system is not supported

ArgumentNullException

Thrown when stream is null

LoadPuzzleAsync(string, NonogramOptions?)

Loads the puzzle at path asynchronously and returns a new Nonogram instance.

public static Task<Nonogram> LoadPuzzleAsync(string path, NonogramOptions? options = null)

Parameters

path string

Puzzle to load

options NonogramOptions

The NonogramOptions to use. Leave as null to use the default options

Returns

Task<Nonogram>

Nonogram instance of the puzzle located at the given path

Exceptions

InvalidFileFormatException

Thrown when the given file format is not supported

NotSupportedException

Thrown when the version of the save system is not supported

PuzzleLoadingFailedException

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

ArgumentNullException

Thrown when path is null or empty

Redo()

Redo the last undone move (if any). Silently returns if there is no command to redo.

public void Redo()

SaveAsFile(string, string?)

Saves a serialized version of the puzzle (that is, the solution and dimensions) to path. If path already exists, it is overwritten.

public void SaveAsFile(string path, string? title = null)

Parameters

path string

Path to save the puzzle at.

title string

Optional title to give the puzzle.

Exceptions

PuzzleSerializationFailedException

Thrown when serialization failed. 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.

ArgumentNullException

Thrown when path is null or empty.

SaveAsFileAsync(string, string?)

Saves a serialized version of the puzzle (that is, the solution and dimensions) to path. If path already exists, it is overwritten.

public Task SaveAsFileAsync(string path, string? title = null)

Parameters

path string

Path to save the puzzle at.

title string

Optional title to give the puzzle.

Returns

Task

Exceptions

PuzzleSerializationFailedException

Thrown when serialization failed. 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.

ArgumentNullException

Thrown when path is null or empty.

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 the cell, zero-indexed from the left.

y int

y-coordinate of the cell, zero-indexed from the top.

newCellType CellType

The CellType to set the cell at (x, y) to.

Exceptions

ArgumentOutOfRangeException

Thrown when x or y falls outside the bounds of the grid.

ToString()

Converts this instance into a nice string representation of the grid. This includes all cells and their respective states and the clues at the sides.

public override string ToString()

Returns

string

A string showing the current state of the game

Undo()

Undoes the last move (if any). Silently returns if there is no command to undo.

public void Undo()

Events

CellCorrected

Raised when a cell is changed incorrectly and is therefore corrected to the expected state of the cell.

public event EventHandler<CorrectionEventArgs>? CellCorrected

Event Type

EventHandler<CorrectionEventArgs>

CellStateChanged

CellStateChanged is raised when one or more cells change to a new state.

public event EventHandler<CellStateEventArgs>? CellStateChanged

Event Type

EventHandler<CellStateEventArgs>

PuzzleSolved

Raised when the puzzle has been solved.

public event EventHandler? PuzzleSolved

Event Type

EventHandler