public void CreateGrid_16x16(bool generate = true) { if (generate) sudoku = SudokuDebug.GetStandart16((new Debug("16x16")).matrix); currenType = "16x16"; mainWindow.Height = 800 + 2 * 10; mainWindow.Width = 825 + 2 * 10; sudokuGrid.Children.Clear(); sudokuGrid.Rows = 16; sudokuGrid.Columns = 16; if (AdmissibleValues.Count != 0) AdmissibleValues.Clear(); for (int i = 0; i < 16; i++) AdmissibleValues.Add(i); foreach (TextBox tb in textBox) sudokuGrid.Children.Remove(tb); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { textBox.Add(TextBox_16_16Add(i, j)); } } UpdateRightness(); }
public void CreateGrid_9x9(bool generate = true) { if (generate) sudoku = SudokuDebug.GetStandart9((new Debug("9x9")).matrix); currenType = "9x9"; mainWindow.Height = 720 + 2 * 10; mainWindow.Width = 745 + 2 * 10; sudokuGrid.Children.Clear(); sudokuGrid.Columns = 9; sudokuGrid.Rows = 9; if (AdmissibleValues.Count != 0) AdmissibleValues.Clear(); for (int i = 1; i < 10; i++) AdmissibleValues.Add(i); foreach (TextBox tb in textBox) sudokuGrid.Children.Remove(tb); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { textBox.Add(TextBox_9_9Add(i, j)); } } UpdateRightness(); }
private static void Generate_External(Sudoku sudoku) { sudoku.generator_external.Run(null, new object[] { sudoku }); }
public void Open_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "*"; dlg.DefaultExt = ".txt"; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; sudoku = Interface.LoadSudoku(filename); } if (sudoku.Size.X == 9) CreateGrid_9x9(false); else CreateGrid_16x16(false); }
public static Sudoku GetStandart9(int[,] numbs) { Number.Position[][] block = new Number.Position[9 + 9 + 9][]; ///Добавление блоков (горизонтальные линии); for (int i = 0; i < 9; i++) { block[i] = new Number.Position[9]; for (int j = 0; j < 9; j++) { block[i][j] = new Number.Position(i, j); } } ///Добавление блоков (вертикальные линии); for (int i = 0; i < 9; i++) { block[9 + i] = new Number.Position[9]; for (int j = 0; j < 9; j++) { block[9 + i][j] = new Number.Position(j, i); } } ///Добавление блоков 3x3; int blockIndex = 9 + 9; for (int i = 0; i < 9; i += 3) { for (int j = 0; j < 9; j += 3, blockIndex++) { block[blockIndex] = new Number.Position[9]; int cellIndex = 0; for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++, cellIndex++) { block[blockIndex][cellIndex] = new Number.Position(i + k, j + l); } } } } int[,] value = new int[9, 9]; ////////////// for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { value[i, j] = 0; } } //////////////// Number.NumberType[,] mask = new Number.NumberType[9, 9]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { mask[i, j] = Number.NumberType.Empty; } } Sudoku sudoku = new Sudoku(new Number.Position(9, 9), value, mask, block, 9); Interface.GenerateSudoku(sudoku); return sudoku; }
public object Clone() { List<Number> numb = Method.Clone(this.Number).ToList(); List<Block> block = Method.Clone(this.Block).ToList(); // NNBB; fix; on change order in list<block>, may be incorrect coping Sudoku result = new Sudoku( blockType: this.BlockType, block: block, cell: numb, maxValue: this.MaxValue ); result.Block.ForEach(x => x.SetParent(result)); for (int i = 0; i < this.Block.Count; i++) { List<Position> blockCell = this.Block[i].Child.ConvertAll<Position> (x => x.Coordinate); block[i].AddChildren(blockCell); } return result; }
/// <summary> /// Изменяет число в ячейке судоку /// Возвращает успех операции /// </summary> /// <param name="sudoku">судоку</param> /// <param name="number_position">позиция ячейки</param> /// <param name="value">новое значение</param> /// <returns></returns> public static bool ChangeNumber(Sudoku sudoku, Position number_position, int value) { return(sudoku.SetNumber(number_position, value)); }
public static Sudoku GetStandart16(int[,] numbs) { Number.Position[][] block = new Number.Position[16 + 16 + 16][]; ///Добавление блоков (горизонтальные линии); for (int i = 0; i < 16; i++) { block[i] = new Number.Position[16]; for (int j = 0; j < 16; j++) { block[i][j] = new Number.Position(i, j); } } ///Добавление блоков (вертикальные линии); for (int i = 0; i < 16; i++) { block[16 + i] = new Number.Position[16]; for (int j = 0; j < 16; j++) { block[16 + i][j] = new Number.Position(j, i); } } ///Добавление блоков 4x4; int blockIndex = 16 + 16; for (int i = 0; i < 16; i += 4) { for (int j = 0; j < 16; j += 4, blockIndex++) { block[blockIndex] = new Number.Position[16]; int cellIndex = 0; for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++, cellIndex++) { block[blockIndex][cellIndex] = new Number.Position(i + k, j + l); } } } } int[,] value = new int[16, 16]; ////////////// Random rand = new Random(); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { value[i, j] = rand.Next(16); } } //////////////// Number.NumberType[,] mask = new Number.NumberType[16, 16]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { mask[i, j] = Number.NumberType.Empty; } } Sudoku sudoku = new Sudoku(new Number.Position(16, 16), value, mask, block, 16); ///Interface.GenerateSudoku(sudoku); return sudoku; }
/// <summary> /// Сохраняет данное судоку в файл /// </summary> /// <param name="filename">путь к файлу</param> /// <param name="sudoku">ссылка на судоку</param> public static void SaveSudoku(string filename, Sudoku sudoku) { Alist.Xml.Transform.ElementToFile(sudoku.UnloadXml(), filename); }
/// <summary> /// Генерирует судоку по его шаблону /// </summary> /// <param name="sudoku"></param> /// <param name="attemptsNumber"></param> /// <param name="fillness"></param> public static void GenerateSudoku(Sudoku sudoku, int attemptsNumber = Generator.AttemptsCountDefault, double fillness = Generator.FillnessDefault) { Generator generator = new Generator(sudoku, attemptsNumber, fillness); generator.Generate(); }
/// <summary> /// Возвращает ячейку судоку по заданной позиции /// </summary> /// <param name="sudoku">судоку</param> /// <param name="position">позиция ячейки</param> /// <returns></returns> public static Number GetNumber(Sudoku sudoku, Position position) { return(sudoku.GetNumber(position)); }
private static void Generate_External(Sudoku sudoku) { sudoku.generator_external.Run(null, new object[] { sudoku }); }
public Block(Sudoku sudoku) : this(sudoku, new Adress(Constant.BlockTypeIdDefault)) { }
public Block(Sudoku sudoku, Adress typeId) : this(sudoku, typeId, null) { }
public Block(Sudoku sudoku, BlockType type) : this(sudoku, type, new List <Number> { }) { }