/// <summary>
        /// Clone
        /// </summary>
        public SudokuSolver Clone()
        {
            SudokuSolver result = new SudokuSolver(m_Problem);

            result.CoreAssign(this);

            return(result);
        }
Example #2
0
        // Core guess
        private void CoreGuess()
        {
            int min     = int.MaxValue;
            int minLine = 0;
            int minCol  = 0;

            for (int i = 0; i < 9; ++i)
            {
                for (int j = 0; j < 9; ++j)
                {
                    List <int> item = m_Data[i][j];

                    if (item.Count <= 1)
                    {
                        continue;
                    }

                    if (item.Count < min)
                    {
                        min     = item.Count;
                        minLine = i;
                        minCol  = j;
                    }
                }
            }

            SudokuSolver solver = Clone();

            solver.m_Data[minLine][minCol].Remove(m_Data[minLine][minCol][0]);

            SudokuData solution = solver.Solve();

            if (solution.IsValid)
            {
                CoreAssign(solver);

                return;
            }

            int v = m_Data[minLine][minCol][0];

            m_Data[minLine][minCol].Clear();
            m_Data[minLine][minCol].Add(v);
        }
Example #3
0
        // Assign
        private void CoreAssign(SudokuSolver other)
        {
            if (other is null)
            {
                return;
            }

            for (int i = 0; i < 9; ++i)
            {
                for (int j = 0; j < 9; ++j)
                {
                    List <int> source = other.m_Data[i][j];
                    List <int> target = m_Data[i][j];

                    target.Clear();

                    for (int k = 0; k < source.Count; ++k)
                    {
                        target.Add(source[k]);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Solve
        /// </summary>
        public SudokuData Solve()
        {
            SudokuSolver solver = new SudokuSolver(this);

            return(solver.Solve());
        }