You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
5.2 KiB
214 lines
5.2 KiB
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
#define SIZE 9
|
|
#define EMPTY 0
|
|
#define LEVEL_NUMBER 3
|
|
|
|
|
|
int difficulty;
|
|
int selected_level;
|
|
|
|
|
|
void startSudoku(); //is instead of main
|
|
void availableLevelsFunction(int difficulty);
|
|
void selectLevel(int grid[SIZE][SIZE]);
|
|
void initializeGrid(int grid[SIZE][SIZE]);
|
|
void generateSudoku(int grid[SIZE][SIZE], int difficulty, int level);
|
|
|
|
|
|
int availableLevels[3][3][SIZE][SIZE] = {
|
|
{ //easy
|
|
{{0, 0, 3, 0, 2, 1, 8, 0, 0},
|
|
{6, 0, 0, 0, 7, 0, 1, 3, 2},
|
|
{9, 2, 1, 5, 0, 0, 7, 6, 4},
|
|
{7, 6, 0, 3, 0, 0, 4, 0, 0},
|
|
{8, 5, 4, 1, 9, 7, 0, 0, 0},
|
|
{1, 0, 0, 4, 0, 6, 0, 0, 0},
|
|
{2, 9, 0, 8, 1, 5, 0, 0, 6},
|
|
{0, 4, 8, 2, 0, 9, 5, 0, 0},
|
|
{5, 0, 0, 7, 0, 3, 2, 0, 1}},
|
|
|
|
{{0, 0, 3, 0, 2, 1, 8, 0, 0},
|
|
{6, 0, 0, 0, 7, 0, 1, 3, 2},
|
|
{9, 2, 1, 5, 0, 0, 7, 6, 4},
|
|
{7, 6, 0, 3, 0, 0, 4, 0, 0},
|
|
{8, 5, 4, 1, 9, 7, 0, 0, 0},
|
|
{1, 0, 0, 4, 0, 6, 0, 0, 0},
|
|
{2, 9, 0, 8, 1, 5, 0, 0, 6},
|
|
{0, 4, 8, 2, 0, 9, 5, 0, 0},
|
|
{5, 0, 0, 7, 0, 3, 2, 0, 2}},
|
|
|
|
{{0, 0, 3, 0, 2, 1, 8, 0, 0},
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|
}
|
|
};
|
|
|
|
|
|
void startSudoku() {
|
|
int grid[SIZE][SIZE];
|
|
selected_level = 0;
|
|
|
|
while (1) {
|
|
printf("\nDifficulty Function - Choose difficulty:\n");
|
|
printf("1. Easy\n2. Medium\n3. Hard\n");
|
|
printf("Enter the corresponding number or type 'quit' to exit: ");
|
|
|
|
char input[10];
|
|
scanf("%s", input);
|
|
|
|
if (strcmp(input, "quit") == 0) {
|
|
break;
|
|
}
|
|
|
|
difficulty = input[0] - '0'; // Convert the first character to an integer
|
|
|
|
if ((difficulty >= 1 && difficulty <= 3) && input[1] == '\0') {
|
|
availableLevelsFunction(difficulty);
|
|
selectLevel(grid);
|
|
} else {
|
|
printf("Invalid input. Please enter a number between 1 and 3.\n");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void availableLevelsFunction(int difficulty) {
|
|
printf("\nAvailable Levels for Difficulty %d:\n", difficulty);
|
|
for (int i = 0; i < LEVEL_NUMBER; i++) {
|
|
printf("%d. Level %d\n", i + 1, i + 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void selectLevel(int grid[SIZE][SIZE]) {
|
|
int level = 0;
|
|
printf("\nSelect a level:\n");
|
|
while (true){
|
|
char level_select[10];
|
|
scanf("%s", level_select);
|
|
|
|
|
|
level = level_select[0] - '0'; // Convert the first character to an integer
|
|
|
|
if ((level >= 1 && level <= 3) && level_select[1] == '\0') {
|
|
selected_level = level;
|
|
|
|
level--; // Adjust to 0-based index
|
|
|
|
generateSudoku(grid, difficulty, selected_level);
|
|
break;
|
|
} else {
|
|
printf("Invalid input. Please enter a number between 1 and 3.\n");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void initializeGrid(int grid[SIZE][SIZE]) {
|
|
for (int i = 0; i < SIZE; i++) {
|
|
for (int j = 0; j < SIZE; j++) {
|
|
grid[i][j] = EMPTY;
|
|
}
|
|
}
|
|
}
|
|
|
|
void generateSudoku(int grid[SIZE][SIZE], int difficulty, int level) {
|
|
initializeGrid(grid);
|
|
printf("Level is getting initialized");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
startSudoku();
|
|
return 0;
|
|
}
|