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.

213 lines
5.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5. #define SIZE 9
  6. #define EMPTY 0
  7. #define LEVEL_NUMBER 3
  8. int difficulty;
  9. int selected_level;
  10. void startSudoku(); //is instead of main
  11. void availableLevelsFunction(int difficulty);
  12. void selectLevel(int grid[SIZE][SIZE]);
  13. void initializeGrid(int grid[SIZE][SIZE]);
  14. void generateSudoku(int grid[SIZE][SIZE], int difficulty, int level);
  15. int availableLevels[3][3][SIZE][SIZE] = {
  16. { //easy
  17. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  18. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  19. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  20. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  21. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  22. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  23. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  24. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  25. {5, 0, 0, 7, 0, 3, 2, 0, 1}},
  26. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  27. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  28. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  29. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  30. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  31. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  32. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  33. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  34. {5, 0, 0, 7, 0, 3, 2, 0, 2}},
  35. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  36. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  37. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  38. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  39. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  40. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  41. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  42. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  43. {5, 0, 0, 7, 0, 3, 2, 0, 3}}},
  44. {//medium
  45. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  46. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  47. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  48. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  49. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  50. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  51. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  52. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  53. {5, 0, 0, 7, 0, 3, 2, 0, 0}},
  54. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  55. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  56. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  57. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  58. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  59. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  60. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  61. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  62. {5, 0, 0, 7, 0, 3, 2, 0, 0}},
  63. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  64. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  65. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  66. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  67. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  68. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  69. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  70. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  71. {5, 0, 0, 7, 0, 3, 2, 0, 0}}
  72. },
  73. {//hard
  74. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  75. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  76. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  77. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  78. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  79. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  80. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  81. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  82. {5, 0, 0, 7, 0, 3, 2, 0, 0}},
  83. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  84. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  85. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  86. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  87. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  88. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  89. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  90. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  91. {5, 0, 0, 7, 0, 3, 2, 0, 0}},
  92. {{0, 0, 3, 0, 2, 1, 8, 0, 0},
  93. {6, 0, 0, 0, 7, 0, 1, 3, 2},
  94. {9, 2, 1, 5, 0, 0, 7, 6, 4},
  95. {7, 6, 0, 3, 0, 0, 4, 0, 0},
  96. {8, 5, 4, 1, 9, 7, 0, 0, 0},
  97. {1, 0, 0, 4, 0, 6, 0, 0, 0},
  98. {2, 9, 0, 8, 1, 5, 0, 0, 6},
  99. {0, 4, 8, 2, 0, 9, 5, 0, 0},
  100. {5, 0, 0, 7, 0, 3, 2, 0, 0}}
  101. }
  102. };
  103. void startSudoku() {
  104. int grid[SIZE][SIZE];
  105. selected_level = 0;
  106. while (1) {
  107. printf("\nDifficulty Function - Choose difficulty:\n");
  108. printf("1. Easy\n2. Medium\n3. Hard\n");
  109. printf("Enter the corresponding number or type 'quit' to exit: ");
  110. char input[10];
  111. scanf("%s", input);
  112. if (strcmp(input, "quit") == 0) {
  113. break;
  114. }
  115. difficulty = input[0] - '0'; // Convert the first character to an integer
  116. if ((difficulty >= 1 && difficulty <= 3) && input[1] == '\0') {
  117. availableLevelsFunction(difficulty);
  118. selectLevel(grid);
  119. } else {
  120. printf("Invalid input. Please enter a number between 1 and 3.\n");
  121. }
  122. }
  123. }
  124. void availableLevelsFunction(int difficulty) {
  125. printf("\nAvailable Levels for Difficulty %d:\n", difficulty);
  126. for (int i = 0; i < LEVEL_NUMBER; i++) {
  127. printf("%d. Level %d\n", i + 1, i + 1);
  128. }
  129. }
  130. void selectLevel(int grid[SIZE][SIZE]) {
  131. int level = 0;
  132. printf("\nSelect a level:\n");
  133. while (true){
  134. char level_select[10];
  135. scanf("%s", level_select);
  136. level = level_select[0] - '0'; // Convert the first character to an integer
  137. if ((level >= 1 && level <= 3) && level_select[1] == '\0') {
  138. selected_level = level;
  139. level--; // Adjust to 0-based index
  140. generateSudoku(grid, difficulty, selected_level);
  141. break;
  142. } else {
  143. printf("Invalid input. Please enter a number between 1 and 3.\n");
  144. }
  145. }
  146. }
  147. void initializeGrid(int grid[SIZE][SIZE]) {
  148. for (int i = 0; i < SIZE; i++) {
  149. for (int j = 0; j < SIZE; j++) {
  150. grid[i][j] = EMPTY;
  151. }
  152. }
  153. }
  154. void generateSudoku(int grid[SIZE][SIZE], int difficulty, int level) {
  155. initializeGrid(grid);
  156. printf("Level is getting initialized");
  157. }
  158. int main(){
  159. startSudoku();
  160. return 0;
  161. }