Example #1
0
        public SolveResult DoLogicalSolve(SudokuGrid grid, HintSelections hs)
        {
            if (hs == null)
            {
                return(DoBacktrackingSolve(grid));
            }

            while (true)
            {
                if (Solved)
                {
                    return(SolveResult.SingleSolution);
                }
                Hint hint = SingleHint(hs);
                if (hint == null)
                {
                    return(SolveResult.TooDifficult);
                }
                SolveResult result = hint.Apply(grid);
                if (result != SolveResult.Ongoing)
                {
                    return(result);
                }
            }
        }
Example #2
0
        public void ApplyUpdate()
        {
            Name?.Apply(BoundObject.Name);
            BoundObject.UpdateIdIfAllowed(ID);
            Hint?.Apply(BoundObject.Hint);

            BoundObject.WithoutAttributes();
            foreach (var attribute in Attributes)
            {
                if (attribute.IsOn && attribute.Value != null)
                {
                    BoundObject.WithAttribute(attribute.Value);
                }
            }
        }
Example #3
0
        public SolveResult DoLogicalProof(SudokuGrid grid, HintSelections hs, TextWriter log)
        {
            while (true)
            {
                if (Solved)
                {
                    return(SolveResult.SingleSolution);
                }
                Hint hint = SingleHint(hs);
                if (hint == null)
                {
                    return(SolveResult.TooDifficult);
                }

                if (hint.IsComplex)
                {
                    int sc     = tsc;
                    var action = hint.Illustration;
                    if (action == Hint.Actions.Discard)
                    {
                        log.WriteLine("Suppose we do not " + hint.Candidate);
                        DiscardCandidate(hint.Candidate);
                    }
                    if (action == Hint.Actions.Select)
                    {
                        log.WriteLine("Suppose we " + hint.Candidate);
                        SelectCandidate(hint.Candidate);
                    }

                    int solns = 0;
                    while (true)
                    {
                        if (Solved)
                        {
                            break;
                        }
                        Requirement r = EasiestRequirement;
                        solns = r.s;
                        if (solns == 0)
                        {
                            log.WriteLine(" " + r); // No way to...
                        }
                        if (solns != 1)
                        {
                            break;
                        }
                        Candidate c = r.UnselectedCandidates[0];
                        //log.WriteLine(" then we must " + c);
                        log.WriteLine(" then " + c + " because " + r);
                        SelectCandidate(c);
                    }

                    while (tsc > sc)
                    {
                        UnselectCandidate();
                    }
                    if (action == Hint.Actions.Discard)
                    {
                        UndiscardCandidate(hint.Candidate);
                    }
                }

                log.WriteLine(hint.ToString());

                SolveResult result = hint.Apply(grid);
                if (result != SolveResult.Ongoing)
                {
                    return(result);
                }
            }
        }