// Generate private void btnGenerate_Click(object sender, System.EventArgs e) { Sudoku s = new Sudoku(); byte[,] d = GetData(); s.Data = d; Cursor oldCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; tbHistory.AppendText("-------------------------------\r\n"); var result = s.Generate((int)numSpots.Value); if (result.Item2) { tbHistory.AppendText(String.Format("Sudoku generated succesfully after {0} tries\r\n", result.Item1)); tbHistory.AppendText("Sudoku with " + numSpots.Value + " spots\r\n"); d = s.Data; SetData(d); } else { tbHistory.AppendText(String.Format("Sudoku not found after {0} tries.\r\n Press generate to try again.\r\n", result.Item1)); } Cursor.Current = oldCursor; }
public static string Generate() { SudokuModel.Sudoku sudoku = new SudokuModel.Sudoku(); sudoku.Data = new byte[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; while (!(sudoku.Generate(30).second&& sudoku.Solve())) { } char[] rawData = new char[81]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { rawData[i * 9 + j] = sudoku.Data[i, j].ToString()[0]; } } return(new string(rawData)); }
public static void Main() { while (true) { Sudoku s = new Sudoku(); s.Data = new byte[, ] { { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; s.Generate(30); if (s.Solve()) { Console.Write("\""); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { Console.Write(s.Data[i, j]); } } Console.WriteLine("\","); } } }
// Generate private void btnGenerate_Click(object sender, System.EventArgs e) { Sudoku s = new Sudoku(); byte[,] d = GetData(); s.Data = d; Cursor oldCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; tbHistory.AppendText("-------------------------------\r\n"); var result = s.Generate((int)numSpots.Value); if(result.Item2) { tbHistory.AppendText(String.Format("Sudoku generated succesfully after {0} tries\r\n", result.Item1)); tbHistory.AppendText("Sudoku with " + numSpots.Value + " spots\r\n"); d = s.Data; SetData(d); } else { tbHistory.AppendText(String.Format("Sudoku not found after {0} tries.\r\n Press generate to try again.\r\n", result.Item1)); } Cursor.Current = oldCursor; }