Beispiel #1
0
        public void SolveRandomly_ValidPuzzle_SolvesPuzzle(Puzzle puzzle)
        {
            var solver = new PuzzleSolver(puzzle);

            solver.SolveRandomly();
            _AssertPuzzleSolved(puzzle);
        }
        public bool SudokuSpice(PuzzleSample puzzle)
        {
            var p      = new Puzzle(puzzle.NullableMatrix);
            var solver = new PuzzleSolver(p);

            solver.SolveRandomly();
            return(p.NumEmptySquares == 0);
        }
        public void SolveRandomly_ValidPuzzle_SolvesPuzzle(Puzzle puzzle)
        {
            var solver = new PuzzleSolver <Puzzle>(
                new List <IConstraint> {
                new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint()
            });

            solver.SolveRandomly(puzzle);
            _AssertPuzzleSolved(puzzle);
        }
        public bool SudokuSpiceDynamicSingle(PuzzleSample puzzle)
        {
            var p = new Puzzle(puzzle.NullableMatrix);
            var possibleValues = new PossibleValues(p);
            var standardRules  = new StandardRules(p, possibleValues.AllPossible);
            var ruleKeeper     = new DynamicRuleKeeper(
                p, possibleValues,
                new List <ISudokuRule> {
                standardRules
            });
            var heuristic = new StandardHeuristic(
                p, possibleValues, standardRules, standardRules, standardRules);
            var solver = new PuzzleSolver(p, possibleValues, ruleKeeper, heuristic);

            solver.SolveRandomly();
            return(p.NumEmptySquares == 0);
        }
        public bool SudokuSpiceDynamicMultiple(PuzzleSample puzzle)
        {
            var p = new Puzzle(puzzle.NullableMatrix);
            var possibleValues = new PossibleValues(p);
            var rowRule        = new RowUniquenessRule(p, possibleValues.AllPossible);
            var columnRule     = new ColumnUniquenessRule(p, possibleValues.AllPossible);
            var boxRule        = new BoxUniquenessRule(p, possibleValues.AllPossible, true);
            var ruleKeeper     = new DynamicRuleKeeper(
                p, possibleValues,
                new List <ISudokuRule> {
                rowRule, columnRule, boxRule
            });
            var heuristic = new StandardHeuristic(
                p, possibleValues, rowRule, columnRule, boxRule);
            var solver = new PuzzleSolver(p, possibleValues, ruleKeeper, heuristic);

            solver.SolveRandomly();
            return(p.NumEmptySquares == 0);
        }