Пример #1
0
        public bool SudokuSpice(PuzzleSample puzzle)
        {
            var p      = new PuzzleWithPossibleValues(puzzle.NullableJaggedMatrix);
            var solver = StandardPuzzles.CreateSolver();
            var result = solver.Solve(p, randomizeGuesses: true);

            return(result.NumEmptySquares == 0);
        }
Пример #2
0
        public bool SudokuSpiceConstraints(PuzzleSample puzzle)
        {
            var p      = new Puzzle(puzzle.NullableJaggedMatrix);
            var solver = ConstraintBased.StandardPuzzles.CreateSolver();
            var result = solver.Solve(p);

            return(result.NumEmptySquares == 0);
        }
Пример #3
0
        public bool SudokuSpice(PuzzleSample puzzle)
        {
            var p      = new Puzzle(puzzle.NullableMatrix);
            var solver = new PuzzleSolver(p);

            solver.SolveRandomly();
            return(p.NumEmptySquares == 0);
        }
Пример #4
0
        public bool SudokuSpiceDynamicSingle(PuzzleSample puzzle)
        {
            var p             = new PuzzleWithPossibleValues(puzzle.NullableJaggedMatrix);
            var standardRules = new StandardRules();
            var ruleKeeper    = new DynamicRuleKeeper(
                new IRule[] { standardRules });
            var heuristic = new StandardHeuristic(
                standardRules, standardRules, standardRules);
            var solver = new RuleBased.PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper, heuristic);
            var result = solver.Solve(p, randomizeGuesses: true);

            return(result.NumEmptySquares == 0);
        }
Пример #5
0
        public bool SudokuSpiceConstraints(PuzzleSample puzzle)
        {
            var p      = new Puzzle(puzzle.NullableMatrix);
            var solver = new PuzzleSolver <Puzzle>(
                new IConstraint[] {
                new RowUniquenessConstraint(),
                new ColumnUniquenessConstraint(),
                new BoxUniquenessConstraint()
            });

            solver.Solve(p);
            return(p.NumEmptySquares == 0);
        }
Пример #6
0
        public bool SudokuSpiceDynamicMultiple(PuzzleSample puzzle)
        {
            var p          = new PuzzleWithPossibleValues(puzzle.NullableJaggedMatrix);
            var rowRule    = new RowUniquenessRule();
            var columnRule = new ColumnUniquenessRule();
            var boxRule    = new BoxUniquenessRule();
            var ruleKeeper = new DynamicRuleKeeper(
                new IRule[] { rowRule, columnRule, boxRule });
            var heuristic = new StandardHeuristic(
                rowRule, columnRule, boxRule);
            var solver = new RuleBased.PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper, heuristic);
            var result = solver.Solve(p, randomizeGuesses: true);

            return(result.NumEmptySquares == 0);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public bool SudokuSharp(PuzzleSample puzzle)
        {
            var board = new SudokuSharp.Board();

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    if (puzzle.NullableMatrix[row, col].HasValue)
                    {
                        board.PutCell(new SudokuSharp.Location(col, row), puzzle.NullableMatrix[row, col].Value);
                    }
                }
            }

            board = board.Fill.Randomized();

            return(board.IsSolved);
        }
Пример #9
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);
        }
Пример #10
0
        public bool SudokuSharp(PuzzleSampleCollection sampleCollection)
        {
            PuzzleSample sample = sampleCollection.Random();
            var          board  = new SudokuSharp.Board();

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    if (sample.NullableMatrix[row, col].HasValue)
                    {
                        board.PutCell(new SudokuSharp.Location(col, row), sample.NullableMatrix[row, col].Value);
                    }
                }
            }

            board = board.Fill.Sequential();

            return(board.IsSolved);
        }
Пример #11
0
 public bool SudokuSolverLite(PuzzleSample puzzle) =>
 // Must clone the input, since this method solves the puzzle in-place.
 SudokuSolver.SudokuSolver.Solve((int[, ])puzzle.Matrix.Clone());