Hi,
I've been working on a sudoku game, which seems to be working pretty well so far. I've managed to make a basic solver, and the interface is pretty nice :icon_cheesygrin: But i'm having problems trying generate a random unique sudoku. I need to be able to create 3 different difficulty level sudoku's, and I don't want them to take long to generate.
For example, say I have these functions.
struct cell {
int value;
};
struct sudoku {
cell grid[9][9];
};
void solve_easy(sudoku &sud) {
// Working
}
void generate_easy(sudoku &sud) {
// Reset sudoku
for (uint x = 0; x < 9; ++x) {
for (uint y = 0; y < 9; ++y) {
sud.grid[x][y] = 0;
}
}
// How do I generate an easy sudoku here?
}
I was thinking to first totally fill up the grid with valid integers (which is the first problem), and then keep removing one random number from the grid until it is no longer solvable using my basic solver. At that point, I put back the last number I removed from the grid. Would that give me a unique sudoku?
If not, what other ways could I manage this? any help would be appreciated :icon_lol:
The project is over a 1000 lines and wouldn't help much anyway, but I will attach the executable (along with one previously saved sudoku to show the solver works) to show you what I mean a little better.
Thanks.