Show / Hide Table of Contents

Class PuzzleGenerator<TPuzzle>

Generates puzzles of the given type based on the provided solver.

Inheritance
System.Object
PuzzleGenerator<TPuzzle>
StandardPuzzleGenerator
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)
System.Object.ToString()
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 Source

PuzzleGenerator(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 Source

Generate(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 numSquaresToSet. Use TimeSpan.Zero to disable the timeout.

Returns
Type Description
TPuzzle

A puzzle of type TPuzzle with a unique solution and numSquaresToSet preset squares.

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 timeout.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX