private void UpdateCurrentChar() { SuperChar selected = problems[selectedCharIdx]; tbCurrentName.Text = selected.Name; for (int t = 0; t < selected.descriptors.Count; ++t) { TagStroke descriptor = selected.descriptors[t]; for (int i = 0; i < descriptor.positions.Count; ++i) { for (int j = 0; j < descriptor.positions[i].Length; ++j) { Point pt = descriptor.positions[i][j]; int sceneIdx = (int)pt.Y * sceneCols + (int)pt.X; scene[sceneIdx].SelfType = GridPoint.GridPointType.Assigned; scene[sceneIdx].AddVersePos(selectedCharIdx, t, i, j); } } } table1 = new DataTable(); table2 = new DataTable(); PrepareTables(table1, table2); dgStrokes.ItemsSource = table1.DefaultView; dgAnchor.ItemsSource = table2.DefaultView; }
public static void SaveProblemBank(List <SuperChar> bank, string fnDB) { if (File.Exists(fnDB)) { File.Delete(fnDB); } using (StreamWriter sw = new StreamWriter(fnDB, false)) { string line = "SuperChars:" + bank.Count.ToString(); sw.WriteLine(line); for (int k = 0; k < bank.Count; ++k) { SuperChar sc = bank[k]; line = "SuperChar:" + k.ToString() + ",Name:" + sc.Name; sw.WriteLine(line); int nbStrokes = sc.descriptors.Count; line = "Strokes:" + nbStrokes.ToString(); sw.WriteLine(line); for (int t = 0; t < nbStrokes; ++t) { TagStroke descriptor = sc.descriptors[t]; line = "Stroke:" + t.ToString(); sw.WriteLine(line); int nV = descriptor.nbVerses, nA = descriptor.nbAnchors; line = "Verses:" + nV.ToString(); sw.WriteLine(line); for (int v = 0; v < nV; ++v) { Point[] points = descriptor.positions[v]; int len = descriptor.LenVerses[v]; line = v.ToString() + ":" + len.ToString() + " "; for (int l = 0; l < len; ++l) { line += points[l].ToString() + " "; } sw.WriteLine(line); } line = "Anchors:" + nA.ToString(); sw.WriteLine(line); for (int a = 0; a < nA; ++a) { line = a.ToString() + ":" + descriptor.Anchors[a][0].ToString() + "," + descriptor.Anchors[a][1].ToString() + "," + descriptor.Anchors[a][2].ToString() + "," + descriptor.Anchors[a][3].ToString(); sw.WriteLine(line); } } } } }
private void SolveCollate(object sender, DoWorkEventArgs e) { SolverParam param = e.Argument as SolverParam; backend.ClearUsedIndices(); if (IsDoingOther) { SuperChar sc = problems[selectedCharIdx]; if (param.Reuse) { backend.ClearUsedIndices(); } for (int nd = 0; nd < sc.descriptors.Count; ++nd) { TagStroke desc = sc.descriptors[nd]; backend.ClearPuzzleData(); backend.MakePuzzleData(desc); uint step = backend.Solve(MainLogic.Solver.BasicSearch, param); sc.strokes.Add(backend.GetResult()); if (backend.SearchSuccess()) { ShowResultOnScene(selectedCharIdx, nd); } Dispatcher.Invoke(new Action <int, int, uint>(PrintSteps), new object[] { selectedCharIdx, nd, step }); } } else { for (int tsc = 0; tsc < 4; ++tsc) { SuperChar sc = problems[tsc]; sc.strokes = new List <Stroke>(); for (int nd = 0; nd < sc.descriptors.Count; ++nd) { if (param.Reuse) { backend.ClearUsedIndices(); } TagStroke desc = sc.descriptors[nd]; backend.ClearPuzzleData(); backend.MakePuzzleData(desc); uint step = backend.Solve(MainLogic.Solver.BasicSearch, param); sc.strokes.Add(backend.GetResult()); if (backend.SearchSuccess()) { ShowResultOnScene(tsc, nd); } Dispatcher.Invoke(new Action <int, int, uint>(PrintSteps), new object[] { tsc, nd, step }); } } } }
private void ShowOtherSuperChar() { ResetScene(); SuperChar selected = problems[selectedCharIdx]; for (int t = 0; t < selected.descriptors.Count; ++t) { TagStroke descriptor = selected.descriptors[t]; for (int i = 0; i < descriptor.positions.Count; ++i) { for (int j = 0; j < descriptor.positions[i].Length; ++j) { Point pt = descriptor.positions[i][j]; int sceneIdx = (int)pt.Y * sceneCols + (int)pt.X; scene[sceneIdx].SelfType = GridPoint.GridPointType.Assigned; scene[sceneIdx].AddVersePos(selectedCharIdx, t, i, j); } } } lblInfo.Content = ""; tblStepInfo.Text = ""; }
private void SetBenchmarkScene() { for (int tsc = 0; tsc < 4; ++tsc) { SuperChar sc = problems[tsc]; for (int t = 0; t < sc.descriptors.Count; ++t) { TagStroke descriptor = sc.descriptors[t]; for (int k = 0; k < descriptor.positions.Count; ++k) { Point[] applicants = descriptor.positions[k]; for (int l = 0; l < applicants.Length; ++l) { Point p = applicants[l]; int idx = (int)p.Y * sceneCols + (int)p.X; scene[idx].SelfType = GridPoint.GridPointType.Assigned; scene[idx].AddVersePos(tsc, t, k, l); } } } } lblInfo.Content = ""; tblStepInfo.Text = ""; }
public static void LoadProblemBank(List <SuperChar> bank, string fnDB) { if (!File.Exists(fnDB)) { throw new FileNotFoundException(); } using (StreamReader sr = new StreamReader(fnDB, Encoding.UTF8)) { int nbSuperChars = 0; string[] res = null; string line = sr.ReadLine(); if (line.StartsWith("SuperChars:")) { res = line.Split(new char[] { ':' }); nbSuperChars = Convert.ToInt32(res[1]); } bank.Capacity = nbSuperChars; for (int k = 0; k < nbSuperChars; ++k) { SuperChar sc = new SuperChar { descriptors = new List <TagStroke>() }; line = sr.ReadLine(); res = line.Split(new char[] { ':', ',' }); if (res[0] == "SuperChar" && res[2] == "Name") { if (k != Convert.ToInt32(res[1])) { throw new InvalidDataException(); } sc.Name = res[3]; } line = sr.ReadLine(); res = line.Split(new char[] { ':' }); int nStroke = 0; if (res[0] == "Strokes") { nStroke = Convert.ToInt32(res[1]); } for (int t = 0; t < nStroke; ++t) { TagStroke descriptor = new TagStroke { positions = new List <Point[]>() }; line = sr.ReadLine(); res = line.Split(new char[] { ':' }); if (res[0] != "Stroke" || Convert.ToInt32(res[1]) != t) { throw new InvalidDataException(); } line = sr.ReadLine(); res = line.Split(new char[] { ':', ',' }); int nV = 0, nA = 0; if (res[0] == "Verses") { nV = Convert.ToInt32(res[1]); descriptor.nbVerses = nV; for (int v = 0; v < nV; ++v) { line = sr.ReadLine(); res = line.Split(new char[] { ':', '_', ' ' }); if (v != Convert.ToInt32(res[0])) { throw new InvalidDataException(); } int len = Convert.ToInt32(res[1]); descriptor.LenVerses.Add(len); Point[] points = new Point[len]; for (int j = 0; j < len; ++j) { points[j] = Point.Parse(res[j + 2]); } descriptor.positions.Add(points); } } line = sr.ReadLine(); res = line.Split(new char[] { ':', ',' }); if (res[0] == "Anchors") { nA = Convert.ToInt32(res[1]); descriptor.nbAnchors = nA; descriptor.Anchors = new List <int[]>(); for (int a = 0; a < nA; ++a) { line = sr.ReadLine(); res = line.Split(new char[] { ':' }); if (a != Convert.ToInt32(res[0])) { throw new InvalidDataException(); } res = res[1].Split(new char[] { ',' }); int[] aa = new int[4]; for (int l = 0; l < 4; ++l) { aa[l] = Convert.ToInt32(res[l]); } descriptor.Anchors.Add(aa); } } sc.descriptors.Add(descriptor); } bank.Add(sc); } } }