protected void init_comp(Suduku_Blank[] original_data) { if (original_data.Length == 81) { origin_suduku_values = new int[81]; for (int i = 0; i < 81; i++) { origin_suduku_values[i] = original_data[i].Value; } for (int i = 0; i < 81; i++) { Ori_Blank[i] = new Suduku_Blank(0, 0); Ori_Blank[i].Restore_Image(original_data[i]); } } for (int i = 0; i < 9; i++) { Row_Group[i] = new Suduku_Group(GroupType.Row, i, Ori_Blank); } for (int i = 0; i < 9; i++) { Column_Group[i] = new Suduku_Group(GroupType.Column, i, Ori_Blank); } for (int i = 0; i < 9; i++) { Mix_Group[i] = new Suduku_Group(GroupType.Mix, i, Ori_Blank); } }
protected void init_comp(string filepath) { origin_suduku_values = Suduku_DataReader.GetDataFromFile(filepath); if (origin_suduku_values.Length != 81) { this.switch_enable_status(); } if (this.Enabled == true) { for (int i = 0; i < 81; i++) { Ori_Blank[i] = new Suduku_Blank(i, origin_suduku_values[i]); } } for (int i = 0; i < 9; i++) { Row_Group[i] = new Suduku_Group(GroupType.Row, i, Ori_Blank); } for (int i = 0; i < 9; i++) { Column_Group[i] = new Suduku_Group(GroupType.Column, i, Ori_Blank); } for (int i = 0; i < 9; i++) { Mix_Group[i] = new Suduku_Group(GroupType.Mix, i, Ori_Blank); } }
public void Restore_Image(Suduku_Blank ori) { this.val = ori.val; this.ival.Clear(); for (int i = 0; i < ori.ival.Count; i++) { this.ival.Add(ori.ival[i]); } this.Index = ori.Index; }
static public int Mix_index(Suduku_Blank sb) { return(Column(sb) % 3 + Row(sb) % 3 * 3); }
static public int Column_index(Suduku_Blank sb) { return(sb.Index / 9); }
static public int Row_index(Suduku_Blank sb) { return(sb.Index % 9); }
static public int MixGroup(Suduku_Blank sb) { return(Row(sb) / 3 * 3 + Column(sb) / 3); }
static public int Column(Suduku_Blank sb) { return(sb.Index % 9); }
static public int Row(Suduku_Blank sb) { return(sb.Index / 9); }
//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); }