Beispiel #1
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));
        }
Beispiel #2
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));
        }
Beispiel #3
0
        public static PuzzleSolver.SolveResult Solve(Puzzle puzzle, Puzzle puzzleForNumbers, ThreadHelper threadHelper)
        {
            var solver = new LogicalSolver(puzzle, puzzleForNumbers, threadHelper);

            return(solver.solveLogically(puzzle, puzzleForNumbers));
        }