add step description
This commit is contained in:
@@ -27,6 +27,7 @@ int sudoku[9][9] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// https://www.free-sudoku.com/sudoku.php?dchoix=evil
|
// https://www.free-sudoku.com/sudoku.php?dchoix=evil
|
||||||
|
/*
|
||||||
int sudoku[9][9] = {
|
int sudoku[9][9] = {
|
||||||
{VALUE_UNDEFINED,1,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
{VALUE_UNDEFINED,1,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
||||||
{3,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
{3,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
||||||
@@ -38,6 +39,19 @@ int sudoku[9][9] = {
|
|||||||
{1,VALUE_UNDEFINED,VALUE_UNDEFINED,6,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
{1,VALUE_UNDEFINED,VALUE_UNDEFINED,6,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED},
|
||||||
{5,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED}
|
{5,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,8,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED,VALUE_UNDEFINED}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
int sudoku[9][9] = {
|
||||||
|
{5, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, 2},
|
||||||
|
{7, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 3, VALUE_UNDEFINED, VALUE_UNDEFINED, 5, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, VALUE_UNDEFINED, 7, 3, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 6, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, 2, VALUE_UNDEFINED, VALUE_UNDEFINED, 6, VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, 9, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 8, 3, VALUE_UNDEFINED, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, 8, VALUE_UNDEFINED, VALUE_UNDEFINED, 4, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 2},
|
||||||
|
{4, VALUE_UNDEFINED, 6, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 7, VALUE_UNDEFINED, VALUE_UNDEFINED},
|
||||||
|
{VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 1, VALUE_UNDEFINED, VALUE_UNDEFINED, VALUE_UNDEFINED, 9}
|
||||||
|
};
|
||||||
|
|
||||||
void readQ(int num) {
|
void readQ(int num) {
|
||||||
printf("Enter every number of Q%d from left top to right bottom. Use `0` if on no initial value:\n", num + 1);
|
printf("Enter every number of Q%d from left top to right bottom. Use `0` if on no initial value:\n", num + 1);
|
||||||
@@ -225,9 +239,9 @@ bool isInQuadrat(int q, int val) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(int q, int f, int val) {
|
void setValue(int q, int f, int val, char* rule) {
|
||||||
sudoku[q][f] = val;
|
sudoku[q][f] = val;
|
||||||
printf("=> setting %d in Q %d; F %d\n", val, q, f);
|
printf("=> setting %d in Q %d; F %d (%s)\n", val, q, f, rule);
|
||||||
//printDumpSudoku();
|
//printDumpSudoku();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,12 +290,14 @@ int main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (int val = 1; val <= 9; val++) {
|
for (int val = 1; val <= 9; val++) {
|
||||||
|
// val is already set in quadrat, go ahead
|
||||||
if (isInQuadrat(q, val)) {
|
if (isInQuadrat(q, val)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int possibleField = FIELD_UNDEFINED;
|
int possibleField = FIELD_UNDEFINED;
|
||||||
for (int f = 0; f < 9; f++) {
|
for (int f = 0; f < 9; f++) {
|
||||||
|
// calculate row and col of current field in quadrant
|
||||||
int row = calculateRow(q, f);
|
int row = calculateRow(q, f);
|
||||||
int col = calculateCol(q, f);
|
int col = calculateCol(q, f);
|
||||||
|
|
||||||
@@ -310,12 +326,12 @@ int main() {
|
|||||||
|
|
||||||
// found possible field? set val
|
// found possible field? set val
|
||||||
if (possibleField > FIELD_UNDEFINED) {
|
if (possibleField > FIELD_UNDEFINED) {
|
||||||
setValue(q, possibleField, val);
|
setValue(q, possibleField, val, "standard col/row check");
|
||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if only one field is left undefined -> hast to be the one special value
|
// check if only one field is left undefined -> has to be the one special value
|
||||||
for (int f = 0; f < 9; f++) {
|
for (int f = 0; f < 9; f++) {
|
||||||
// keep in mind that sudoku array might have changed since evaluation
|
// keep in mind that sudoku array might have changed since evaluation
|
||||||
// -> ignore already set values
|
// -> ignore already set values
|
||||||
@@ -324,7 +340,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (possbileVal[f] > VALUE_UNDEFINED) {
|
if (possbileVal[f] > VALUE_UNDEFINED) {
|
||||||
setValue(q, f, possbileVal[f]);
|
setValue(q, f, possbileVal[f], "every other value is not possible here");
|
||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
} else {
|
} else {
|
||||||
// set to undefined, multiple or any other meta information
|
// set to undefined, multiple or any other meta information
|
||||||
@@ -336,4 +352,4 @@ int main() {
|
|||||||
printDumpSudoku();
|
printDumpSudoku();
|
||||||
|
|
||||||
checkSolution();
|
checkSolution();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user