public void checkColumns() { PossibleNums[] col; int knownValue; for (int i = 0; i < possibles.GetLength(0); i++) { col = new PossibleNums[possibles.GetLength(0)]; for (int j = 0; j < possibles.GetLength(0); j++) { col[j] = possibles[j, i]; } //Now loop through the column for (int j = 0; j < col.Length; j++) { if (col[j].getValue() != -1) { knownValue = col[j].getValue(); for (int k = 0; k < col.Length; k++) { if (k != j) { possibles[k, i].setImpossible(knownValue); } } } } } }
public void checkRows() { PossibleNums[] row; int knownValue; for (int i = 0; i < possibles.GetLength(0); i++) { row = new PossibleNums[possibles.GetLength(1)]; for (int j = 0; j < possibles.GetLength(1); j++) { row[j] = possibles[i, j]; } //Now loop through the row for (int j = 0; j < row.Length; j++) { if (row[j].getValue() != -1) { knownValue = row[j].getValue(); for (int k = 0; k < row.Length; k++) { if (k != j) { possibles[i, k].setImpossible(knownValue); } } } } } }
public SudokuGrid() { grid = new TextBox[9, 9]; isSolved = false; possibles = new PossibleNums[9, 9]; //Fill the possibles array because C# is dumb =( for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { possibles[i, j] = new PossibleNums(); } } }
public void checkSquares() { PossibleNums[,] square; int knownValue; for (int i = 0; i < 9; i++) { square = new PossibleNums[3, 3]; for (int j = 0; j < square.GetLength(0); j++) { for (int k = 0; k < square.GetLength(1); k++) { square[j, k] = possibles[(i / 3) * 3 + j, (i % 3) * 3 + k]; } } //Now loop through the square for (int j = 0; j < square.GetLength(0); j++) { for (int k = 0; k < square.GetLength(1); k++) { if (square[j, k].getValue() != -1) { knownValue = square[j, k].getValue(); for (int l = 0; l < square.GetLength(0); l++) { for (int m = 0; m < square.GetLength(1); m++) { if (possibles[(i / 3) * 3 + l, (i % 3) * 3 + m].getValue() == -1) { possibles[(i / 3) * 3 + l, (i % 3) * 3 + m].setImpossible(knownValue); } } } } } } } }
public void checkOnlyPossible() { int onlyPossible; PossibleNums[] row; PossibleNums[] col; PossibleNums[,] square; for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { if (possibles[i, j].getValue() == -1) { //Get the row row = new PossibleNums[possibles.GetLength(1)]; for (int k = 0; k < row.Length; k++) { row[k] = possibles[i, k]; } //Check the row for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check row //Loop through the rest of the row to check if it's possible somewhere else for (int l = 0; l < possibles.GetLength(0) && onlyPossible != -1; l++) { if (l != j) { if (row[l].isPossible(onlyPossible)) { onlyPossible = -1; } } } if (onlyPossible == k) { setValue(i, j, onlyPossible); } } } } } } for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { //Get the column col = new PossibleNums[possibles.GetLength(0)]; for (int k = 0; k < col.Length; k++) { col[k] = possibles[k, j]; } for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check column //Loop through the rest of the col to check if it's possible somewhere else for (int l = 0; l < possibles.GetLength(0) && onlyPossible != -1; l++) { if (l != i) { if (col[l].isPossible(onlyPossible)) { onlyPossible = -1; } } } if (onlyPossible == k) { setValue(i, j, onlyPossible); } } } } } for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { //Get the square square = new PossibleNums[3, 3]; for (int k = 0; k < square.GetLength(0); k++) { for (int l = 0; l < square.GetLength(1); l++) { square[k, l] = possibles[(i / 3) * 3 + k, (j / 3) * 3 + l]; } } for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check square //Loop through the rest of the square to check if it's possible somewhere else for (int l = 0; l < square.GetLength(0) && onlyPossible != -1; l++) { for (int m = 0; m < square.GetLength(1) && onlyPossible != -1; m++) { if (l != i && m != j) { if (square[l, m].isPossible(onlyPossible)) { onlyPossible = -1; } } } } if (onlyPossible == k) { setValue(i, j, onlyPossible); } } } } } }
public void checkSquares() { PossibleNums[,] square; int knownValue; for (int i = 0; i < 9; i++) { square = new PossibleNums[3, 3]; for (int j = 0; j < square.GetLength(0); j++) { for (int k = 0; k < square.GetLength(1); k++) { square[j, k] = possibles[(i / 3) * 3 + j, (i % 3) * 3 + k]; } } //Now loop through the square for (int j = 0; j < square.GetLength(0); j++) { for (int k = 0; k < square.GetLength(1); k++) { if (square[j, k].getValue() != -1) { knownValue = square[j, k].getValue(); for (int l = 0; l < square.GetLength(0); l++) { for (int m = 0; m < square.GetLength(1); m++) { if (possibles[(i / 3) * 3 + l, (i % 3) * 3 + m].getValue() == -1) possibles[(i / 3) * 3 + l, (i % 3) * 3 + m].setImpossible(knownValue); } } } } } } }
public void checkOnlyPossible() { int onlyPossible; PossibleNums[] row; PossibleNums[] col; PossibleNums[,] square; for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { if (possibles[i, j].getValue() == -1) { //Get the row row = new PossibleNums[possibles.GetLength(1)]; for (int k = 0; k < row.Length; k++) { row[k] = possibles[i, k]; } //Check the row for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check row //Loop through the rest of the row to check if it's possible somewhere else for (int l = 0; l < possibles.GetLength(0) && onlyPossible != -1; l++) { if (l != j) { if (row[l].isPossible(onlyPossible)) { onlyPossible = -1; } } } if (onlyPossible == k) { setValue(i,j,onlyPossible); } } } } } } for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { //Get the column col = new PossibleNums[possibles.GetLength(0)]; for (int k = 0; k < col.Length; k++) { col[k] = possibles[k, j]; } for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check column //Loop through the rest of the col to check if it's possible somewhere else for (int l = 0; l < possibles.GetLength(0) && onlyPossible != -1; l++) { if (l != i) { if (col[l].isPossible(onlyPossible)) { onlyPossible = -1; } } } if (onlyPossible == k) { setValue(i,j,onlyPossible); } } } } } for (int i = 0; i < possibles.GetLength(0); i++) { for (int j = 0; j < possibles.GetLength(1); j++) { //Get the square square = new PossibleNums[3, 3]; for (int k = 0; k < square.GetLength(0); k++) { for (int l = 0; l < square.GetLength(1); l++) { square[k, l] = possibles[(i / 3) * 3 + k, (j / 3) * 3 + l]; } } for (int k = 1; k <= possibles.GetLength(0); k++) //Loop through possible numbers { if (possibles[i, j].isPossible(k) && possibles[i, j].getValue() == -1) { onlyPossible = k; //Check square //Loop through the rest of the square to check if it's possible somewhere else for (int l = 0; l < square.GetLength(0) && onlyPossible != -1; l++) { for (int m = 0; m < square.GetLength(1) && onlyPossible != -1; m++) { if (l != i && m != j) { if (square[l, m].isPossible(onlyPossible)) { onlyPossible = -1; } } } } if (onlyPossible == k) { setValue(i,j,onlyPossible); } } } } } }