Class PuzzleSolver<TPuzzle>
Solves puzzles of the given type.
This solver uses a rule-based approach based on the IRules provided in the constructor. An optional heuristic can also be provided.
Inheritance
Implements
Inherited Members
Namespace: SudokuSpice.RuleBased
Assembly: SudokuSpice.dll
Syntax
public class PuzzleSolver<TPuzzle> : IPuzzleSolver<TPuzzle> where TPuzzle : class, IPuzzleWithPossibleValues<TPuzzle>
Type Parameters
Name | Description |
---|---|
TPuzzle | The type of puzzle to solve. |
Remarks
This solver is not thread-safe.
Constructors
| Improve this Doc View SourcePuzzleSolver(IRuleKeeper, IHeuristic)
Constructs a solver with the given rules and optional heuristic.
This solver can be used to solve multiple puzzles.
Declaration
public PuzzleSolver(IRuleKeeper ruleKeeper, IHeuristic heuristic = null)
Parameters
Type | Name | Description |
---|---|---|
IRuleKeeper | ruleKeeper | The rule keeper to satisfy when solving puzzles. |
IHeuristic | heuristic | A heuristic to use to solve this puzzle efficiently. Can be set to null to skip using heuristics. Note that only one heuristic can be provided. To use multiple heuristics, create a wrapper heuristic like StandardHeuristic. |
Methods
| Improve this Doc View SourceComputeStatsForAllSolutions(TPuzzle, Nullable<CancellationToken>)
Finds stats for all the solutions to the given puzzle. The puzzle is left unchanged.
Declaration
public SolveStats ComputeStatsForAllSolutions(TPuzzle puzzle, CancellationToken? token = default(CancellationToken? ))
Parameters
Type | Name | Description |
---|---|---|
TPuzzle | puzzle | |
System.Nullable<System.Threading.CancellationToken> | token |
Returns
Type | Description |
---|---|
SolveStats |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | May be thrown if the given cancellation token is canceled during the operation. |
HasUniqueSolution(TPuzzle, Nullable<CancellationToken>)
Determines if the given puzzle has a unique solution. The puzzle is left unchanged.
Declaration
public bool HasUniqueSolution(TPuzzle puzzle, CancellationToken? token = default(CancellationToken? ))
Parameters
Type | Name | Description |
---|---|---|
TPuzzle | puzzle | |
System.Nullable<System.Threading.CancellationToken> | token |
Returns
Type | Description |
---|---|
System.Boolean |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | May be thrown if the given cancellation token is canceled during the operation. |
Solve(TPuzzle, Boolean)
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. |
System.Boolean | 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 |
---|---|
System.ArgumentException | Thrown if this puzzle can't be solved by this solver. |
TrySolve(TPuzzle, Boolean)
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. |
System.Boolean | 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 |
---|---|
System.Boolean |