private void EnterPuzzle() { int[] oneDimensionalArray = new int[81]; for (int i = 1; i <= 81; i++) { if (this.Controls.ContainsKey("tb" + i.ToString())) { TextBox tb = this.Controls["tb" + i.ToString()] as TextBox; int result; if (tb.Text != "" && Int32.TryParse(tb.Text, out result)) { oneDimensionalArray[i - 1] = result; } else { oneDimensionalArray[i - 1] = 0; } } } int[,] twoDimensionalArray = new int[9, 9]; for (int x = 0; x < 9; x++) { for (int y = 0; y < 9; y++) { twoDimensionalArray[x, y] = oneDimensionalArray[9 * x + y]; } } sudokuGrid = new SudokuGrid(twoDimensionalArray); fc = new FourCube(sudokuGrid); }
private void ClearSudokuGrid() { for (int i = 1; i <= 81; i++) { if (this.Controls.ContainsKey("tb" + i.ToString())) { TextBox tb = this.Controls["tb" + i.ToString()] as TextBox; tb.Text = ""; } } nrOfSteps = 0; sudokuGrid = null; fc = null; foreach (var series in chartDifference.Series) { series.Points.Clear(); } foreach (var series in chartConfidence.Series) { series.Points.Clear(); } lbDigitSelection.Items.Clear(); lbRowSelection.Items.Clear(); lbColumnSelection.Items.Clear(); lbBlockSelection.Items.Clear(); }
public FourCube(SudokuGrid sudokuGrid) { this.originalSudokuGrid = sudokuGrid; cubeCells = new CubeCell[4, 9, 9, 9]; for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { for (int azimuth = 0; azimuth < 9; azimuth++) { for (int cube = 0; cube < 4; cube++) { cubeCells[cube, row, col, azimuth] = new CubeCell(); } } } } for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { if (originalSudokuGrid.GetCells()[row, col] != 0) { int azimuthalIndex = originalSudokuGrid.GetCells()[row, col] - 1; for (int cube = 0; cube < 4; cube++) { cubeCells[cube, row, col, azimuthalIndex] = new CubeCell(1, true); for (int i = 0; i < 9; i++) { int baseRowIndex = (row / 3) * 3; int offsetRow = i / 3; int baseColIndex = (col / 3) * 3; int offsetCol = i % 3; //block if (baseRowIndex + offsetRow != row && baseColIndex + offsetCol != col) { cubeCells[cube, baseRowIndex + offsetRow, baseColIndex + offsetCol, azimuthalIndex] = new CubeCell(0, true); } //row if (i != row) { cubeCells[cube, i, col, azimuthalIndex] = new CubeCell(0, true); } //col if (i != col) { cubeCells[cube, row, i, azimuthalIndex] = new CubeCell(0, true); } //azimuth if (i != azimuthalIndex) { cubeCells[cube, row, col, i] = new CubeCell(0, true); } } } } else { for (int cube = 0; cube < 4; cube++) { for (int azimuthalIndex = 0; azimuthalIndex < 9; azimuthalIndex++) { //cubeCells[cube, row, col, azimuthalIndex].GetIsClue() != true if (cubeCells[cube, row, col, azimuthalIndex].GetIsClue() != true) { cubeCells[cube, row, col, azimuthalIndex] = new CubeCell(); } } } } } } }