Class PuzzleWithPossibleValues
Stores a puzzle's data and associated possible values.
Inheritance
Implements
Inherited Members
Namespace: SudokuSpice.RuleBased
Assembly: SudokuSpice.dll
Syntax
public class PuzzleWithPossibleValues : IPuzzleWithPossibleValues<PuzzleWithPossibleValues>, IPuzzle<PuzzleWithPossibleValues>, IReadOnlyPuzzleWithMutablePossibleValues, IReadOnlyPuzzleWithPossibleValues, IReadOnlyPuzzle, IPossibleValues, IReadOnlyPossibleValues
Constructors
| Improve this Doc View SourcePuzzleWithPossibleValues(Puzzle)
Constructs a puzzle backed by the given Puzzle object, but now with the ability to track possible values.
Declaration
public PuzzleWithPossibleValues(Puzzle puzzle)
Parameters
Type | Name | Description |
---|---|---|
Puzzle | puzzle | The puzzle data to use. The puzzle maintains a reference to this object. |
PuzzleWithPossibleValues(PuzzleWithPossibleValues)
A deep copy constructor for an existing puzzle.
Declaration
public PuzzleWithPossibleValues(PuzzleWithPossibleValues existing)
Parameters
Type | Name | Description |
---|---|---|
PuzzleWithPossibleValues | existing |
PuzzleWithPossibleValues(Int32)
Constructs a new puzzle of the given side length.
Declaration
public PuzzleWithPossibleValues(int size)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | The side-length for this Sudoku puzzle. Must be in the inclusive range [1, 31]. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown if size is not the square of a whole number, or is outside the range [1, 31]. |
PuzzleWithPossibleValues(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 PuzzleWithPossibleValues(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. |
Properties
| Improve this Doc View SourceAllPossibleValuesSpan
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> |
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> |
Item[Coordinate]
Provides read and write access to a Sudoku puzzle.
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 |
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> |
NumEmptySquares
Provides read-only access to a puzzle's data.
Declaration
public int NumEmptySquares { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
NumSetSquares
Provides read-only access to a puzzle's data.
Declaration
public int NumSetSquares { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
NumSquares
Provides read-only access to a puzzle's data.
Declaration
public int NumSquares { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Size
Provides read-only access to a puzzle's data.
Declaration
public int Size { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
UniquePossibleValues
Provides read-only access to a puzzle's data.
Declaration
public BitVector UniquePossibleValues { get; }
Property Value
Type | Description |
---|---|
BitVector |
Methods
| Improve this Doc View SourceCopyFrom(Nullable<Int32>[][])
Creates a new puzzle with a copy of the given matrix.
Declaration
public static PuzzleWithPossibleValues CopyFrom(int? [][] matrix)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32>[][] | matrix |
Returns
Type | Description |
---|---|
PuzzleWithPossibleValues |
CopyFrom(Nullable<Int32>[,])
Creates a new puzzle with a copy of the given matrix.
Declaration
public static PuzzleWithPossibleValues CopyFrom(int? [, ] matrix)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32>[,] | matrix |
Returns
Type | Description |
---|---|
PuzzleWithPossibleValues |
DeepCopy()
Creates a deep-copy of this puzzle.
Declaration
public PuzzleWithPossibleValues DeepCopy()
Returns
Type | Description |
---|---|
PuzzleWithPossibleValues |
GetPossibleValues(Coordinate)
Gets the current possible values for a given coordinate.
If the value is already set for the given coordinate, the result is undefined.
Declaration
public BitVector GetPossibleValues(in Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c |
Returns
Type | Description |
---|---|
BitVector |
GetUnsetCoords()
Gets a span of coordinates for all the unset squares.
Declaration
public ReadOnlySpan<Coordinate> GetUnsetCoords()
Returns
Type | Description |
---|---|
System.ReadOnlySpan<Coordinate> |
IntersectPossibleValues(Coordinate, BitVector)
Modifies the possible values for a square to be the intersect of the current possible
values and the given possibleValues
.
Declaration
public void IntersectPossibleValues(in Coordinate c, BitVector possibleValues)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c | |
BitVector | possibleValues |
ResetPossibleValues(Coordinate)
Resets the possible values at the given location to be all possible values for this puzzle.
Declaration
public void ResetPossibleValues(in Coordinate c)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c |
SetPossibleValues(Coordinate, BitVector)
Sets the possible values for a square.
Declaration
public void SetPossibleValues(in Coordinate c, BitVector possibleValues)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c | |
BitVector | possibleValues |
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 |