public void HasUniqueSolution_IsUniqueWithDiagonals() { var puzzle = new Puzzle(new int?[][] { new int?[] { null, null, null, null, null, null, null, 1, 2 }, new int?[] { null, 5, null, null, 9, null, null, null, null }, new int?[] { null, null, null, null, null, 8, null, null, null }, new int?[] { null, 3, null, null, null, null, 5, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, 9, null }, new int?[] { null, null, null, null, 4, 3, 9, null, null }, new int?[] { 6, null, 1, null, null, null, 7, null, null }, new int?[] { 2, null, null, null, null, null, null, null, null }, }); var boxesToConstrain = new Box[] { new Box(new Coordinate(3, 3), 3), }; var solver = new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint(), new MagicSquaresConstraint( _CreateStandardPossibleValues(9), boxesToConstrain, includeDiagonals: true) }); Assert.True(solver.HasUniqueSolution(puzzle)); }
public void HasUniqueSolution_WithOneSolutionUsingDiagonals_IsTrue() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { null, null, null, null, null, null, null, 1, 2 }, new int?[] { null, 5, null, null, 9, null, null, null, null }, new int?[] { null, null, null, null, null, 8, null, null, null }, new int?[] { null, 3, null, null, null, null, 5, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, 9, null }, new int?[] { null, null, null, null, 4, 3, 9, null, null }, new int?[] { 6, null, 1, null, null, null, 7, null, null }, new int?[] { 2, null, null, null, null, null, null, null, null }, }); var magicSquares = new Box[] { new Box(new Coordinate(3, 3), 3), }; var solver = new PuzzleSolver <PuzzleWithPossibleValues>( new DynamicRuleKeeper( new IRule[] { new RowUniquenessRule(), new ColumnUniquenessRule(), new BoxUniquenessRule(), new MagicSquaresRule(puzzle.Size, magicSquares, includeDiagonals: true), })); Assert.True(solver.HasUniqueSolution(puzzle)); }
public void HasUniqueSolution_NotUnique() { var puzzle = new Puzzle(new int?[][] { new int?[] { null, null, 9, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, 3, 5, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, }); var boxesToConstrain = new Box[] { new Box(new Coordinate(0, 0), 3), new Box(new Coordinate(3, 3), 3), new Box(new Coordinate(6, 6), 3), }; var constraint = new MagicSquaresConstraint( _CreateStandardPossibleValues(9), boxesToConstrain, includeDiagonals: false); var solver = new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), constraint, }); Assert.False(solver.HasUniqueSolution(puzzle)); }
public void HasUniqueSolution_WithManySolutions_IsFalse() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { null, null, 9, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, 3, 5, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, new int?[] { null, null, null, null, null, null, null, null, null }, }); var magicSquares = new Box[] { new Box(new Coordinate(0, 0), 3), new Box(new Coordinate(3, 3), 3), new Box(new Coordinate(6, 6), 3), }; var solver = new PuzzleSolver <PuzzleWithPossibleValues>( new DynamicRuleKeeper( new IRule[] { new RowUniquenessRule(), new MagicSquaresRule(puzzle.Size, magicSquares, includeDiagonals: false), })); Assert.False(solver.HasUniqueSolution(puzzle)); }