Class DynamicRuleKeeper
Enforces an arbitrary injected set of rules.
Inheritance
Implements
Inherited Members
Namespace: SudokuSpice.RuleBased
Assembly: SudokuSpice.dll
Syntax
public class DynamicRuleKeeper : IRuleKeeper
Constructors
| Improve this Doc View SourceDynamicRuleKeeper(IRule[])
Constructs a rule keeper that will enforce all the given rules.
Declaration
public DynamicRuleKeeper(IRule[] rules)
Parameters
Type | Name | Description |
---|---|---|
IRule[] | rules | The rules to enforce. |
Methods
| Improve this Doc View SourceCopyWithNewReferences(IReadOnlyPuzzleWithMutablePossibleValues)
Creates a deep copy of this rule keeper, including copies of any IRules it contains, with updated internal IReadOnlyPuzzleWithMutablePossibleValues.
Declaration
public IRuleKeeper CopyWithNewReferences(IReadOnlyPuzzleWithMutablePossibleValues puzzle)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyPuzzleWithMutablePossibleValues | puzzle | The new puzzle reference. Should contain the same data as the current puzzle instance. |
Returns
Type | Description |
---|---|
IRuleKeeper |
GetRules()
Gets the IRules enforced by this rule keeper.
Declaration
public ReadOnlySpan<IRule> GetRules()
Returns
Type | Description |
---|---|
System.ReadOnlySpan<IRule> |
TryInit(IReadOnlyPuzzleWithMutablePossibleValues)
Tries to initialize this rule keeper to solve the given puzzle.
When reusing a rule keeper to solve multiple puzzles, this must be called with each new puzzle to be solved.
Declaration
public bool TryInit(IReadOnlyPuzzleWithMutablePossibleValues puzzle)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyPuzzleWithMutablePossibleValues | puzzle | The puzzle to be solved. |
Returns
Type | Description |
---|---|
System.Boolean | False if the rule keeper couldn't be initialized, for example if the puzzle already violates one of the rules. Else returns true. |
Remarks
In general, it doesn't make sense to want to maintain the previous state if this method fails. Therefore, it is not guaranteed that the rule keeper's state is unchanged on failure.
TrySet(Coordinate, Int32)
Updates possible values based on setting the given coordinate to the given value.
If this update fails (i.e. it leads to an unset square with no possible values), then it returns false and leaves all possible values unchanged.
Declaration
public bool TrySet(in Coordinate c, int value)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c | The coordinate to update. |
System.Int32 | value | The value to set |
Returns
Type | Description |
---|---|
System.Boolean | True if the possible values have been updated and the rules are still satisfied. |
Unset(Coordinate, Int32)
Undoes an update for the given value at the specified coordinate.
Declaration
public void Unset(in Coordinate c, int value)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | c | The coordinate where a value is being unset. |
System.Int32 | value | The value being unset. |