Show / Hide Table of Contents

Class UniquenessRule

Simplifies the logic needed to implement a uniqueness rule, such as "all values in a row must be unique."

Inheritance
System.Object
UniquenessRule
BoxUniquenessRule
ColumnUniquenessRule
RowUniquenessRule
Implements
IRule
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.RuleBased.Rules
Assembly: SudokuSpice.dll
Syntax
public abstract class UniquenessRule : IRule

Constructors

| Improve this Doc View Source

UniquenessRule()

Declaration
protected UniquenessRule()
| Improve this Doc View Source

UniquenessRule(UniquenessRule)

Declaration
protected UniquenessRule(UniquenessRule existing)
Parameters
Type Name Description
UniquenessRule existing

Methods

| Improve this Doc View Source

CopyWithNewReference(IReadOnlyPuzzle)

Creates a deep copy of this IRule, with any internal IReadOnlyPuzzle references updated to the given puzzle.

Declaration
public abstract IRule CopyWithNewReference(IReadOnlyPuzzle puzzle)
Parameters
Type Name Description
IReadOnlyPuzzle puzzle

The new puzzle reference to use. To ensure this rule's internal state is correct, this puzzle should contain the same data as the current puzzle referenced by this rule.

Returns
Type Description
IRule
| Improve this Doc View Source

GetDimension(Coordinate)

Gets the dimension for a coordinate.

Declaration
protected abstract int GetDimension(in Coordinate c)
Parameters
Type Name Description
Coordinate c
Returns
Type Description
System.Int32
| Improve this Doc View Source

GetNumDimensions(IReadOnlyPuzzle)

Returns the number of dimensions that will be enforced to contain unique values.

Declaration
protected abstract int GetNumDimensions(IReadOnlyPuzzle puzzle)
Parameters
Type Name Description
IReadOnlyPuzzle puzzle

The puzzle for which to determine the number of dimensions.

Returns
Type Description
System.Int32
| Improve this Doc View Source

GetPossibleValues(Coordinate)

Gets the possible values for the given coordinate based on this rule.

Declaration
public BitVector GetPossibleValues(in Coordinate c)
Parameters
Type Name Description
Coordinate c
Returns
Type Description
BitVector

The possible values represented as a BitVector.

Remarks

When implementing this method, avoid depending on dynamic information in the current puzzle being solved, such as the currently set values. This method must return information that reflects the most recent calls to Update(Coordinate, Int32, CoordinateTracker) or Revert(Coordinate, Int32, CoordinateTracker), as it can be called before or after modifying the underlying puzzle's data.

| Improve this Doc View Source

GetPossibleValues(Int32)

Declaration
protected BitVector GetPossibleValues(int dimension)
Parameters
Type Name Description
System.Int32 dimension
Returns
Type Description
BitVector
| Improve this Doc View Source

Revert(Coordinate, Int32)

Undoes an update for the given value at the specified coordinate.

This performs the same internal updates as Revert(Coordinate, Int32, CoordinateTracker), but without passing affected coordinates back to the caller. Therefore this is more efficient in cases where the caller already knows all the possible coordinates that could be affected.

Declaration
public void Revert(in Coordinate c, int val)
Parameters
Type Name Description
Coordinate c

The coordinate where a value is being unset.

System.Int32 val

The value being unset.

Remarks

This method will always be called before reverting the value on the underlying puzzle.

| Improve this Doc View Source

Revert(Coordinate, Int32, CoordinateTracker)

Undoes an update for the given value at the specified coordinate. Tracks affected coordinates in the given tracker.

Declaration
public void Revert(in Coordinate c, int val, CoordinateTracker coordTracker)
Parameters
Type Name Description
Coordinate c

The coordinate where a value is being unset.

System.Int32 val

The value being unset.

CoordinateTracker coordTracker

The coordinates of unset squares impacted by this change will be tracked in this tracker.

Remarks

This method will always be called before reverting the value on the underlying puzzle.

| Improve this Doc View Source

TrackUnsetCoordinatesOnSameDimension(Int32, Coordinate, CoordinateTracker)

Adds the coordinates of unset values on the given dimension to the given tracker.

Declaration
protected abstract void TrackUnsetCoordinatesOnSameDimension(int dimension, in Coordinate source, CoordinateTracker tracker)
Parameters
Type Name Description
System.Int32 dimension

The dimension to search.

Coordinate source

The source coordinate for the change; should be skipped.

CoordinateTracker tracker

The tracker to add coordiantes to.

| Improve this Doc View Source

TryInit(IReadOnlyPuzzle, BitVector)

Tries to initialize this rule to prepare to solve the given puzzle.

Declaration
public virtual bool TryInit(IReadOnlyPuzzle puzzle, BitVector uniquePossibleValues)
Parameters
Type Name Description
IReadOnlyPuzzle puzzle

The puzzle to be solved.

BitVector uniquePossibleValues

All the unique possible values for this puzzle.

Returns
Type Description
System.Boolean

False if the puzzle violates this rule and initialization fails, else 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's state is unchanged on failure.

| Improve this Doc View Source

Update(Coordinate, Int32, CoordinateTracker)

Updates possible values based on setting the given coordinate to the given value. Tracks affected coordinates in the given tracker.

Declaration
public void Update(in Coordinate c, int val, CoordinateTracker coordTracker)
Parameters
Type Name Description
Coordinate c

The coordinate to update.

System.Int32 val

The value to set c to.

CoordinateTracker coordTracker

The coordinates of unset squares impacted by this change will be tracked in this tracker.

Remarks

This method will always be called before setting the value on the underlying puzzle.

Implements

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