Exemplo n.º 1
0
        public static PuzzleSolver.SolveResult CheckUniqueness(Puzzle puzzle, ThreadHelper threadHelper)
        {
            BacktrackSolver solver = new BacktrackSolver(puzzle.Clone(), puzzle, threadHelper);

            int nrOfSolutions = 0;

            return(solver.backTracking(0, 0, ref nrOfSolutions));
        }
Exemplo n.º 2
0
        public static PuzzleSolver.SolveResult Solve(Puzzle puzzle, Puzzle puzzleForNumbers, ThreadHelper threadHelper)
        {
            var solver = new BacktrackSolver(puzzle, puzzleForNumbers, threadHelper);

            int nrOfSolutions = -1;

            return(solver.backTracking(0, 0, ref nrOfSolutions));
        }
Exemplo n.º 3
0
        private PuzzleSolverDto solvePlayMode(ThreadHelper threadHelper)
        {
            if (Settings.Get.Solver.IsOneOf(Settings.SolverSetting.Smart, Settings.SolverSetting.OnlyLogic))
            {
                this.stopwatch.Start();
                var result = LogicalSolver.Solve(this.puzzle, this.backUpOriginalPuzzle, threadHelper);
                return(this.timeResult(result));
            }

            if (Settings.Get.Solver == Settings.SolverSetting.OnlyBacktracking)
            {
                this.stopwatch.Start();
                var result = BacktrackSolver.Solve(this.puzzle, this.backUpOriginalPuzzle, threadHelper);
                return(this.timeResult(result));
            }

            return(new PuzzleSolverDto(SolveResult.NoSolutionFound));
        }
Exemplo n.º 4
0
        private PuzzleSolverDto solveEditorMode(ThreadHelper threadHelper)
        {
            var solveTimes = new List <long>();

            Puzzle solvePuzzle = this.puzzle.EmptyClone();

            if (Settings.Get.Solver.IsOneOf(Settings.SolverSetting.Smart, Settings.SolverSetting.OnlyLogic))
            {
                this.stopwatch.Start();

                var logicResult = LogicalSolver.Solve(solvePuzzle, this.puzzle, threadHelper);
                this.addTimeResult(solveTimes);

                if (logicResult == SolveResult.UniqueOrLogicSolution)
                {
                    return(new PuzzleSolverDto(logicResult, solveTimes));
                }
            }

            if (Settings.Get.Solver.IsOneOf(Settings.SolverSetting.Smart, Settings.SolverSetting.OnlyBacktracking))
            {
                this.stopwatch.Start();

                var backtrackResult = Settings.Get.Solver == Settings.SolverSetting.Smart
                    ? BacktrackSolver.Solve(solvePuzzle, this.puzzle, threadHelper)
                    : BacktrackSolver.CheckUniqueness(solvePuzzle, threadHelper);

                this.addTimeResult(solveTimes);
                if (backtrackResult == SolveResult.UniqueOrLogicSolution && Settings.Get.Solver == Settings.SolverSetting.Smart)
                {
                    return(new PuzzleSolverDto(SolveResult.NoLogicSolution, solveTimes));
                }

                return(this.adjustNoSolutionResult(backtrackResult, solveTimes));
            }

            return(this.adjustNoSolutionResult(SolveResult.NoSolutionFound, solveTimes));
        }