|
|
@ -2,7 +2,7 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdbool.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#include "sudoku.h" |
|
|
|
|
|
|
|
#define SIZE_OF_GAMEBORD_AXIS_X 9 |
|
|
|
#define SIZE_OF_GAMEBORD_AXIS_Y 9 |
|
|
@ -14,6 +14,11 @@ |
|
|
|
|
|
|
|
int selected_difficulty; |
|
|
|
int selected_level; |
|
|
|
bool check_solved; |
|
|
|
bool test_help = false; |
|
|
|
int test_row_e; |
|
|
|
int test_col_e; |
|
|
|
int test_num; |
|
|
|
|
|
|
|
|
|
|
|
void Game_loop(); //is instead of main |
|
|
@ -29,6 +34,7 @@ void check_if_Sudoku_solved(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int availableLevels[AVAILABLE_DIFFICULTIES][AVAILABLE_LEVELS][SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
|
|
|
{ //easy |
|
|
|
{{0, 0, 3, 0, 2, 1, 8, 0, 0}, |
|
|
@ -234,6 +240,7 @@ void Game_loop() { |
|
|
|
printf("1. Easy\n2. Medium\n3. Hard\n"); |
|
|
|
printf("Enter the corresponding number or type 'quit' to exit: "); |
|
|
|
|
|
|
|
if(!test_help){ |
|
|
|
char input[10]; |
|
|
|
scanf("%s", input); |
|
|
|
|
|
|
@ -243,6 +250,7 @@ void Game_loop() { |
|
|
|
|
|
|
|
selected_difficulty = input[0] - '0'; // Convert the first character to an integer |
|
|
|
|
|
|
|
|
|
|
|
if ((selected_difficulty >= 1 && selected_difficulty <= 3) && input[1] == '\0') { |
|
|
|
Level_Pool(selected_difficulty); |
|
|
|
Level_Selection(Sudoku_grid); |
|
|
@ -250,7 +258,11 @@ void Game_loop() { |
|
|
|
} else { |
|
|
|
printf("Invalid input. Please enter a number between 1 and 3.\n"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if(test_help){ |
|
|
|
Level_Pool(selected_difficulty); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -267,6 +279,7 @@ void Level_Selection(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_A |
|
|
|
int level = 0; |
|
|
|
printf("\nSelect a level:\n"); |
|
|
|
while (true){ |
|
|
|
if(!test_help){ |
|
|
|
char level_select[10]; |
|
|
|
scanf("%s", level_select); |
|
|
|
|
|
|
@ -285,6 +298,13 @@ void Level_Selection(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_A |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(test_help){ |
|
|
|
selected_level = level; |
|
|
|
level--; |
|
|
|
create_playing_field(Sudoku_grid, selected_difficulty, selected_level); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
@ -299,11 +319,13 @@ void initializeGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AX |
|
|
|
|
|
|
|
void create_playing_field(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y], int selected_difficulty, int level) { |
|
|
|
initializeGrid(Sudoku_grid); |
|
|
|
if(!test_help){ |
|
|
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; i++) { |
|
|
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; j++) { |
|
|
|
Sudoku_grid[i][j] = availableLevels[selected_difficulty - 1][level - 1][i][j]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; i++) { |
|
|
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; j++) { |
|
|
|
printf("%d", Sudoku_grid[i][j]); |
|
|
@ -324,8 +346,14 @@ void Player_actions_for_playing(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF |
|
|
|
printf("5. Select level\n"); |
|
|
|
printf("6. Quit\n"); |
|
|
|
|
|
|
|
int action; |
|
|
|
|
|
|
|
int action; |
|
|
|
if(test_help){ |
|
|
|
printGrid(Sudoku_grid); |
|
|
|
check_if_Sudoku_solved(Sudoku_grid); |
|
|
|
break; |
|
|
|
} |
|
|
|
if(!test_help){ |
|
|
|
while (true){ |
|
|
|
char action_str[10]; |
|
|
|
scanf("%s", action_str); |
|
|
@ -362,6 +390,7 @@ void Player_actions_for_playing(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF |
|
|
|
printf("Invalid input. Please enter a number between 1 and 6.\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -372,9 +401,18 @@ void giving_hints_to_player(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAM |
|
|
|
printf("2. Set the user-specified 3x3 field to the right values\n"); |
|
|
|
printf("3. Solve the entire puzzle for the current level\n"); |
|
|
|
|
|
|
|
if(test_help){ |
|
|
|
initializeGrid(Sudoku_grid); |
|
|
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; i++) { |
|
|
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; j++) { |
|
|
|
Sudoku_grid[i][j] = solutionLevels[selected_difficulty - 1][selected_level - 1][i][j]; |
|
|
|
} |
|
|
|
} |
|
|
|
printf("Puzzle solved. \n"); |
|
|
|
|
|
|
|
} |
|
|
|
int option = 0; |
|
|
|
|
|
|
|
if(!test_help){ |
|
|
|
while (true){ |
|
|
|
char tip_str[10]; |
|
|
|
scanf("%s", tip_str); |
|
|
@ -452,6 +490,7 @@ void giving_hints_to_player(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAM |
|
|
|
default: |
|
|
|
printf("Invalid option. Please enter a number between 1 and 3.\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void write_userinput_into_Sudoku(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
|
|
@ -459,8 +498,14 @@ void write_userinput_into_Sudoku(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_O |
|
|
|
printf("1. Insert value in an empty field\n"); |
|
|
|
printf("2. Clear an already filled field\n"); |
|
|
|
|
|
|
|
int action; |
|
|
|
if(test_help){ |
|
|
|
initializeGrid(Sudoku_grid); |
|
|
|
Sudoku_grid[test_row_e -1][test_col_e -1] = test_num; |
|
|
|
printGrid(Sudoku_grid); |
|
|
|
} |
|
|
|
|
|
|
|
int action; |
|
|
|
if(!test_help){ |
|
|
|
while (true){ |
|
|
|
char in_str[10]; |
|
|
|
scanf("%s", in_str); |
|
|
@ -541,6 +586,7 @@ void write_userinput_into_Sudoku(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_O |
|
|
|
printf("Invalid input. Please enter 1 or 2.\n"); |
|
|
|
} |
|
|
|
printGrid(Sudoku_grid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -561,16 +607,17 @@ void check_if_Sudoku_solved(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAM |
|
|
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; j++) { |
|
|
|
if (Sudoku_grid[i][j] != solutionLevels[selected_difficulty - 1][selected_level - 1][i][j]) { |
|
|
|
printf("Incorrect solution. Keep trying!\n"); |
|
|
|
check_solved = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
check_solved = true; |
|
|
|
printf("Congratulations! Sudoku is solved correctly.\n"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(){ |
|
|
|
int mainn(){ |
|
|
|
Game_loop(); |
|
|
|
return 0; |
|
|
|
} |