Hey guys. About a week or two ago I made a sudoku game, but I didn't post it because I couldn't(and still can't) make a random level generator for it. Unfortunately, I gave up making the sudoku random level generator, and I have no idea how to proceed even making it.

If anyone can explain how a level generator works/make me a random level generator, that would be great.

The menu for sudoku is pretty much the same as my flow game menu, because it uses the same code(in fact, I made the code for this and then copied it to my flow game). Also, the encoding for the levels is very similar.

Screenshot of a level:
How have you been thinking about the level design so far? Without giving away the complete answer, it seems to me that you would need the following constraints to make the game solveable:
1) Each digit appears once per row
2) Each digit appears once per column
3) Each digit appears once per block.
Additionally, there's the problem of how to delete squares once you construct a complete, solved game so that the player can then solve it, but let's punt on that for now. Consider techniques like constructing a complete but trivial board, then permuting them, as a starting point, then go from there.
Here are some slightly different questions:
Which 3x3 blocks, if any, can be generated independently of one another? If there are any, what are the largest sets of blocks you can find that are independent of one another? Is it possible to work yourself into a corner with some 3x3 blocks so that there are no valid ways to fill the remaining 3x3 blocks?
Ok so I finally managed after many revisions to make a filled sudoku generator. It is not implemented as I originally planned and isn't very well made, but it seems to work, so whatever. Now the task is to make the sudoku generator somehow remove tiles in a way that works with a certain difficulty and has only one unique solution.

Here is the code:

Code:
``` #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include <stdio.h> #include <stdlib.h> const char* fileLoc = "easyLevels.txt"; FILE *myfile; int *possibleMoves; int board[9][9] = { { 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 },{ 0,0,0,0,0,0,0,0,0 } }; void initFile() {    if ((myfile = fopen(fileLoc, "w")) == NULL) {       printf("didnt open");       return;    } } void closeFile() {    fclose(myfile); } void printBoard() {    fprintf(myfile, ",\"");    for (int i = 0; i < 9; i++) {       for (int j = 0; j < 9; j++) {          fprintf(myfile, "%d", board[i][j]);          if (j == 8) {             if(i!=8)                fprintf(myfile, "//");          }          else             fprintf(myfile, ",");       }    }    fprintf(myfile, "\" "); } void getPossibleMoves(int *possibleMoves[], int x, int y) {    int cpX = x / 3;    cpX *= 3;    int cpY = y / 3;    cpY *= 3;    int cpB[3][3];    for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++)          cpB[i][j] = board[cpX + i][cpY + j];    }    int psbleMoves[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };    for (int i = 0; i < 9; i++) {       for (int j = 0; j < 3; j++) {          for (int k = 0; k < 3; k++) {             if (psbleMoves[i] == cpB[j][k])                psbleMoves[i] = 0;          }       }       for (int j = 0; j < 9; j++) {          if (psbleMoves[i] == board[x][j] || psbleMoves[i] == board[j][y])             psbleMoves[i] = 0;       }    }    int numMoves = 0;    for (int i = 0; i < 9; i++) {       if (psbleMoves[i] != 0)          numMoves++;    }    delete(*possibleMoves);    *possibleMoves = new int[numMoves + 1];//(int*)malloc((numMoves+1)*sizeof(int));    (*possibleMoves)[0] = numMoves;    int prevInt = 1;    for (int i = 0; i < 9; i++) {       if (psbleMoves[i] != 0) {          (*possibleMoves)[prevInt] = psbleMoves[i];          prevInt++;       }    } } /*void generateBoard(int i, int j, int k, int h, int f) {    if (i < 81) {       board[i % 9][i / 9] = 0;       int *possibleMoves;       getPossibleMoves(&possibleMoves, i % 9, i / 9);       if (possibleMoves[0] > 0) {          board[i % 9][i / 9] = possibleMoves[rand() % possibleMoves[0] + 1];          delete(possibleMoves);          if (j < 10) {             if (i < h) {                generateBoard(i + 1, j, k - 1, h, f);             }             else {                generateBoard(i + 1, 0, 0, i + 1, 0);             }          }          else {             if (i == h) {                if (f < 9) {                   for (int l = h; l > h - k; l--)                      board[l % 9][l / 9] = 0;                   generateBoard(h - k, 0, k + 1, h, f + 1);                }                else {                   for (int l = h; l > h - k-1; l--)                      board[l % 9][l / 9] = 0;                   generateBoard(h - k - 1, 0, k + 1, h, 0);                }             }             else {                generateBoard(i - 1, 0, k + 1, h, f);             }          }       }       else {          delete(possibleMoves);          generateBoard(i - 1, j+1, k+1, h, f);       }    }    else {       return;    }    return; }*/ void generateBoard(int i, int j, int k) {    if (i < 81) {       board[i % 9][i / 9] = 0;       getPossibleMoves(&possibleMoves, i % 9, i / 9);       if (possibleMoves[0] > 0) {          board[i % 9][i / 9] = possibleMoves[rand() % possibleMoves[0] + 1];          if (i == k) {             generateBoard(i + 1, 0, i + 1);          }          else {             generateBoard(i + 1, j, k);          }       }       else {          if (i == k) {             for (int l = i; l > i - j - 1; l--)                board[l % 9][l / 9] = 0;             generateBoard(i - j - 1, j + 1, k);          }          else {             board[i % 9][i / 9] = 0;             generateBoard(i - 1, 1, i);          }       }    }    return; } int main() {    initFile();    generateBoard(0, 0, 0);    printBoard();    closeFile();    return 0; } ```

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum