Class PuzzleGenerator<TPuzzle>
Generates puzzles of the given type based on the provided solver.
Inherited Members
Namespace: SudokuSpice
Assembly: SudokuSpice.dll
Syntax
public class PuzzleGenerator<TPuzzle>
where TPuzzle : class, IPuzzle<TPuzzle>
Type Parameters
Name | Description |
---|---|
TPuzzle | The type of puzzle to generate. |
Constructors
| Improve this Doc View SourcePuzzleGenerator(Func<Int32, TPuzzle>, IPuzzleSolver<TPuzzle>)
Creates a puzzle generator for generating puzzles.
Declaration
public PuzzleGenerator(Func<int, TPuzzle> puzzleFromSize, IPuzzleSolver<TPuzzle> solver)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Int32, TPuzzle> | puzzleFromSize | A function that constructs an empty IPuzzle<T> of the desired type and shape. The requested puzzle size (i.e. side-length) is provided as an argument. |
IPuzzleSolver<TPuzzle> | solver | A solver to be used to generate puzzles. The solver determines the rules or constraints a puzzle must satisfy. |
Methods
| Improve this Doc View SourceGenerate(Int32, Int32, TimeSpan)
Generates a puzzle that has a unique solution with the given number of squares set.
Declaration
public TPuzzle Generate(int puzzleSize, int numSquaresToSet, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | puzzleSize | The size (i.e. side-length) of the puzzle to generate. |
System.Int32 | numSquaresToSet | The number of squares that will be preset in the generated puzzle. |
System.TimeSpan | timeout | The maximum timeout during which this function can search for a unique puzzle.
Especially useful when trying to generate puzzles with low
|
Returns
Type | Description |
---|---|
TPuzzle | A puzzle of type |
Remarks
Be careful calling this with low values, as it can take a very long time to generate
unique puzzles as the value of numSquaresToSet
approaches the
minimum number of clues necessary to provide a unique puzzle of the given
puzzleSize
.
Exceptions
Type | Condition |
---|---|
System.TimeoutException | Thrown if no valid unique puzzle is found within the specified
|