public Sudoku(int a, int b) { _size = a * b; Rows = new SudokuRow[_size]; Columns = new SudokuColumn[_size]; Rectangles = new SudokuRectangle[_size]; for (int i = 0; i < _size; i++) { Rows[i] = new SudokuRow(_size); Columns[i] = new SudokuColumn(_size); Rectangles[i] = new SudokuRectangle(_size); } for (int i = 0; i < _size; i++) { for (int j = 0; j < _size; j++) { Field pole = new Field(_size, Rows[i], Columns[j], Rectangles[(i / b) * b + j / a]); Rows[i].Container.Add(pole); Columns[j].Container.Add(pole); Rectangles[(i / b) * b + j / a].Container.Add(pole); } } _width = a; _high = b; }
public void SetValueInRow(SudokuRow row) { for (int i = 0; i < Container.Count; i++) { if (row.Container[i].Value != 0) { Container[i].Value = row.Container[i].Value; } } }
public Field(int size, SudokuRow row, SudokuColumn column, SudokuRectangle rectangle) { this.Row = row; this.Rectangle = rectangle; this.Column = column; this.Value = 0; this.IsValueSet = false; Options = new List <int>(); for (int i = 1; i <= size; i++) { this.Options.Add(i); } }
public Sudoku(Sudoku sudokuCopy, Field fieldToChange, int Value) { _size = sudokuCopy._size; _high = sudokuCopy._high; _width = sudokuCopy._width; Rows = new SudokuRow[_size]; Columns = new SudokuColumn[_size]; Rectangles = new SudokuRectangle[_size]; for (int i = 0; i < _size; i++) { Rows[i] = new SudokuRow(_size); Columns[i] = new SudokuColumn(_size); Rectangles[i] = new SudokuRectangle(_size); } for (int i = 0; i < _size; i++) { for (int j = 0; j < _size; j++) { Field field = new Field(_size, Rows[i], Columns[j], Rectangles[(i / _high) * _high + j / _width]); Rows[i].Container.Add(field); Columns[j].Container.Add(field); Rectangles[(i / _high) * _high + j / _width].Container.Add(field); } } InsertData(sudokuCopy.Rows); for (int i = 0; i < sudokuCopy.Rows.Length; i++) { for (int j = 0; j < sudokuCopy.Rows[i].Container.Count; j++) { if (fieldToChange == sudokuCopy.Rows[i].Container[j]) { Rows[i].Container[j].Value = Value; } } } }