Exemple #1
0
        internal SudokuSolutionNode Step(SudokuSolutionNode a_node, SudokuSolutionType a_type)
        {
            if (a_node.Board.IsEmpty)
            {
                return(new SudokuSolutionNode(a_node.Board, SudokuSolutionNodeState.Unsolvable));
            }

            if (a_node.StepMode != SudokuSolutionNodeStepMode.StepAllAlgorithms)
            {
                Debug.Assert(!a_node.Nodes.Any());

                a_node.StepMode = SudokuSolutionNodeStepMode.StepSelectedAlgorithm;

                List <SudokuSolution> solution_nodes = SudokuSolutionTypeToSolvingFunction(a_type)(a_node.NextBoard, true);

                solution_nodes = SudokuSolutionNode.Consolidate(solution_nodes.Distinct().ToList());

                foreach (SudokuSolution solution in solution_nodes)
                {
                    if (!a_node.Nodes.Any(n => n.Solution.Equals(solution)))
                    {
                        a_node.AddNode(a_node.NextBoard, SudokuSolutionNodeState.Solution, solution);
                    }
                }
            }

            return(a_node.Nodes.FirstOrDefault(node => node.Solution.Type == a_type));
        }
Exemple #2
0
        public SudokuSolution(SudokuSolutionType a_type, IEnumerable <SudokuNumber> a_removed, IEnumerable <SudokuNumber> a_stayed,
                              IEnumerable <SudokuNumber> a_solved, IEnumerable <IEnumerable <SudokuCell> > a_cellColors)
        {
            m_type = a_type;

            if (a_removed != null)
            {
                m_removed = a_removed.Distinct().OrderBy(num => num.Index).ToList();
            }
            else
            {
                m_removed = new List <SudokuNumber>();
            }

            if (a_stayed != null)
            {
                m_stayed = a_stayed.Distinct().OrderBy(num => num.Index).ToList();
            }
            else
            {
                m_stayed = new List <SudokuNumber>();
            }

            if (a_solved != null)
            {
                m_solved = a_solved.Distinct().OrderBy(num => num.Index).ToList();
            }
            else
            {
                m_solved = new List <SudokuNumber>();
            }

            if (a_cellColors != null)
            {
                m_colorUnits = new SudokuSolutionColorUnits(a_cellColors);
            }
            else
            {
                m_colorUnits = new SudokuSolutionColorUnits();
            }
        }
Exemple #3
0
 private SolvingFunction SudokuSolutionTypeToSolvingFunction(SudokuSolutionType a_type)
 {
     return(m_sudokuSolutionTypeToSolvingFunctionMap[a_type]);
 }
Exemple #4
0
 public static string SudokuSolutionTypeToString(SudokuSolutionType a_type)
 {
     if (a_type == SudokuSolutionType.BoxLineReduction)
     {
         return("Box-line reduction");
     }
     else if (a_type == SudokuSolutionType.HiddenPair)
     {
         return("Hidden pair");
     }
     else if (a_type == SudokuSolutionType.HiddenQuad)
     {
         return("Hidden quad");
     }
     else if (a_type == SudokuSolutionType.HiddenTriple)
     {
         return("Hidden triple");
     }
     else if (a_type == SudokuSolutionType.MarkImpossibles)
     {
         return("Mark impossibles");
     }
     else if (a_type == SudokuSolutionType.MarkSolved)
     {
         return("Mark solved");
     }
     else if (a_type == SudokuSolutionType.NakedPair)
     {
         return("Naked pair");
     }
     else if (a_type == SudokuSolutionType.NakedQuad)
     {
         return("Naked quad");
     }
     else if (a_type == SudokuSolutionType.NakedTriple)
     {
         return("Naked triple");
     }
     else if (a_type == SudokuSolutionType.PointingPair)
     {
         return("Pointing pair");
     }
     else if (a_type == SudokuSolutionType.PointingTriple)
     {
         return("Pointing triple");
     }
     else if (a_type == SudokuSolutionType.SinglesInUnit)
     {
         return("Singles in unit");
     }
     else if (a_type == SudokuSolutionType.SwordFish)
     {
         return("Sword-fish");
     }
     else if (a_type == SudokuSolutionType.JellyFish)
     {
         return("Jelly-fish");
     }
     else if (a_type == SudokuSolutionType.XWing)
     {
         return("X-Wing");
     }
     else if (a_type == SudokuSolutionType.XYZWing)
     {
         return("XYZ-Wing");
     }
     else if (a_type == SudokuSolutionType.WXYZWing)
     {
         return("WXYZ-Wing");
     }
     else if (a_type == SudokuSolutionType.YWing)
     {
         return("Y-Wing");
     }
     else if (a_type == SudokuSolutionType.MultivalueXWing)
     {
         return("Multivalue X-wing");
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemple #5
0
 public SudokuSolutionNode Step(SudokuSolutionType a_type)
 {
     return(s_solver.Step(this, a_type));
 }