コード例 #1
0
        public static Panel[] FindAnswer(Panel pl)
        {
            Panel        p  = (Panel)pl.Clone();
            List <Panel> ls = new List <Panel>();

            for (int y = 0; y < 9; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    if (pl[x, y].Number == SudoNum.Unknown)
                    {
                        foreach (SudoNum item in pl[x, y].CandidateNumber.GetNumbers())
                        {
                            if (CancelRequest)
                            {
                                return(ls.ToArray());
                            }
                            p[x, y].Number = item;
                            FullExpel(ref p);
                            if (p.IsFull())
                            {
                                ls.Add(p);
                            }
                            foreach (Panel ele in FindAnswer(p))
                            {
                                ls.Add(ele);
                            }
                        }
                        return(ls.ToArray());
                    }
                }
            }
            return(ls.ToArray());
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: Leo1003/SudokuSolver
        private void Calc()
        {
            string ds = GetOneLine();

            data = new SudoCalc.Panel(ds);
            Calculator.ExpelCandidate(ref data);
            //Calculator.Filler(ref data);
            while (Calculator.Filler(ref data))
            {
                Calculator.ExpelCandidate(ref data);
            }

            if (!data.IsFull())
            {
                SudoCalc.Panel[] debug = Calculator.FindAnswer(data);
                if (Calculator.CancelRequest)
                {
                    Calculator.CancelRequest = false;
                    return;
                }
                //data = Calculator.FindAnswer(data)[0];//TODO:FixMultiAns
                if (debug.Length == 0)
                {
                    MessageBox.Show("此題無解", "計算結果", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                if (debug.Length > 1)
                {
                    MessageBox.Show("此題多解,將只會顯示第一解。", "計算結果", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                data = debug[0];
            }
        }
コード例 #3
0
        public static double O(Panel pl)
        {
            double ans = 1d;

            if (pl.IsFull())
            {
                return(0d);
            }
            foreach (Block item in pl)
            {
                ans *= item.CandidateNumber.Count;
            }
            return(ans);
        }