예제 #1
0
        //IMAGE函数
        public Suduku_Model Make_Image()
        {
            Suduku_Model image = new Suduku_Model(this.Blanks);

            for (int i = 0; i < 9; i++)
            {
                image.Row_Group[i].Resutore_Image(this.Row_Group[i]);
                image.Column_Group[i].Resutore_Image(this.Column_Group[i]);
                image.Mix_Group[i].Resutore_Image(this.Mix_Group[i]);
            }
            return(image);
        }
예제 #2
0
 public void Restore_Image(Suduku_Model image)
 {
     for (int i = 0; i < 81; i++)
     {
         this.Blanks[i].Restore_Image(image.Blanks[i]);
     }
     for (int i = 0; i < 9; i++)
     {
         this.Row_Group[i].Resutore_Image(image.Row_Group[i]);
         this.Column_Group[i].Resutore_Image(image.Column_Group[i]);
         this.Mix_Group[i].Resutore_Image(image.Mix_Group[i]);
     }
 }
예제 #3
0
 private void SetTextBoxValue(TextBox[] tb, Suduku_Model su)
 {
     for (int i = 0; i < 81; i++)
     {
         if (su.Blanks[i].Value != 0)
         {
             tb[i].FontSize = 20;
             tb[i].Text     = su.Blanks[i].Value.ToString();
         }
         else
         {
             tb[i].FontSize = 10;
             string txt = "";
             for (int j = 0; j < su.Blanks[i].iValues.Count; j++)
             {
                 txt += su.Blanks[i].iValues[j];
             }
             tb[i].Text = txt;
         }
     }
 }
예제 #4
0
        //Guess函数
        private void guess_suduku()
        {
            List <Suduku_Model> g_wh         = new List <Suduku_Model>();
            List <int>          g_ih         = new List <int>();
            List <Suduku_Blank> b_ch         = new List <Suduku_Blank>();
            Suduku_Model        latest_image = new Suduku_Model();
            Suduku_Blank        c_blank      = new Suduku_Blank(0, 0);
            int c_ivalue_index = 0;

            do
            {
                if (!isfinish)
                {
                    if (isNotWrong)
                    {
                        g_wh.Add(this.Make_Image());
                        g_ih.Add(0);
                        b_ch.Add(find_cursor());
                        latest_image   = g_wh[g_wh.Count - 1];
                        c_blank        = b_ch[b_ch.Count - 1];
                        c_ivalue_index = g_ih[g_ih.Count - 1];

                        c_blank.Value = c_blank.iValues[c_ivalue_index];
                        this.solve_suduku();
                    }
                    else
                    {
                        this.Restore_Image(latest_image);
                        g_ih[g_ih.Count - 1]++;
                        while (g_ih[g_ih.Count - 1] > b_ch[b_ch.Count - 1].iValues.Count - 1)
                        {
                            g_wh.RemoveAt(g_wh.Count - 1);
                            this.Restore_Image(g_wh[g_wh.Count - 1]);
                            g_ih.RemoveAt(g_ih.Count - 1);
                            b_ch.RemoveAt(b_ch.Count - 1);
                            g_ih[g_ih.Count - 1]++;
                        }
                        latest_image   = g_wh[g_wh.Count - 1];
                        c_blank        = b_ch[b_ch.Count - 1];
                        c_ivalue_index = g_ih[g_ih.Count - 1];

                        c_blank.Value = c_blank.iValues[c_ivalue_index];
                        this.solve_suduku();
                    }
                }
                else
                {
                    if (!isNotWrong)
                    {
                        this.Restore_Image(latest_image);
                        g_ih[g_ih.Count - 1]++;
                        while (g_ih[g_ih.Count - 1] > b_ch[b_ch.Count - 1].iValues.Count - 1)
                        {
                            g_wh.RemoveAt(g_wh.Count - 1);
                            this.Restore_Image(g_wh[g_wh.Count - 1]);
                            g_ih.RemoveAt(g_ih.Count - 1);
                            b_ch.RemoveAt(b_ch.Count - 1);
                            g_ih[g_ih.Count - 1]++;
                        }
                        latest_image   = g_wh[g_wh.Count - 1];
                        c_blank        = b_ch[b_ch.Count - 1];
                        c_ivalue_index = g_ih[g_ih.Count - 1];

                        c_blank.Value = c_blank.iValues[c_ivalue_index];
                        this.solve_suduku();
                    }
                }
            } while (!isSolved);
        }