Show / Hide Table of Contents

Class PuzzleSolver<TPuzzle>

Solves puzzles of the given type using an ExactCoverGraph.

Inheritance
object
PuzzleSolver<TPuzzle>
Implements
IPuzzleSolver<TPuzzle>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: SudokuSpice.ConstraintBased
Assembly: SudokuSpice.dll
Syntax
public class PuzzleSolver<TPuzzle> : IPuzzleSolver<TPuzzle> where TPuzzle : class, IPuzzle<TPuzzle>
Type Parameters
Name Description
TPuzzle

The type of puzzle to solve.

Remarks

This class is thread-safe as long as the given constraints' implementations of TryConstrain(IReadOnlyPuzzle, ExactCoverGraph) are also thread-safe. If that's true, then it's safe to solve multiple puzzles concurrently via the same solver object.

Constructors

| Edit this page View Source

PuzzleSolver(IConstraint[])

Creates a solver that can solve puzzles using the given IConstraints. The same solver can be reused for multiple puzzles.

Declaration
public PuzzleSolver(IConstraint[] constraints)
Parameters
Type Name Description
IConstraint[] constraints

The constraints to satisfy when solving puzzles.

Methods

| Edit this page View Source

ComputeStatsForAllSolutions(TPuzzle, CancellationToken?)

Finds stats for all the solutions to the given puzzle. The puzzle is left unchanged.

Declaration
public SolveStats ComputeStatsForAllSolutions(TPuzzle puzzle, CancellationToken? token = null)
Parameters
Type Name Description
TPuzzle puzzle
CancellationToken? token
Returns
Type Description
SolveStats
Exceptions
Type Condition
OperationCanceledException

May be thrown if the given cancellation token is canceled during the operation.

| Edit this page View Source

HasUniqueSolution(TPuzzle, CancellationToken?)

Determines if the given puzzle has a unique solution. The puzzle is left unchanged.

Declaration
public bool HasUniqueSolution(TPuzzle puzzle, CancellationToken? token = null)
Parameters
Type Name Description
TPuzzle puzzle
CancellationToken? token
Returns
Type Description
bool
Exceptions
Type Condition
OperationCanceledException

May be thrown if the given cancellation token is canceled during the operation.

| Edit this page View Source

Solve(TPuzzle, bool)

Solves the given puzzle in place.

Declaration
public TPuzzle Solve(TPuzzle puzzle, bool randomizeGuesses = false)
Parameters
Type Name Description
TPuzzle puzzle

The puzzle to solve. This will be copied instead of solved in-place.

bool randomizeGuesses

If true, this will guess in a random order when forced to guess. Else, the guessing order is up to the implementation, but it should be stable.

Returns
Type Description
TPuzzle

A solved copy of the given puzzle.

Exceptions
Type Condition
ArgumentException

Thrown if this puzzle can't be solved by this solver.

| Edit this page View Source

TrySolve(TPuzzle, bool)

Attempts to solve the given puzzle.

Declaration
public bool TrySolve(TPuzzle puzzle, bool randomizeGuesses = false)
Parameters
Type Name Description
TPuzzle puzzle

The puzzle to solve. This will be solved in place.

bool randomizeGuesses

If true, this will guess in a random order when forced to guess. Else, the guessing order is up to the implementation, but it should be stable.

Returns
Type Description
bool

Implements

IPuzzleSolver<TPuzzle>
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX