Show / Hide Table of Contents

Class Puzzle

Represents a square puzzle of shape size-by-size.

Inheritance
System.Object
Puzzle
Implements
IPuzzle<Puzzle>
IReadOnlyPuzzle
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: SudokuSpice
Assembly: SudokuSpice.dll
Syntax
public class Puzzle : IPuzzle<Puzzle>, IReadOnlyPuzzle

Constructors

| Improve this Doc View Source

Puzzle(Puzzle)

A copy constructor for an existing Puzzle.

Declaration
public Puzzle(Puzzle existing)
Parameters
Type Name Description
Puzzle existing
| Improve this Doc View Source

Puzzle(Int32)

Constructs a new puzzle of the given side length. Assumes the standard possible values for each region (i.e. the numbers from [1, size]).

Declaration
public Puzzle(int size)
Parameters
Type Name Description
System.Int32 size

The side-length for this Sudoku puzzle.

Exceptions
Type Condition
System.ArgumentException

Thrown if size is less than 1.

| Improve this Doc View Source

Puzzle(Int32, ReadOnlySpan<Int32>)

Constructs a new puzzle of the given side length and possible values for each region.

Declaration
public Puzzle(int size, ReadOnlySpan<int> allPossibleValues)
Parameters
Type Name Description
System.Int32 size

The side-length for this Sudoku puzzle.

System.ReadOnlySpan<System.Int32> allPossibleValues

List the possible values for a given region in the puzzle. A value should be repeated as many times as it can be used.

Exceptions
Type Condition
System.ArgumentException

Thrown if size is less than 1.

| Improve this Doc View Source

Puzzle(Nullable<Int32>[][])

Constructs a new puzzle backed by the given array.

The puzzle is backed directly by this array (i.e. modifying the array modifies the puzzle, and vice-versa). If this is not what you want, see CopyFrom(Nullable<Int32>[,]) and CopyFrom(Nullable<Int32>[][]). Note that all future modifications should be done through this puzzle object, else this will be in an incorrect state.

Declaration
public Puzzle(int? [][] puzzleMatrix)
Parameters
Type Name Description
System.Nullable<System.Int32>[][] puzzleMatrix

The data for this Sudoku puzzle. Preset squares should be set, and unset squares should be null. The puzzle maintains a reference to this array.

Exceptions
Type Condition
System.ArgumentException

Thrown if the given matrix is not square.

| Improve this Doc View Source

Puzzle(Nullable<Int32>[][], ReadOnlySpan<Int32>)

Constructs a new puzzle backed by the given array.

The puzzle is backed directly by this array (i.e. modifying the array modifies the puzzle, and vice-versa). If this is not what you want, see CopyFrom(Nullable<Int32>[,]) and CopyFrom(Nullable<Int32>[][]). Note that all future modifications should be done through this puzzle object, else this will be in an incorrect state.

Declaration
public Puzzle(int? [][] puzzleMatrix, ReadOnlySpan<int> allPossibleValues)
Parameters
Type Name Description
System.Nullable<System.Int32>[][] puzzleMatrix

The data for this Sudoku puzzle. Preset squares should be set, and unset squares should be null. The puzzle maintains a reference to this array.

System.ReadOnlySpan<System.Int32> allPossibleValues

List the possible values for a given region in the puzzle. A value should be repeated as many times as it can be used.

Exceptions
Type Condition
System.ArgumentException

Thrown if the given matrix is not square.

Properties

| Improve this Doc View Source

AllPossibleValuesSpan

Gets all the possible values for this puzzle.

If a value can be repeated n times in a region, then there should be n instances of it in the span.

Declaration
public ReadOnlySpan<int> AllPossibleValuesSpan { get; }
Property Value
Type Description
System.ReadOnlySpan<System.Int32>
| Improve this Doc View Source

CountPerUniqueValue

The count of times each unique value is expected to be included in a region.

Declaration
public IReadOnlyDictionary<int, int> CountPerUniqueValue { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyDictionary<System.Int32, System.Int32>
| Improve this Doc View Source

Item[Coordinate]

Gets or sets the value of the given square, like Item[Int32, Int32], but using a Coordinate instead of langword_csharp_int accessors.

Declaration
public int? this[in Coordinate c] { get; set; }
Parameters
Type Name Description
Coordinate c

The location of the square to get/set the value of.

Property Value
Type Description
System.Nullable<System.Int32>

The value of the square at c

| Improve this Doc View Source

Item[Int32, Int32]

Gets or sets the current value of a given square. A square can be 'unset' by setting its value to null.

Declaration
public int? this[int row, int col] { get; set; }
Parameters
Type Name Description
System.Int32 row
System.Int32 col
Property Value
Type Description
System.Nullable<System.Int32>
| Improve this Doc View Source

NumEmptySquares

The current number of empty/unknown squares in the puzzle.

Declaration
public int NumEmptySquares { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

NumSetSquares

The number of set/known squares in the puzzle.

Declaration
public int NumSetSquares { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

NumSquares

The total number of squares in the puzzle.

Declaration
public int NumSquares { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Size

The side-length of the puzzle (puzzles must be square).

Declaration
public int Size { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

CopyFrom(Nullable<Int32>[][])

Creates a new puzzle with a copy of the given matrix.

Declaration
public static Puzzle CopyFrom(int? [][] matrix)
Parameters
Type Name Description
System.Nullable<System.Int32>[][] matrix
Returns
Type Description
Puzzle
| Improve this Doc View Source

CopyFrom(Nullable<Int32>[,])

Creates a new puzzle with a copy of the given matrix.

Declaration
public static Puzzle CopyFrom(int? [, ] matrix)
Parameters
Type Name Description
System.Nullable<System.Int32>[,] matrix
Returns
Type Description
Puzzle
| Improve this Doc View Source

DeepCopy()

Creates a deep-copy of this puzzle.

Declaration
public Puzzle DeepCopy()
Returns
Type Description
Puzzle
| Improve this Doc View Source

GetUnsetCoords()

Gets a span of coordinates for all the unset squares.

Declaration
public ReadOnlySpan<Coordinate> GetUnsetCoords()
Returns
Type Description
System.ReadOnlySpan<Coordinate>
| Improve this Doc View Source

ToString()

Returns the puzzle in a pretty string format, with boxes and rows separated by pipes and dashes.

Declaration
public override string ToString()
Returns
Type Description
System.String
Overrides
System.Object.ToString()

Implements

IPuzzle<T>
IReadOnlyPuzzle
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX