示例#1
0
        public void TrySolve_MegaPuzzle_Solves()
        {
            var puzzle = new PuzzleWithPossibleValues(new int?[][] {
                new int?[] { null, null, null, null, 10, 1, null, 8, null, 15, 3, 11, null, 2, 16, null },
                new int?[] { 14, null, 2, null, null, 4, 3, null, null, 13, 8, null, null, 12, null, null },
                new int?[] { null, null, null, 12, null, null, null, 15, null, null, null, 7, null, null, 9, 10 },
                new int?[] { 1, 10, 15, null, 6, null, null, null, null, 14, null, null, null, null, null, 11 },
                new int?[] { null, 11, 14, 6, null, null, null, 9, 13, 8, null, null, null, null, 2, 3 },
                new int?[] { 12, null, null, null, 4, null, 7, 3, 11, 6, null, null, 16, null, 5, null },
                new int?[] { 13, 16, null, 2, null, null, null, 1, null, null, 5, null, 10, 9, null, null },
                new int?[] { null, 4, null, null, 13, null, 2, null, null, null, 16, 3, 11, null, null, null },
                new int?[] { null, null, null, 10, 3, 6, null, null, null, 9, null, 12, null, null, 4, null },
                new int?[] { null, null, 12, 15, null, 9, null, null, 7, null, null, null, 1, null, 3, 14 },
                new int?[] { null, 1, null, 4, null, null, 5, 12, 3, 10, null, 8, null, null, null, 2 },
                new int?[] { 3, 6, null, null, null, null, 15, 10, 4, null, null, null, 12, 5, 7, null },
                new int?[] { 2, null, null, null, null, null, 4, null, null, null, null, 15, null, 16, 11, 9 },
                new int?[] { 4, 14, null, null, 16, null, null, null, 2, null, null, null, 6, null, null, null },
                new int?[] { null, null, 16, null, null, 7, 8, null, null, 4, 10, null, null, 14, null, 5 },
                new int?[] { null, 3, 6, null, 9, 12, 14, null, 8, null, 13, 16, null, null, null, null }
            });
            var rowRule      = new RowUniquenessRule();
            var columnRule   = new ColumnUniquenessRule();
            var boxRule      = new BoxUniquenessRule();
            var diagonalRule = new DiagonalUniquenessRule();
            var ruleKeeper   = new DynamicRuleKeeper(
                new IRule[] { rowRule, columnRule, boxRule, diagonalRule });
            var heuristic = new StandardHeuristic(
                rowRule, columnRule, boxRule);
            var solver = new PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper, heuristic);

            Assert.True(solver.TrySolve(puzzle));
            _AssertMegaPuzzleSolved(puzzle);
        }
示例#2
0
        public void TrySolve_InvalidPuzzleWithRandomGuesses_ReturnsFalse(int?[][] matrix)
        {
            var puzzle = new Puzzle(matrix);
            var solver = new PuzzleSolver <Puzzle>(
                new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() });

            Assert.False(solver.TrySolve(puzzle, randomizeGuesses: true));
        }
示例#3
0
        public void TrySolve_ValidPuzzle_SolvesPuzzle(int?[][] matrix)
        {
            var puzzle = new Puzzle(matrix);
            var solver = new PuzzleSolver <Puzzle>(
                new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() });

            Assert.True(solver.TrySolve(puzzle));
            PuzzleTestUtils.AssertStandardPuzzleSolved(puzzle);
        }