//Read file private void goBtn_Click(object sender, EventArgs e) { readFile(); fileNametb.Hide(); goBtn.Hide(); filename_label.Hide(); printGrid(); init(); Console.WriteLine("GRID"); for (int i = 0; i < 9; ++i) { for (int j = 0; j < 9; ++j) { Console.WriteLine(grid[i, j]); } } Console.WriteLine("END GRID"); MyThread.setGrid(grid); }
void init() { Console.WriteLine("Before start thread"); Thread[] testThread = new Thread[11]; Thread tid1 = new Thread(new ThreadStart(MyThread.Thread1)); Thread tid2 = new Thread(new ThreadStart(MyThread.Thread2)); testThread[0] = tid1; testThread[1] = tid2; for (int i = 2; i < 11; ++i) { Thread tid = new Thread(new ThreadStart(MyThread.Thread3)); testThread[i] = tid; } foreach (Thread myThread in testThread) { update_label.Text = "Starting Thread " + (Array.IndexOf(testThread, myThread) + 1); update_label.Refresh(); Thread.Sleep(1000); myThread.Start(); } foreach (Thread myThread in testThread) { myThread.Join(); update_label.Text = "Threads joined."; update_label.Refresh(); } /* Cross check all problem rows with all problem columns, then use square to determine what numbers are missing and compare with those rows and columns to not make duplicates */ if(MyThread.getProblemRows().Count != 0 && MyThread.getProblemColumns().Count != 0) { label1.Text = "Problem rows: \n" + string.Join(", ", MyThread.getProblemRows()); label1.Refresh(); label2.Text = "Problem columns: \n" + string.Join(", ", MyThread.getProblemColumns()); label2.Refresh(); foreach(int r in MyThread.getProblemRows()) { foreach(int c in MyThread.getProblemColumns()) { Tuple<int, int> tuple = new Tuple<int, int>(r, c); problems.Add(tuple); } } label3.Text = "Fix: \n" + string.Join(", ", problems); label3.Refresh(); //dataGridView1.Rows[rowIndex].Cells[columnIndex].Style.BackColor = Color.Red; //var list = new List<int>(new[] { 1, 2, 4, 7, 9 }); // var result = Enumerable.Range(0, 10).Except(list); var missingSquareList = new List<IEnumerable<int>>(); foreach (Square s in Square.getSquares()) { List<int> list = s.getSquare().Cast<int>().ToList(); var missing = Enumerable.Range(1, 9).Except(list); missingSquareList.Add(missing); //MessageBox.Show(string.Join(", ", result)); } var missingRowList = new List<IEnumerable<int>>(); foreach(int rowM in MyThread.getProblemRows()) { List<int> list2 = new List<int>(); for(int g = 0; g < 9; g++) { list2.Add(grid[rowM, g]); } var missing = Enumerable.Range(1, 9).Except(list2); missingRowList.Add(missing); } var missingColList = new List<IEnumerable<int>>(); foreach(int colM in MyThread.getProblemColumns()) { List<int> list3 = new List<int>(); for(int g = 0; g < 9; g++) { list3.Add(grid[g, colM]); } var missing = Enumerable.Range(1, 9).Except(list3); missingColList.Add(missing); } foreach(Tuple<int,int> t in problems) { } } else { label3.Text = "Valid solution"; label3.Refresh(); } }