Browse Source
Merge branch 'main' of https://gitlab.cs.hs-fulda.de/fdai7715/the-hamsters
remotes/origin/Lucas
Merge branch 'main' of https://gitlab.cs.hs-fulda.de/fdai7715/the-hamsters
remotes/origin/Lucas
Joe Lukas Kalb
11 months ago
16 changed files with 2305 additions and 1 deletions
-
177src/main/c/TicTacToe.c
-
11src/main/c/TicTacToe.h
-
232src/main/c/VierGewinnt.c
-
20src/main/c/VierGewinnt.h
-
BINsrc/main/c/a.exe
-
398src/main/c/hangman.c
-
23src/main/c/hangman.h
-
1src/main/c/hangman.txt
-
20src/main/c/hangman_words.txt
-
623src/main/c/sudoku.c
-
41src/main/c/sudoku.h
-
173src/test/c/test_TicTacToe.c
-
151src/test/c/test_VierGewinnt.c
-
147src/test/c/test_hangman_test.c
-
286src/test/c/test_sudoku.c
-
1team.md
@ -0,0 +1,177 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#define ANSI_COLOR_BRIGHT_RED "\x1b[91m" |
||||
|
#define ANSI_COLOR_BRIGHT_CYAN "\x1b[96m" |
||||
|
#define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" |
||||
|
#define ANSI_COLOR_RESET "\x1b[0m" |
||||
|
|
||||
|
int Runde = 1; |
||||
|
// Funktion, um das Spielboard zu initialisieren |
||||
|
void initializeBoard(char board[3][3]) { |
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
for (int j = 0; j < 3; j++) { |
||||
|
board[i][j] = '_'; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
void displayBoard(char board[3][3]) { |
||||
|
#ifdef _WIN32 |
||||
|
system("cls"); |
||||
|
#else |
||||
|
system("clear"); |
||||
|
#endif |
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
for (int j = 0; j < 3; j++) { |
||||
|
if (board[i][j] == '_') { |
||||
|
printf(ANSI_COLOR_BRIGHT_YELLOW"%c "ANSI_COLOR_RESET, board[i][j]); |
||||
|
} |
||||
|
else if (board[i][j] == 'X') { |
||||
|
printf(ANSI_COLOR_BRIGHT_CYAN"%c "ANSI_COLOR_RESET, board[i][j]); |
||||
|
} |
||||
|
else { |
||||
|
printf(ANSI_COLOR_BRIGHT_RED"%c "ANSI_COLOR_RESET, board[i][j]); |
||||
|
} |
||||
|
} |
||||
|
printf("\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int Winner(char board[3][3]) { |
||||
|
// Überprüfen Sieg |
||||
|
// Überprüfen Reihen |
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
if (board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != '_') { |
||||
|
if (board[i][0] == 'X') { |
||||
|
return 1; |
||||
|
} |
||||
|
else return 2; |
||||
|
} |
||||
|
} |
||||
|
// Überprüfen Spalten |
||||
|
for (int j = 0; j < 3; j++) { |
||||
|
if (board[0][j] == board[1][j] && board[1][j] == board[2][j] && board[0][j] != '_') { |
||||
|
if (board[0][j] == 'X') { |
||||
|
return 1; |
||||
|
} |
||||
|
else return 2; |
||||
|
} |
||||
|
} |
||||
|
// Überprüfen Diagonalen |
||||
|
if ((board[0][0] == board[1][1] && board[1][1] == board[2][2]) || (board[0][2] == board[1][1] && board[1][1] == board[2][0])) { |
||||
|
if (board[1][1] != '_') { |
||||
|
if (board[1][1] == 'X') { |
||||
|
return 1; |
||||
|
} |
||||
|
else return 2; |
||||
|
} |
||||
|
} |
||||
|
//Überprüfe Runde |
||||
|
for (int k = 0; k < 3; k++) { |
||||
|
for (int l = 0; l < 3; l++) { |
||||
|
if (board[k][l] == '_') { |
||||
|
return 9; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
//Bestätige Unendschieden |
||||
|
printf("Es ist ein Unendschieden\n"); |
||||
|
return 0; |
||||
|
} |
||||
|
void makeMove(char board[3][3], int row, int column) { |
||||
|
if (Runde < 10) { |
||||
|
if (Runde % 2 == 0) { |
||||
|
if (board[row][column] == '_') { |
||||
|
board[row][column] = 'O'; |
||||
|
} |
||||
|
else { |
||||
|
printf("Das Feld ist schon besetzt. Gib ein anderes Feld ein:\n"); |
||||
|
printf("Reihe:"); |
||||
|
scanf("%d", &row); |
||||
|
printf("Spalte:"); |
||||
|
scanf("%d", &column); |
||||
|
row -= 1; |
||||
|
column -= 1; |
||||
|
makeMove(board, row, column); |
||||
|
} |
||||
|
} |
||||
|
else { |
||||
|
if (board[row][column] == '_') { |
||||
|
board[row][column] = 'X'; |
||||
|
} |
||||
|
else { |
||||
|
printf("Das Feld ist schon besetzt. Gib ein anderes Feld ein:\n"); |
||||
|
printf("Reihe:"); |
||||
|
scanf("%d", &row); |
||||
|
printf("Spalte:"); |
||||
|
scanf("%d", &column); |
||||
|
row -= 1; |
||||
|
column -= 1; |
||||
|
makeMove(board, row, column); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// Hauptfunktion zum Spielen des Tic Tac Toe-Spiels |
||||
|
int TicTacToe_ausfuehren() { |
||||
|
int row; |
||||
|
int column; |
||||
|
char board[3][3]; |
||||
|
char Spieler1[50], Spieler2[50]; |
||||
|
int Punkte1 = 0, Punkte2 = 0; |
||||
|
char Name1[50], Name2[50]; |
||||
|
char Ende[50] = { "Weiter" }; |
||||
|
printf("Name Spieler 1:"); |
||||
|
scanf("%s", Name1); |
||||
|
printf("Name Spieler 2:"); |
||||
|
scanf("%s", Name2); |
||||
|
while (Ende[0] == 'W' || Ende[0] == 'w') { |
||||
|
Runde = 1; |
||||
|
initializeBoard(board); |
||||
|
printf("%s, Was willst du sein?\n[X/O]\n", Name1); |
||||
|
scanf("%s", Spieler1); |
||||
|
if (Spieler1[0] != 'X' && Spieler1[0] != 'O') { |
||||
|
printf("Ungültige Auswahl. Das Spiel wird beendet.\n"); |
||||
|
break; |
||||
|
} |
||||
|
strcpy(Spieler2, (Spieler1[0] == 'X') ? Name2 : Name1); |
||||
|
strcpy(Spieler1, (Spieler1[0] == 'X') ? Name1 : Name2); |
||||
|
printf("\nWillkommen %s und %s. Eure Runde Beginnt jetzt.", Spieler1, Spieler2); |
||||
|
while (Winner(board) == 9) { |
||||
|
displayBoard(board); |
||||
|
if (Runde % 2 != 0) { |
||||
|
printf("Spieler 1 gebe das Feld an wo du dein X setzen willst.\n"); |
||||
|
} |
||||
|
else printf("Spieler 2 gebe das Feld an wo du dein O setzen willst.\n"); |
||||
|
printf("Reihe:"); |
||||
|
scanf("%d", &row); |
||||
|
printf("Spalte:"); |
||||
|
scanf("%d", &column); |
||||
|
row -= 1; |
||||
|
column -= 1; |
||||
|
if (row > 3 || column > 3) { |
||||
|
printf("Das ist nicht mehr im Feld. Versuch es nochmal:"); |
||||
|
scanf("%d %d", &row, &column); |
||||
|
row -= 1; //Für Index eins kleiner |
||||
|
column -= 1; |
||||
|
} |
||||
|
makeMove(board, row, column); |
||||
|
Runde++; |
||||
|
} |
||||
|
displayBoard(board); |
||||
|
if (Winner(board) == 1) { |
||||
|
printf("Der Sieger ist %s", Spieler1); |
||||
|
Punkte1++; |
||||
|
} |
||||
|
else if (Winner(board) == 2) { |
||||
|
printf("Der Sieger ist %s", Spieler2); |
||||
|
Punkte2++; |
||||
|
} |
||||
|
printf("%s - %d, %s - %d\n", Spieler1, Punkte1, Spieler2, Punkte2); |
||||
|
printf("Wollt ihr weiter spielen?\n[Weiter]\n[Ende]\n"); |
||||
|
scanf("%s", Ende); |
||||
|
} |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
#ifndef TICTACTOE_H |
||||
|
#define TICTACTOE_H |
||||
|
|
||||
|
void initializeBoard(char board[3][3]); |
||||
|
void displayBoard(char board[3][3]); |
||||
|
int Winner(char board[3][3]); |
||||
|
void makeMove(char board[3][3], int row, int col); |
||||
|
int TicTacToe_ausfuehren(); |
||||
|
|
||||
|
#endif |
||||
|
|
@ -0,0 +1,232 @@ |
|||||
|
// Author fdai7726 |
||||
|
|
||||
|
/* |
||||
|
*Ein Vier-Gewinnt-Spiel, das in der Kommandozeile gespielt wird. |
||||
|
*Das Programm ermöglicht es zwei Spielern, abwechselnd Steine in eine Spalte zu setzen, |
||||
|
*um eine Reihe von vier Steinen horizontal, |
||||
|
*vertikal oder diagonal zu bilden und das Spiel zu gewinnen. |
||||
|
*Das Spielfeld wird grafisch in der Kommandozeile dargestellt, |
||||
|
*und das Programm überprüft automatisch, |
||||
|
*ob einer der Spieler gewonnen hat oder ob das Spielfeld voll ist. |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
|
||||
|
//Importiere wichtige Bibliotheken |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
//Definiere Feldgröße |
||||
|
#define ROWS 6 |
||||
|
#define COLS 7 |
||||
|
|
||||
|
// Definiere Farben |
||||
|
#define RESET_COLOR "\033[0m" |
||||
|
#define BLACK "\033[0;30m" |
||||
|
#define RED "\033[0;31m" |
||||
|
#define GREEN "\033[0;32m" |
||||
|
#define YELLOW "\033[0;33m" |
||||
|
#define BLUE "\033[0;34m" |
||||
|
#define MAGENTA "\033[0;35m" |
||||
|
#define CYAN "\033[0;36m" |
||||
|
#define WHITE "\033[0;37m" |
||||
|
|
||||
|
//Funktionsprototypen |
||||
|
void initializeBoard(char board[ROWS][COLS]); |
||||
|
void printBoard(char board[ROWS][COLS]); |
||||
|
void clearScreen(); |
||||
|
int isColumnFull(char board[ROWS][COLS], int col); |
||||
|
int dropPiece(char board[ROWS][COLS], int col, char player); |
||||
|
int checkWin(char board[ROWS][COLS], char player); |
||||
|
int checkHorizontal(char board[ROWS][COLS], char player); |
||||
|
int checkVertical(char board[ROWS][COLS], char player); |
||||
|
int checkDiagonalRL(char board[ROWS][COLS], char player); |
||||
|
void showInvalidInputWarning(); |
||||
|
void showColumnFullMessage(); |
||||
|
void showWinMessage(int player); |
||||
|
|
||||
|
|
||||
|
int main_function() { |
||||
|
char board[ROWS][COLS]; |
||||
|
int Player = 1; |
||||
|
|
||||
|
initializeBoard(board); |
||||
|
printBoard(board); |
||||
|
|
||||
|
int column; |
||||
|
while (1) { |
||||
|
printf(YELLOW"Spieler %d, wähle eine Spalte (1-7): "RESET_COLOR, Player); |
||||
|
|
||||
|
scanf("%d", &column); |
||||
|
if (column < 1 || column > 7) { |
||||
|
showInvalidInputWarning(); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
column--; |
||||
|
|
||||
|
if (isColumnFull(board, column)) { |
||||
|
showColumnFullMessage(); |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (dropPiece(board, column, (Player == 1) ? 'X' : 'O')) { |
||||
|
printBoard(board); |
||||
|
if (checkWin(board, (Player == 1) ? 'X' : 'O')) { |
||||
|
showWinMessage(Player); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
Player = (Player == 1) ? 2 : 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
void initializeBoard(char board[ROWS][COLS]) { |
||||
|
for (int i = 0; i < ROWS; i++) { |
||||
|
for (int j = 0; j < COLS; j++) { |
||||
|
board[i][j] = ' '; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void printBoard(char board[ROWS][COLS]) { |
||||
|
clearScreen(); |
||||
|
printf("\n"); |
||||
|
|
||||
|
for (int i = 0; i < ROWS; i++) { |
||||
|
for (int j = 0; j < COLS; j++) { |
||||
|
printf("| %c ", board[i][j]); |
||||
|
} |
||||
|
printf("|\n"); |
||||
|
|
||||
|
for (int j = 0; j < COLS; j++) { |
||||
|
printf("----"); |
||||
|
} |
||||
|
printf("-\n"); |
||||
|
} |
||||
|
|
||||
|
printf(" 1 2 3 4 5 6 7\n\n"); |
||||
|
} |
||||
|
void clearScreen() { |
||||
|
#ifdef _WIN32 |
||||
|
system("cls"); |
||||
|
#else |
||||
|
system("clear"); |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
int isColumnFull(char board[ROWS][COLS], int col) { |
||||
|
return (board[0][col] != ' '); |
||||
|
} |
||||
|
|
||||
|
int dropPiece(char board[ROWS][COLS], int col, char player) { |
||||
|
for (int i = ROWS - 1; i >= 0; i--) { |
||||
|
if (board[i][col] == ' ') { |
||||
|
board[i][col] = player; |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
int checkHorizontal(char board[ROWS][COLS], char player) { |
||||
|
for (int row = 0; row < ROWS; row++) { |
||||
|
for (int col = 0; col <= COLS - 4; col++) { |
||||
|
if (board[row][col] == player && |
||||
|
board[row][col + 1] == player && |
||||
|
board[row][col + 2] == player && |
||||
|
board[row][col + 3] == player) { |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int checkVertical(char board[ROWS][COLS], char player) { |
||||
|
for (int col = 0; col < COLS; col++) { |
||||
|
for (int row = 0; row <= ROWS - 4; row++) { |
||||
|
if (board[row][col] == player && |
||||
|
board[row + 1][col] == player && |
||||
|
board[row + 2][col] == player && |
||||
|
board[row + 3][col] == player) { |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
int checkDiagonalLR(char board[ROWS][COLS], char player) { |
||||
|
for (int row = 0; row <= ROWS - 4; row++) { |
||||
|
for (int col = 0; col <= COLS - 4; col++) { |
||||
|
if (board[row][col] == player && |
||||
|
board[row + 1][col + 1] == player && |
||||
|
board[row + 2][col + 2] == player && |
||||
|
board[row + 3][col + 3] == player) { |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
int checkDiagonalRL(char board[ROWS][COLS], char player) { |
||||
|
for (int row = 0; row <= ROWS - 4; row++) { |
||||
|
for (int col = 3; col < COLS; col++) { |
||||
|
if (board[row][col] == player && |
||||
|
board[row + 1][col - 1] == player && |
||||
|
board[row + 2][col - 2] == player && |
||||
|
board[row + 3][col - 3] == player) { |
||||
|
return 1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return 0; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
int checkWin(char board[ROWS][COLS], char player) { |
||||
|
return checkHorizontal(board, player) || |
||||
|
checkVertical(board, player) || |
||||
|
checkDiagonalLR(board, player) || |
||||
|
checkDiagonalRL(board, player); |
||||
|
} |
||||
|
|
||||
|
// Die Funktion showMessage gibt eine formatierte Nachricht aus, wobei die Farbe der Nachricht dynamisch festgelegt werden kann. |
||||
|
void showMessage(const char* messageColor, const char* message) { |
||||
|
printf("%s%s"RESET_COLOR, messageColor, message); |
||||
|
} |
||||
|
|
||||
|
//Die Funktion showInvalidInputWarning zeigt eine Warnung für ungültige Benutzereingaben an. Sie ruft die Funktion showMessage auf, um die Nachricht in roter Farbe auszugeben, die den Benutzer darüber informiert, dass die Eingabe ungültig ist und er eine Spalte zwischen 1 und 7 wählen soll. |
||||
|
|
||||
|
void showInvalidInputWarning() { |
||||
|
showMessage(RED, "Ungültige Eingabe. Bitte wähle eine Spalte zwischen 1 und 7.\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void showColumnFullMessage() { |
||||
|
showMessage(RED, "Die ausgewählte Spalte ist bereits belegt. Bitte wähle eine andere Spalte aus.\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
void showWinMessage(int player) { |
||||
|
printf("Spieler %d ist der Gewinner!\n", player); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,20 @@ |
|||||
|
#ifndef VIERGEWINNT_H |
||||
|
#define VIERGEWINNT_H |
||||
|
|
||||
|
#define ROWS 6 |
||||
|
#define COLS 7 |
||||
|
|
||||
|
void initializeBoard(char board[ROWS][COLS]); |
||||
|
void printBoard(char board[ROWS][COLS]); |
||||
|
int isColumnFull(char board[ROWS][COLS], int col); |
||||
|
int dropPiece(char board[ROWS][COLS], int col, char player); |
||||
|
int checkWin(char board[ROWS][COLS], char player); |
||||
|
int checkHorizontal(char board[ROWS][COLS], char player); |
||||
|
int checkVertical(char board[ROWS][COLS], char player); |
||||
|
int checkDiagonalLR(char board[ROWS][COLS], char player); |
||||
|
int checkDiagonalRL(char board[ROWS][COLS], char player); |
||||
|
void showMessage(const char* messageColor, const char* message); |
||||
|
void showInvalidInputMessage(); |
||||
|
void showColumnFullMessage(); |
||||
|
void showWinMessage(int player); |
||||
|
#endif |
@ -0,0 +1,398 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include <conio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <ctype.h> |
||||
|
#include <unistd.h> |
||||
|
|
||||
|
void protokoll(); |
||||
|
void clear_screen(); |
||||
|
void willkommen(); |
||||
|
int namePruefen(); |
||||
|
void nameWaehlen(); |
||||
|
void startauswahl(); |
||||
|
void nameAusgeben(); |
||||
|
void levelauswahl(); |
||||
|
void hauptSpiel(int level); |
||||
|
void zeichne_galgen(int versuche); |
||||
|
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter); |
||||
|
char eingabe_buchstabe(); |
||||
|
void hole_zu_erratendes_wort(char* secret_word, int level, char* path); |
||||
|
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]); |
||||
|
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]); |
||||
|
int gewonnen(char secret_word[100], char guessed_letters[100]); |
||||
|
void level_plus(); |
||||
|
int overlay(); |
||||
|
|
||||
|
void protokoll(){ |
||||
|
clear_screen(); |
||||
|
willkommen(); |
||||
|
namePruefen(); |
||||
|
startauswahl(); |
||||
|
} |
||||
|
|
||||
|
void clear_screen() { |
||||
|
system("clear"); |
||||
|
// system("cls"); // fuer Windows |
||||
|
// system("clear"); // fuer UNIX/Linux |
||||
|
} |
||||
|
|
||||
|
void willkommen(){ |
||||
|
char ENTERtxt[] = {"-Druecke ENTER zum starten-\n"}; |
||||
|
|
||||
|
overlay(); |
||||
|
printf("%s", ENTERtxt); |
||||
|
getchar(); |
||||
|
} |
||||
|
|
||||
|
int namePruefen() { |
||||
|
char KonfDatei[100]; |
||||
|
int laengeKonfDatei = 0; |
||||
|
|
||||
|
FILE *fp = NULL; |
||||
|
fp = fopen("hangman.txt", "r"); |
||||
|
|
||||
|
if (fp == NULL) { |
||||
|
printf("Fehler beim Öffnen der Konfigurationsdatei\n"); |
||||
|
return 1; |
||||
|
} else { |
||||
|
fscanf(fp, "%s", KonfDatei); //Inhalt der KonfDatei wird ins Array gelesen |
||||
|
|
||||
|
while(KonfDatei[laengeKonfDatei] != 0){ //Laenge der KonfDatei wird ermittelt |
||||
|
laengeKonfDatei++; |
||||
|
} |
||||
|
|
||||
|
if(laengeKonfDatei > 14){ //mit der Laenge wird geschaut, ob ein Name gespeichert ist oder nicht |
||||
|
fclose(fp); |
||||
|
return 0; |
||||
|
} else { |
||||
|
printf("Sieht aus, als haettest du noch keinen Namen :(\n"); |
||||
|
nameWaehlen(); |
||||
|
fclose(fp); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
fclose(fp); |
||||
|
} |
||||
|
|
||||
|
void nameWaehlen(){ |
||||
|
char name[50]; |
||||
|
|
||||
|
FILE *fp = NULL; |
||||
|
fp = fopen("hangman.txt", "w"); |
||||
|
|
||||
|
clear_screen(); // |
||||
|
overlay(); |
||||
|
printf("Geben Sie den Namen ein: "); |
||||
|
scanf("%s", name); |
||||
|
|
||||
|
char KonfDatei[100]; |
||||
|
snprintf(KonfDatei, sizeof(KonfDatei), "name:%s,level:01", name); |
||||
|
|
||||
|
fprintf(fp, "%s", KonfDatei); |
||||
|
fclose(fp); |
||||
|
} |
||||
|
|
||||
|
void startauswahl() { |
||||
|
int auswahl; |
||||
|
int modus; |
||||
|
|
||||
|
clear_screen(); // |
||||
|
overlay(); |
||||
|
printf("Willkommen "); |
||||
|
nameAusgeben(); |
||||
|
printf("[1] Spielen\n[2] Namen aendern\n"); |
||||
|
scanf("%d", &auswahl); |
||||
|
|
||||
|
if(auswahl == 1){ |
||||
|
levelauswahl(); |
||||
|
} else if (auswahl == 2){ |
||||
|
nameWaehlen(); |
||||
|
} else { |
||||
|
printf("Eingabe ungueltig"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void nameAusgeben(){ |
||||
|
char KonfDatei[100]; |
||||
|
char name[50]; |
||||
|
int i = 5; |
||||
|
int zaehler = 0; |
||||
|
int nullterminante; |
||||
|
|
||||
|
FILE *fp = NULL; |
||||
|
fp = fopen("hangman.txt", "r"); |
||||
|
|
||||
|
fscanf(fp, "%s", KonfDatei); |
||||
|
while(KonfDatei[i] != ','){ |
||||
|
zaehler++; |
||||
|
i++; |
||||
|
} |
||||
|
nullterminante = zaehler; |
||||
|
while(zaehler != 0){ |
||||
|
name[--zaehler] = KonfDatei[--i]; |
||||
|
} |
||||
|
|
||||
|
i = 0; |
||||
|
while(name[i] != 0){ |
||||
|
i++; |
||||
|
} |
||||
|
|
||||
|
name[nullterminante] = '\0'; |
||||
|
printf("%s\n", name); |
||||
|
|
||||
|
fclose(fp); |
||||
|
} |
||||
|
|
||||
|
void levelauswahl(){ |
||||
|
char levelstr[3]; |
||||
|
char KonfDatei[100]; |
||||
|
int level; |
||||
|
int i = 0; |
||||
|
|
||||
|
clear_screen(); // |
||||
|
overlay(); |
||||
|
|
||||
|
FILE *fp = NULL; |
||||
|
fp = fopen("hangman.txt", "r"); |
||||
|
|
||||
|
fscanf(fp, "%s", KonfDatei); |
||||
|
while(KonfDatei[i] != 0){ |
||||
|
i++; |
||||
|
} |
||||
|
levelstr[0] = KonfDatei[i-2]; |
||||
|
levelstr[1] = KonfDatei[i-1]; |
||||
|
levelstr[2] = '\0'; |
||||
|
level = atoi(levelstr); |
||||
|
hauptSpiel(level); |
||||
|
fclose(fp); |
||||
|
} |
||||
|
|
||||
|
void hauptSpiel(int level){ |
||||
|
char secret_word[100]; |
||||
|
int versuche = 0; |
||||
|
char guessed_letter; |
||||
|
char guessed_letters[100]; |
||||
|
char path[] = "hangman_words.txt"; |
||||
|
int result; |
||||
|
int won = 0; |
||||
|
|
||||
|
hole_zu_erratendes_wort(secret_word, level, path); |
||||
|
|
||||
|
while (versuche < 6 && won == 0) { |
||||
|
zeichne_galgen(versuche); |
||||
|
zeige_Buchstabenfeld(secret_word, guessed_letters); |
||||
|
guessed_letter = eingabe_buchstabe(); |
||||
|
result = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word); |
||||
|
if (result == 0){ |
||||
|
erratenen_buchstaben_hinzufuegen(guessed_letters, guessed_letter); |
||||
|
} |
||||
|
else { |
||||
|
versuche++; |
||||
|
} |
||||
|
won = gewonnen(secret_word, guessed_letters); |
||||
|
} |
||||
|
if (won == 1){ |
||||
|
level_plus(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void zeichne_galgen(int versuche) { |
||||
|
clear_screen(); |
||||
|
printf("Galgenmann!\n"); |
||||
|
printf("v.1.0.2\n\n"); |
||||
|
|
||||
|
switch(versuche) { |
||||
|
case 0: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 1: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 2: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 3: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" | /|\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 4: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" | /|\\\n"); |
||||
|
printf(" |\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 5: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" | /|\\\n"); |
||||
|
printf(" | /\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
case 6: |
||||
|
printf(" _______\n"); |
||||
|
printf(" | |\n"); |
||||
|
printf(" | O\n"); |
||||
|
printf(" | /|\\\n"); |
||||
|
printf(" | / \\\n"); |
||||
|
printf(" |\n"); |
||||
|
printf("__|_________\n\n\n\n"); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter){ |
||||
|
for (int i = 0; i < strlen(guessed_letters); i++){ |
||||
|
if (guessed_letters[i] == guessed_letter){ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
guessed_letters[strlen(guessed_letters)] = guessed_letter; |
||||
|
guessed_letters[strlen(guessed_letters) + 1] = '\0'; |
||||
|
} |
||||
|
|
||||
|
char eingabe_buchstabe(){ |
||||
|
char guess; |
||||
|
scanf(" %c", &guess); |
||||
|
guess = tolower(guess); |
||||
|
return guess; |
||||
|
} |
||||
|
|
||||
|
void hole_zu_erratendes_wort(char* secret_word, int level, char* path){ |
||||
|
FILE *file = fopen(path, "r"); |
||||
|
int count = 0; |
||||
|
if ( file != NULL ) |
||||
|
{ |
||||
|
char line[100]; /* or other suitable maximum line size */ |
||||
|
while (fgets(line, sizeof line, file) != NULL) /* read a line */ |
||||
|
{ |
||||
|
if (count == level) |
||||
|
{ |
||||
|
strcpy(secret_word, line); |
||||
|
secret_word[strlen(secret_word) - 1] = '\0'; |
||||
|
return; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
count++; |
||||
|
} |
||||
|
} |
||||
|
fclose(file); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]){ |
||||
|
printf("Erratene Buchstaben: "); |
||||
|
for(int i = 0; i < strlen(secret_word); i++) { |
||||
|
if(strchr(guessed_letters, secret_word[i])){ |
||||
|
printf("%c ", secret_word[i]); |
||||
|
} |
||||
|
else{ |
||||
|
printf("_ "); |
||||
|
} |
||||
|
} |
||||
|
printf("\n"); |
||||
|
} |
||||
|
|
||||
|
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]){ |
||||
|
for(int i = 0; i < strlen(secret_word); i++){ |
||||
|
if(guessed_letter == secret_word[i]){ |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
int gewonnen(char secret_word[100], char guessed_letters[100]){ |
||||
|
int occured; |
||||
|
for (int i = 0; i < strlen(secret_word); i++){ |
||||
|
occured = 0; |
||||
|
for (int k = 0; k < strlen(guessed_letters); k++){ |
||||
|
if (secret_word[i] == guessed_letters[k]){ |
||||
|
occured = 1; |
||||
|
} |
||||
|
} |
||||
|
if (occured == 0){ |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
void level_plus(){ |
||||
|
char KonfDatei[100]; |
||||
|
char level[3]; |
||||
|
int i = 0; |
||||
|
|
||||
|
FILE *fp = NULL; |
||||
|
fp = fopen("hangman.txt", "r+"); |
||||
|
fscanf(fp, "%s", KonfDatei); |
||||
|
|
||||
|
while(KonfDatei[i] != 0){ |
||||
|
i++; |
||||
|
} |
||||
|
level[0] = KonfDatei[i-2]; |
||||
|
level[1] = KonfDatei[i-1]; |
||||
|
level[2] = '\0'; |
||||
|
if (level[1] == '9'){ |
||||
|
KonfDatei[i-2]++; |
||||
|
KonfDatei[i-1] = '0'; |
||||
|
} else { |
||||
|
KonfDatei[i-1]++; |
||||
|
} |
||||
|
fclose(fp); |
||||
|
fp = fopen("hangman.txt", "w"); |
||||
|
fprintf(fp, "%s", KonfDatei); |
||||
|
fclose(fp); |
||||
|
} |
||||
|
|
||||
|
int overlay(){ |
||||
|
char galgen_overlay[10][41] = { |
||||
|
" _______ ", |
||||
|
" | | ", |
||||
|
" | ", |
||||
|
" | ", |
||||
|
" | ", |
||||
|
" | ", |
||||
|
"__|_________\n" |
||||
|
}; |
||||
|
|
||||
|
printf("Galgenmann!\n"); |
||||
|
printf("v.1.0.2\n\n"); |
||||
|
|
||||
|
|
||||
|
for (int i = 0; i < 9; i++) { |
||||
|
printf("%s\n", galgen_overlay[i]); |
||||
|
} |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
#ifndef TEST_H |
||||
|
#define TEST_H |
||||
|
|
||||
|
void protokoll(); |
||||
|
void clear_screen(); |
||||
|
void willkommen(); |
||||
|
int namePruefen(); |
||||
|
void nameWaehlen(); |
||||
|
void startauswahl(); |
||||
|
void nameAusgeben(); |
||||
|
void levelauswahl(); |
||||
|
void hauptSpiel(int level); |
||||
|
void zeichne_galgen(int versuche); |
||||
|
void erratenen_buchstaben_hinzufuegen(char* guessed_letters, char guessed_letter); |
||||
|
char eingabe_buchstabe(); |
||||
|
void hole_zu_erratendes_wort(char* secret_word, int level, char* path); |
||||
|
void zeige_Buchstabenfeld(char secret_word[100], char guessed_letters[100]); |
||||
|
int buchstabe_im_zu_erratenden_wort(char guessed_letter, char secret_word[100]); |
||||
|
int gewonnen(char secret_word[100], char guessed_letters[100]); |
||||
|
void level_plus(); |
||||
|
int overlay(); |
||||
|
|
||||
|
#endif // TEST_H |
@ -0,0 +1 @@ |
|||||
|
name:peter,level:02 |
@ -0,0 +1,20 @@ |
|||||
|
fulda |
||||
|
galgenmann |
||||
|
programmiermethoden |
||||
|
test |
||||
|
peter |
||||
|
ahmad |
||||
|
joe |
||||
|
celine |
||||
|
sigi |
||||
|
jonas |
||||
|
mitochondrien |
||||
|
aufmerksamkeitsdefizithyperaktivitaetsstoerung |
||||
|
donaudampfschifffahrtelekrizitaetenhauptbetriebswerkbauunternehmenbeamtengesellschaft |
||||
|
malaysia |
||||
|
lucas |
||||
|
yasin |
||||
|
samuel |
||||
|
celli |
||||
|
hochschule |
||||
|
fulda |
@ -0,0 +1,623 @@ |
|||||
|
#include <stdio.h> |
||||
|
#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 |
||||
|
#define AVAILABLE_DIFFICULTIES 3 |
||||
|
#define AVAILABLE_LEVELS 3 |
||||
|
#define EMPTY 0 |
||||
|
#define LEVEL_NUMBER 3 |
||||
|
|
||||
|
|
||||
|
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 |
||||
|
void Level_Pool(int selected_difficulty); |
||||
|
void Level_Selection(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void initializeGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void create_playing_field(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y], int selected_difficulty, int level); |
||||
|
void Player_actions_for_playing(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void giving_hints_to_player(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void write_userinput_into_Sudoku(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void printGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void check_if_Sudoku_solved(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
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}, |
||||
|
{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, 0}}, |
||||
|
|
||||
|
{{7, 0, 2, 0, 0, 0, 9, 5, 0}, |
||||
|
{0, 8, 0, 7, 5, 0, 2, 1, 6}, |
||||
|
{0, 0, 5, 5, 2, 8, 7, 0, 3}, |
||||
|
{5, 1, 8, 4, 3, 0, 6, 0, 0}, |
||||
|
{0, 0, 6, 1, 0, 0, 5, 3, 0}, |
||||
|
{0, 0, 0, 0, 6, 2, 0, 8, 1}, |
||||
|
{0, 9, 0, 2, 0, 4, 0, 0, 5}, |
||||
|
{0, 2, 0, 0, 9, 5, 0, 7, 4}, |
||||
|
{0, 5, 1, 0, 0, 0, 0, 9, 2}}, |
||||
|
|
||||
|
{{4, 2, 5, 0, 9, 7, 1, 3, 0}, |
||||
|
{0, 7, 0, 1, 0, 3, 0, 0, 6}, |
||||
|
{0, 6, 1, 4, 8, 2, 0, 0, 0}, |
||||
|
{1, 0, 0, 0, 3, 0, 0, 6, 0}, |
||||
|
{7, 0, 8, 0, 2, 0, 0, 1, 3}, |
||||
|
{9, 3, 0, 0, 4, 1, 5, 7, 2}, |
||||
|
{0, 0, 7, 9, 6, 5, 0, 0, 0}, |
||||
|
{0, 0, 4, 3, 7, 0, 2, 0, 5}, |
||||
|
{0, 0, 0, 2, 1, 0, 0, 0, 0}}}, |
||||
|
|
||||
|
{//medium |
||||
|
{{0, 0, 3, 0, 2, 1, 8, 0, 0}, |
||||
|
{6, 0, 0, 0, 0, 0, 1, 3, 2}, |
||||
|
{0, 2, 1, 0, 0, 0, 7, 6, 4}, |
||||
|
{7, 6, 0, 3, 0, 0, 4, 0, 0}, |
||||
|
{0, 5, 0, 1, 0, 7, 0, 0, 0}, |
||||
|
{1, 0, 0, 4, 0, 6, 0, 0, 0}, |
||||
|
{2, 0, 0, 8, 0, 0, 0, 0, 6}, |
||||
|
{0, 4, 0, 0, 0, 9, 5, 0, 0}, |
||||
|
{5, 0, 0, 7, 0, 3, 2, 0, 0}}, |
||||
|
|
||||
|
{{7, 0, 2, 0, 0, 0, 9, 5, 0}, |
||||
|
{0, 0, 0, 7, 5, 0, 2, 0, 6}, |
||||
|
{0, 0, 5, 0, 2, 8, 7, 0, 3}, |
||||
|
{5, 1, 8, 0, 3, 0, 6, 0, 0}, |
||||
|
{0, 0, 6, 1, 0, 0, 0, 3, 0}, |
||||
|
{0, 0, 0, 0, 6, 2, 0, 8, 1}, |
||||
|
{0, 9, 0, 2, 0, 4, 0, 0, 5}, |
||||
|
{0, 0, 0, 0, 9, 0, 0, 0, 4}, |
||||
|
{0, 5, 1, 0, 0, 0, 0, 9, 2}}, |
||||
|
|
||||
|
{{4, 2, 5, 0, 9, 7, 1, 3, 0}, |
||||
|
{0, 0, 0, 1, 0, 3, 0, 0, 6}, |
||||
|
{0, 6, 0, 4, 0, 2, 0, 0, 0}, |
||||
|
{1, 0, 0, 0, 3, 0, 0, 6, 0}, |
||||
|
{7, 0, 8, 0, 2, 0, 0, 1, 3}, |
||||
|
{0, 3, 0, 0, 0, 1, 0, 7, 2}, |
||||
|
{0, 0, 7, 9, 6, 0, 0, 0, 0}, |
||||
|
{0, 0, 4, 3, 7, 0, 2, 0, 5}, |
||||
|
{0, 0, 0, 2, 1, 0, 0, 0, 0}} |
||||
|
}, |
||||
|
|
||||
|
{//hard |
||||
|
{{0, 0, 3, 0, 2, 0, 8, 0, 0}, |
||||
|
{6, 0, 0, 0, 0, 0, 0, 3, 0}, |
||||
|
{9, 2, 1, 5, 0, 0, 7, 6, 4}, |
||||
|
{0, 0, 0, 3, 0, 0, 0, 0, 0}, |
||||
|
{0, 5, 4, 1, 0, 7, 0, 0, 0}, |
||||
|
{1, 0, 0, 0, 0, 0, 0, 0, 0}, |
||||
|
{2, 0, 0, 0, 1, 5, 0, 0, 6}, |
||||
|
{0, 4, 0, 2, 0, 0, 0, 0, 0}, |
||||
|
{5, 0, 0, 0, 0, 3, 2, 0, 0}}, |
||||
|
|
||||
|
{{7, 0, 2, 0, 0, 0, 9, 0, 0}, |
||||
|
{0, 0, 0, 7, 0, 0, 0, 1, 6}, |
||||
|
{0, 0, 5, 0, 0, 8, 7, 0, 3}, |
||||
|
{5, 0, 0, 4, 0, 0, 6, 0, 0}, |
||||
|
{0, 0, 6, 1, 0, 0, 5, 3, 0}, |
||||
|
{0, 0, 0, 0, 0, 2, 0, 0, 1}, |
||||
|
{0, 9, 0, 2, 0, 4, 0, 0, 0}, |
||||
|
{0, 2, 0, 0, 0, 5, 0, 7, 0}, |
||||
|
{0, 5, 0, 0, 0, 0, 0, 9, 2}}, |
||||
|
|
||||
|
{{4, 0, 5, 0, 9, 7, 1, 3, 0}, |
||||
|
{0, 0, 0, 0, 0, 3, 0, 0, 6}, |
||||
|
{0, 6, 1, 4, 0, 2, 0, 0, 0}, |
||||
|
{1, 0, 0, 0, 3, 0, 0, 6, 0}, |
||||
|
{0, 0, 8, 0, 0, 0, 0, 0, 3}, |
||||
|
{9, 3, 0, 0, 4, 1, 5, 7, 2}, |
||||
|
{0, 0, 7, 9, 0, 5, 0, 0, 0}, |
||||
|
{0, 0, 4, 3, 0, 0, 2, 0, 5}, |
||||
|
{0, 0, 0, 2, 1, 0, 0, 0, 0}} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
int solutionLevels[AVAILABLE_DIFFICULTIES][AVAILABLE_LEVELS][SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
||||
|
|
||||
|
{ //easy |
||||
|
{{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}, |
||||
|
|
||||
|
{{7, 3, 2, 6, 4, 1, 9, 5, 8}, |
||||
|
{9, 8, 4, 7, 5, 3, 2, 1, 6}, |
||||
|
{1, 6, 5, 9, 2, 8, 7, 4, 3}, |
||||
|
{5, 1, 8, 4, 3, 7, 6, 2, 9}, |
||||
|
{2, 4, 6, 1, 8, 9, 5, 3, 7}, |
||||
|
{3, 7, 9, 5, 6, 2, 4, 8, 1}, |
||||
|
{8, 9, 7, 2, 1, 4, 3, 6, 5}, |
||||
|
{6, 2, 3, 8, 9, 5, 1, 7, 4}, |
||||
|
{4, 5, 1, 3, 7, 6, 8, 9, 2}}, |
||||
|
|
||||
|
{{4, 2, 5, 6, 9, 7, 1, 3, 8}, |
||||
|
{8, 7, 9, 1, 5, 3, 4, 2, 6}, |
||||
|
{3, 6, 1, 4, 8, 2, 7, 5, 9}, |
||||
|
{1, 5, 2, 7, 3, 9, 8, 6, 4}, |
||||
|
{7, 4, 8, 5, 2, 6, 9, 1, 3}, |
||||
|
{9, 3, 6, 8, 4, 1, 5, 7, 2}, |
||||
|
{2, 8, 7, 9, 6, 5, 3, 4, 1}, |
||||
|
{6, 1, 4, 3, 7, 8, 2, 9, 5}, |
||||
|
{5, 9, 3, 2, 1, 4, 6, 8, 7}}}, |
||||
|
|
||||
|
{//medium |
||||
|
{{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}, |
||||
|
|
||||
|
{{7, 3, 2, 6, 4, 1, 9, 5, 8}, |
||||
|
{9, 8, 4, 7, 5, 3, 2, 1, 6}, |
||||
|
{1, 6, 5, 9, 2, 8, 7, 4, 3}, |
||||
|
{5, 1, 8, 4, 3, 7, 6, 2, 9}, |
||||
|
{2, 4, 6, 1, 8, 9, 5, 3, 7}, |
||||
|
{3, 7, 9, 5, 6, 2, 4, 8, 1}, |
||||
|
{8, 9, 7, 2, 1, 4, 3, 6, 5}, |
||||
|
{6, 2, 3, 8, 9, 5, 1, 7, 4}, |
||||
|
{4, 5, 1, 3, 7, 6, 8, 9, 2}}, |
||||
|
|
||||
|
{{4, 2, 5, 6, 9, 7, 1, 3, 8}, |
||||
|
{8, 7, 9, 1, 5, 3, 4, 2, 6}, |
||||
|
{3, 6, 1, 4, 8, 2, 7, 5, 9}, |
||||
|
{1, 5, 2, 7, 3, 9, 8, 6, 4}, |
||||
|
{7, 4, 8, 5, 2, 6, 9, 1, 3}, |
||||
|
{9, 3, 6, 8, 4, 1, 5, 7, 2}, |
||||
|
{2, 8, 7, 9, 6, 5, 3, 4, 1}, |
||||
|
{6, 1, 4, 3, 7, 8, 2, 9, 5}, |
||||
|
{5, 9, 3, 2, 1, 4, 6, 8, 7}} |
||||
|
}, |
||||
|
|
||||
|
{//hard |
||||
|
{{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}, |
||||
|
|
||||
|
{{7, 3, 2, 6, 4, 1, 9, 5, 8}, |
||||
|
{9, 8, 4, 7, 5, 3, 2, 1, 6}, |
||||
|
{1, 6, 5, 9, 2, 8, 7, 4, 3}, |
||||
|
{5, 1, 8, 4, 3, 7, 6, 2, 9}, |
||||
|
{2, 4, 6, 1, 8, 9, 5, 3, 7}, |
||||
|
{3, 7, 9, 5, 6, 2, 4, 8, 1}, |
||||
|
{8, 9, 7, 2, 1, 4, 3, 6, 5}, |
||||
|
{6, 2, 3, 8, 9, 5, 1, 7, 4}, |
||||
|
{4, 5, 1, 3, 7, 6, 8, 9, 2}}, |
||||
|
|
||||
|
{{4, 2, 5, 6, 9, 7, 1, 3, 8}, |
||||
|
{8, 7, 9, 1, 5, 3, 4, 2, 6}, |
||||
|
{3, 6, 1, 4, 8, 2, 7, 5, 9}, |
||||
|
{1, 5, 2, 7, 3, 9, 8, 6, 4}, |
||||
|
{7, 4, 8, 5, 2, 6, 9, 1, 3}, |
||||
|
{9, 3, 6, 8, 4, 1, 5, 7, 2}, |
||||
|
{2, 8, 7, 9, 6, 5, 3, 4, 1}, |
||||
|
{6, 1, 4, 3, 7, 8, 2, 9, 5}, |
||||
|
{5, 9, 3, 2, 1, 4, 6, 8, 7}} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
void Game_loop() { |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
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: "); |
||||
|
|
||||
|
if(!test_help){ |
||||
|
char input[10]; |
||||
|
scanf("%s", input); |
||||
|
|
||||
|
if (strcmp(input, "quit") == 0) { |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
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); |
||||
|
Player_actions_for_playing(Sudoku_grid); |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 3.\n"); |
||||
|
} |
||||
|
} |
||||
|
if(test_help){ |
||||
|
Level_Pool(selected_difficulty); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void Level_Pool(int selected_difficulty) { |
||||
|
printf("\nAvailable Levels for Difficulty %d:\n", selected_difficulty); |
||||
|
for (int i = 0; i < LEVEL_NUMBER; i++) { |
||||
|
printf("%d. Level %d\n", i + 1, i + 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
void Level_Selection(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
int level = 0; |
||||
|
printf("\nSelect a level:\n"); |
||||
|
while (true){ |
||||
|
if(!test_help){ |
||||
|
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 |
||||
|
|
||||
|
create_playing_field(Sudoku_grid, selected_difficulty, selected_level); |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 3.\n"); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
if(test_help){ |
||||
|
selected_level = level; |
||||
|
level--; |
||||
|
create_playing_field(Sudoku_grid, selected_difficulty, selected_level); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void initializeGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
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] = EMPTY; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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]); |
||||
|
} |
||||
|
printf("\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void Player_actions_for_playing(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
while (1) { |
||||
|
printf("\nTurn function - Choose an action:\n"); |
||||
|
printf("1. Hints\n"); |
||||
|
printf("2. Insert Number into Game\n"); |
||||
|
printf("3. Print Sudoku grid\n"); |
||||
|
printf("4. Check if your Solution is correct\n"); |
||||
|
printf("5. Select level\n"); |
||||
|
printf("6. Quit\n"); |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
|
||||
|
action = action_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if ((action >= 1 && action <= 6) && action_str[1] == '\0') { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 6.\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
switch (action) { |
||||
|
case 1: |
||||
|
giving_hints_to_player(Sudoku_grid); |
||||
|
break; |
||||
|
case 2: |
||||
|
write_userinput_into_Sudoku(Sudoku_grid); |
||||
|
break; |
||||
|
case 3: |
||||
|
printGrid(Sudoku_grid); |
||||
|
break; |
||||
|
case 4: |
||||
|
check_if_Sudoku_solved(Sudoku_grid); |
||||
|
break; |
||||
|
case 5: |
||||
|
Level_Selection(Sudoku_grid); |
||||
|
break; |
||||
|
case 6: |
||||
|
printf("Exiting Sudoku program.\n"); |
||||
|
exit(0); |
||||
|
default: |
||||
|
printf("Invalid input. Please enter a number between 1 and 6.\n"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
void giving_hints_to_player(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
printf("\nTip function - Choose an option:\n"); |
||||
|
printf("1. Set the user-specified cell to the right value\n"); |
||||
|
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); |
||||
|
|
||||
|
|
||||
|
option = tip_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if ((option >= 1 && option <= 3) && tip_str[1] == '\0') { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 3.\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
switch (option) { |
||||
|
case 1: |
||||
|
printf("Enter the coordinates (row and column) separated by space:\n"); |
||||
|
int row, col; |
||||
|
|
||||
|
while (true){ |
||||
|
char row_str[10]; |
||||
|
char col_str[10]; |
||||
|
scanf("%s %s", row_str, col_str); |
||||
|
|
||||
|
|
||||
|
row = row_str[0] - '0'; // Convert the first character to an integer |
||||
|
col = col_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if (((row >= 1 && row <= 9) && row_str[1] == '\0') && ((col >= 1 && col <= 9) && col_str[1] == '\0')) { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 9.\n"); |
||||
|
} |
||||
|
} |
||||
|
Sudoku_grid[row - 1][col - 1] = solutionLevels[selected_difficulty - 1][selected_level - 1][row - 1][col - 1]; |
||||
|
printf("Value set successfully.\n"); |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
printf("Enter the coordinates (top-left cell of the 3x3 field) separated by space:\n"); |
||||
|
int startRow, startCol; |
||||
|
|
||||
|
while (true){ |
||||
|
char row_squ[10]; |
||||
|
char col_squ[10]; |
||||
|
scanf("%s %s", row_squ, col_squ); |
||||
|
|
||||
|
|
||||
|
startRow = row_squ[0] - '0'; // Convert the first character to an integer |
||||
|
startCol = col_squ[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if (((startRow >= 1 && startRow <= 9) && row_squ[1] == '\0') && ((startCol >= 1 && startCol <= 9) && col_squ[1] == '\0')) { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 9.\n"); |
||||
|
} |
||||
|
} |
||||
|
for (int i = 0; i < 3; i++) { |
||||
|
for (int j = 0; j < 3; j++) { |
||||
|
Sudoku_grid[startRow - 1 + i][startCol - 1 + j] = |
||||
|
solutionLevels[selected_difficulty - 1][selected_level - 1][startRow - 1 + i][startCol - 1 + j]; |
||||
|
} |
||||
|
} |
||||
|
printf("3x3 field set successfully.\n"); |
||||
|
break; |
||||
|
|
||||
|
case 3: |
||||
|
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"); |
||||
|
break; |
||||
|
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]) { |
||||
|
printf("\nInput function - Choose an action:\n"); |
||||
|
printf("1. Insert value in an empty field\n"); |
||||
|
printf("2. Clear an already filled field\n"); |
||||
|
|
||||
|
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); |
||||
|
|
||||
|
action = in_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if ((action >= 1 && action <= 2) && in_str[1] == '\0') { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 2.\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
switch (action) { |
||||
|
case 1: |
||||
|
printf("Enter the coordinates (row and column) separated by space:\n"); |
||||
|
int row_e, col_e, num; |
||||
|
|
||||
|
|
||||
|
while (true){ |
||||
|
char rowe_str[10]; |
||||
|
char cole_str[10]; |
||||
|
scanf("%s %s", rowe_str, cole_str); |
||||
|
|
||||
|
row_e = rowe_str[0] - '0'; // Convert the first character to an integer |
||||
|
col_e = cole_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if (((row_e >= 1 && row_e <= 9) && rowe_str[1] == '\0') && ((col_e >= 1 && col_e <= 9) && cole_str[1] == '\0')) { |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 9.\n"); |
||||
|
} |
||||
|
} |
||||
|
printf("Enter the value to insert (1-9):\n"); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
while (true){ |
||||
|
char nume_str[10]; |
||||
|
scanf("%s", nume_str); |
||||
|
|
||||
|
num = nume_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if ((num >= 1 && num <= 9) && nume_str[1] == '\0') { |
||||
|
Sudoku_grid[row_e - 1][col_e - 1] = num; |
||||
|
printf("Value inserted successfully.\n"); |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 9.\n"); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
case 2: |
||||
|
printf("Enter the coordinates (row and column) separated by space:\n"); |
||||
|
int row_d, col_d; |
||||
|
|
||||
|
|
||||
|
while (true){ |
||||
|
char rowd_str[10]; |
||||
|
char cold_str[10]; |
||||
|
scanf("%s %s", rowd_str, cold_str); |
||||
|
|
||||
|
row_d = rowd_str[0] - '0'; // Convert the first character to an integer |
||||
|
col_d = cold_str[0] - '0'; // Convert the first character to an integer |
||||
|
|
||||
|
if (((row_d >= 1 && row_d <= 9) && rowd_str[1] == '\0') && ((col_d >= 1 && col_d <= 9) && cold_str[1] == '\0')) { |
||||
|
Sudoku_grid[row_d - 1][col_d - 1] = 0; |
||||
|
printf("Cell cleared successfully.\n"); |
||||
|
break; |
||||
|
} else { |
||||
|
printf("Invalid input. Please enter a number between 1 and 9.\n"); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
default: |
||||
|
printf("Invalid input. Please enter 1 or 2.\n"); |
||||
|
} |
||||
|
printGrid(Sudoku_grid); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void printGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
printf("\nSudoku Grid:\n"); |
||||
|
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]); |
||||
|
} |
||||
|
printf("\n"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void check_if_Sudoku_solved(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]) { |
||||
|
printf("\nDone function - Checking if the solution is correct...\n"); |
||||
|
|
||||
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; i++) { |
||||
|
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 mainn(){ |
||||
|
Game_loop(); |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
#ifndef SUDOKU_H |
||||
|
#define SUDOKU_H |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
//constants |
||||
|
#define SIZE_OF_GAMEBORD_AXIS_X 9 |
||||
|
#define SIZE_OF_GAMEBORD_AXIS_Y 9 |
||||
|
#define AVAILABLE_DIFFICULTIES 3 |
||||
|
#define AVAILABLE_LEVELS 3 |
||||
|
#define EMPTY 0 |
||||
|
#define LEVEL_NUMBER 3 |
||||
|
|
||||
|
|
||||
|
extern int selected_difficulty; |
||||
|
extern int selected_level; |
||||
|
extern int solutionLevels[AVAILABLE_DIFFICULTIES][AVAILABLE_LEVELS][SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
extern int availableLevels[AVAILABLE_DIFFICULTIES][AVAILABLE_LEVELS][SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
extern bool check_solved; |
||||
|
extern bool test_help; |
||||
|
extern int test_row_e; |
||||
|
extern int test_col_e; |
||||
|
extern int test_num; |
||||
|
|
||||
|
|
||||
|
|
||||
|
//functions |
||||
|
void Game_loop(); //is instead of main |
||||
|
void Level_Pool(int selected_difficulty); |
||||
|
void Level_Selection(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void initializeGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void create_playing_field(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y], int selected_difficulty, int level); |
||||
|
void Player_actions_for_playing(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void giving_hints_to_player(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void write_userinput_into_Sudoku(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void printGrid(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
void check_if_Sudoku_solved(int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]); |
||||
|
int mainn(); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // SUDOKU_H |
@ -0,0 +1,173 @@ |
|||||
|
|
||||
|
#include "unity.h" |
||||
|
|
||||
|
#include "TicTacToe.h" |
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void test_TicTacToe_Winner_X_line_1(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'X', 'X'}, |
||||
|
{'O', 'O', '_'}, |
||||
|
{'O', '_', '_'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_O_line_2(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 2; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'O', 'X'}, |
||||
|
{'O', 'O', 'O'}, |
||||
|
{'O', 'X', 'X'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_X_line_3(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'O', '_', '_'}, |
||||
|
{'O', 'O', '_'}, |
||||
|
{'X', 'X', 'X'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_O_col_1(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 2; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'O', 'X', 'X'}, |
||||
|
{'O', 'O', '_'}, |
||||
|
{'O', '_', '_'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_X_col_2(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'O', 'X', 'X'}, |
||||
|
{'_', 'X', 'O'}, |
||||
|
{'O', 'X', '_'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_O_col_3(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 2; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'X', 'O'}, |
||||
|
{'_', 'O', 'O'}, |
||||
|
{'_', '_', 'O'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_X_diagonal_1(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O'}, |
||||
|
{'O', '_', 'X'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Winner_O_diagonal_2(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 2; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X'}, |
||||
|
{'O', '_', '_'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_mid_Round(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 9; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'X', 'O'}, |
||||
|
{'_', 'O', 'X'}, |
||||
|
{'_', '_', 'O'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
void test_TicTacToe_Tie(void) |
||||
|
{ |
||||
|
/* arrange */ |
||||
|
int expected = 0; |
||||
|
int actual; |
||||
|
char board[3][3] = { |
||||
|
{'X', 'X', 'O'}, |
||||
|
{'O', 'O', 'X'}, |
||||
|
{'X', 'X', 'O'} |
||||
|
}; |
||||
|
/* act */ |
||||
|
actual = Winner(board); |
||||
|
|
||||
|
/* assert */ |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
@ -0,0 +1,151 @@ |
|||||
|
#include "unity.h" |
||||
|
#include "VierGewinnt.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_dropPiece_ValidMove(void) { |
||||
|
char board[6][7]; |
||||
|
initializeBoard(board); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, dropPiece(board, 3, 'X')); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_dropPiece_FullColumn(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(0, dropPiece(board, 3, 'X')); // Spalte ist voll, sollte 0 zurückgeben |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_checkWin_Horizontal_X(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'X', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'O', 'O', 'O', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', 'X', 'X', 'X', 'X', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Horizontale Gewinnsituation für 'X' |
||||
|
} |
||||
|
|
||||
|
void test_checkWin_Horizontal_O(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'X', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'O', 'O', 'O', 'O', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', 'X', 'X', ' ', 'X', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Horizontale Gewinnsituation für 'X' |
||||
|
} |
||||
|
|
||||
|
void test_checkWin_Diagonal_X(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'X', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'O', 'O', 'O', 'X', ' ', ' ', ' '}, |
||||
|
{' ', 'X', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', 'X', 'X', 'X', 'X', ' ', ' '}, |
||||
|
{' ', ' ', ' ','X', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', 'X', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Horizontale Gewinnsituation für 'X' |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void test_checkWin_Diagonal_O(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'X', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'O', 'O', 'O', 'X', ' ', ' ', ' '}, |
||||
|
{' ', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', 'X', 'O', 'X', 'X', ' ', ' '}, |
||||
|
{' ', ' ', ' ','O', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', 'X', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Horizontale Gewinnsituation für 'X' |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void test_checkWin_Vertical_X(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'X', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'X')); // Vertikale Gewinnsituation für 'X' |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
void test_checkWin_Vertical_O(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{'X', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', 'O', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '}, |
||||
|
{' ', ' ', ' ', ' ', ' ', ' ', ' '} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, checkWin(board, 'O')); // Vertikale Gewinnsituation für 'X' |
||||
|
} |
||||
|
void test_checkWin_NoWinner(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'} |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(0, checkWin(board, 'X')); // Kein Gewinner, horizontale Reihe ist voll |
||||
|
TEST_ASSERT_EQUAL_INT(0, checkWin(board, 'O')); // Kein Gewinner, horizontale Reihe ist voll |
||||
|
} |
||||
|
|
||||
|
void test_isColumnFull(void) { |
||||
|
char board[6][7] = { |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'}, |
||||
|
{'X', 'O', 'X', 'O', 'X', 'O', 'X'}, |
||||
|
{'O', 'X', 'O', 'X', 'O', 'X', 'O'} |
||||
|
}; |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT(1, isColumnFull(board, 3)); // Column 3 is full |
||||
|
} |
||||
|
|
@ -0,0 +1,147 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "hangman.h" |
||||
|
|
||||
|
void setUp(void) {} |
||||
|
|
||||
|
void tearDown(void) {} |
||||
|
|
||||
|
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_leerstring_falsch() { |
||||
|
// arrange |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char guessed_letter = 'j'; |
||||
|
char secret_word[100] = ""; |
||||
|
|
||||
|
// act |
||||
|
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_joe_richtig() { |
||||
|
// arrange |
||||
|
int expected = 0; |
||||
|
int actual; |
||||
|
char guessed_letter = 'j'; |
||||
|
char secret_word[100] = "joe"; |
||||
|
|
||||
|
// act |
||||
|
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_buchstabe_im_zu_erratenden_wort_eingabe_k_in_joe_falsch() { |
||||
|
// arrange |
||||
|
int expected = 1; |
||||
|
int actual; |
||||
|
char guessed_letter = 'k'; |
||||
|
char secret_word[100] = "joe"; |
||||
|
|
||||
|
// act |
||||
|
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_buchstabe_im_zu_erratenden_wort_eingabe_j_in_eoj_richtig() { |
||||
|
// arrange |
||||
|
int expected = 0; |
||||
|
int actual; |
||||
|
char guessed_letter = 'j'; |
||||
|
char secret_word[100] = "eoj"; |
||||
|
|
||||
|
// act |
||||
|
actual = buchstabe_im_zu_erratenden_wort(guessed_letter, secret_word); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_leerstring_zu_peter_richtig() { |
||||
|
// arrange |
||||
|
char expected[100] = "r"; |
||||
|
char actual[100] = ""; |
||||
|
char to_add = 'r'; |
||||
|
|
||||
|
// act |
||||
|
erratenen_buchstaben_hinzufuegen(actual, to_add); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_STRING(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_pete_zu_peter_richtig() { |
||||
|
// arrange |
||||
|
char expected[100] = "peter"; |
||||
|
char actual[100] = "pete"; |
||||
|
char to_add = 'r'; |
||||
|
|
||||
|
// act |
||||
|
erratenen_buchstaben_hinzufuegen(actual, to_add); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_STRING(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_erratenen_buchstaben_hinzufuegen_anhaengen_r_an_peter_zu_peter_falsch() { |
||||
|
// arrange |
||||
|
char expected[100] = "peter"; |
||||
|
char actual[100] = "peter"; |
||||
|
char to_add = 'r'; |
||||
|
|
||||
|
// act |
||||
|
erratenen_buchstaben_hinzufuegen(actual, to_add); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_FALSE(expected == actual); |
||||
|
} |
||||
|
|
||||
|
void test_gewonnen_petr_in_peter_richtig() { |
||||
|
// arrange |
||||
|
int expected = 1; |
||||
|
char actual; |
||||
|
char secret_word[100] = "peter"; |
||||
|
char guessed_letters[100] = "petr"; |
||||
|
|
||||
|
// act |
||||
|
actual = gewonnen(secret_word, guessed_letters); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_gewonnen_p_in_peter_falsch() { |
||||
|
// arrange |
||||
|
int expected = 0; |
||||
|
char actual; |
||||
|
char secret_word[100] = "peter"; |
||||
|
char guessed_letters[100] = "p"; |
||||
|
|
||||
|
// act |
||||
|
actual = gewonnen(secret_word, guessed_letters); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
void test_gewonnen_petr_in_leerstring_richtig() { |
||||
|
// arrange |
||||
|
int expected = 1; |
||||
|
char actual; |
||||
|
char secret_word[100] = ""; |
||||
|
char guessed_letters[100] = "petr"; |
||||
|
|
||||
|
// act |
||||
|
actual = gewonnen(secret_word, guessed_letters); |
||||
|
|
||||
|
// assert |
||||
|
TEST_ASSERT_EQUAL_INT(expected, actual); |
||||
|
} |
||||
|
|
||||
|
#endif // TEST |
@ -0,0 +1,286 @@ |
|||||
|
#ifdef TEST |
||||
|
|
||||
|
#include "unity.h" |
||||
|
#include "sudoku.h" |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
#include <assert.h> |
||||
|
|
||||
|
|
||||
|
|
||||
|
void setUp(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
//1 |
||||
|
|
||||
|
// Unit test for Level_Pool() function |
||||
|
// Call the Level_Pool() function, prints 3 fixed lines and "Available levels for Difficulty <selected difficulty>" |
||||
|
void test_Level_Pool_0() { |
||||
|
selected_difficulty = 0; |
||||
|
Level_Pool(selected_difficulty); |
||||
|
//TEST_PASS(); |
||||
|
printf("Unit test for Level_Pool_0() executed.\n"); |
||||
|
} |
||||
|
|
||||
|
void test_Level_Pool_5() { |
||||
|
selected_difficulty = 5; |
||||
|
Level_Pool(selected_difficulty); |
||||
|
//TEST_PASS(); |
||||
|
printf("Unit test for Level_Pool_5() executed.\n"); |
||||
|
} |
||||
|
|
||||
|
void test_Level_Pool_neg_1() { |
||||
|
selected_difficulty = -1; |
||||
|
Level_Pool(selected_difficulty); |
||||
|
//TEST_PASS(); |
||||
|
printf("Unit test for Level_Pool_-1() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
//2 |
||||
|
|
||||
|
void test_initializeGrid() { |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
|
||||
|
|
||||
|
initializeGrid(Sudoku_grid); |
||||
|
int expected = EMPTY; |
||||
|
|
||||
|
|
||||
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; ++i) { |
||||
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; ++j) { |
||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected, Sudoku_grid[i][j], "Checking if every space is 0"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
printf("Unit test for initializeGrid() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//3 |
||||
|
|
||||
|
void test_create_playing_field_level_medium_two() { |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
selected_difficulty = 2; |
||||
|
selected_level = 2; |
||||
|
int expected_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = {{7, 0, 2, 0, 0, 0, 9, 5, 0}, |
||||
|
{0, 0, 0, 7, 5, 0, 2, 0, 6}, |
||||
|
{0, 0, 5, 0, 2, 8, 7, 0, 3}, |
||||
|
{5, 1, 8, 0, 3, 0, 6, 0, 0}, |
||||
|
{0, 0, 6, 1, 0, 0, 0, 3, 0}, |
||||
|
{0, 0, 0, 0, 6, 2, 0, 8, 1}, |
||||
|
{0, 9, 0, 2, 0, 4, 0, 0, 5}, |
||||
|
{0, 0, 0, 0, 9, 0, 0, 0, 4}, |
||||
|
{0, 5, 1, 0, 0, 0, 0, 9, 2}}; |
||||
|
|
||||
|
create_playing_field(Sudoku_grid, selected_difficulty, selected_level); |
||||
|
|
||||
|
// Check if the generated Sudoku grid is valid |
||||
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; ++i) { |
||||
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; ++j) { |
||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected_grid[i][j], Sudoku_grid[i][j], "Checking if every space is correct"); |
||||
|
}} |
||||
|
|
||||
|
printf("Unit test for create_playing_field() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
//4 |
||||
|
|
||||
|
// Unit test for printGrid() function |
||||
|
void test_printGrid() { |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
||||
|
{5, 3, 0, 0, 7, 0, 0, 0, 0}, |
||||
|
{6, 0, 0, 1, 9, 5, 0, 0, 0}, |
||||
|
{0, 9, 8, 0, 0, 0, 0, 6, 0}, |
||||
|
{8, 0, 0, 0, 6, 0, 0, 0, 3}, |
||||
|
{4, 0, 0, 8, 0, 3, 0, 0, 1}, |
||||
|
{7, 0, 0, 0, 2, 0, 0, 0, 6}, |
||||
|
{0, 6, 0, 0, 0, 0, 2, 8, 0}, |
||||
|
{0, 0, 0, 4, 1, 9, 0, 0, 5}, |
||||
|
{0, 0, 0, 0, 8, 0, 0, 7, 9} |
||||
|
}; |
||||
|
|
||||
|
printf("Sudoku Grid:\n"); |
||||
|
printGrid(Sudoku_grid); |
||||
|
//TEST_PASS(); |
||||
|
printf("Unit test for printGrid() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//5 |
||||
|
|
||||
|
// Unit test for check_if_Sudoku_solved() function |
||||
|
void test_check_if_Sudoku_solved_everything_correct() { |
||||
|
selected_difficulty = 1; |
||||
|
selected_level = 1; |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
||||
|
{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}; |
||||
|
|
||||
|
|
||||
|
check_if_Sudoku_solved(Sudoku_grid); |
||||
|
TEST_ASSERT_TRUE(check_solved); |
||||
|
|
||||
|
|
||||
|
printf("Unit test for check_if_Sudoku_solved() executed.\n"); |
||||
|
} |
||||
|
|
||||
|
void test_check_if_Sudoku_solved_mistake_on_purpose() { |
||||
|
selected_difficulty = 1; |
||||
|
selected_level = 1; |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
||||
|
{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 3}}; |
||||
|
|
||||
|
|
||||
|
check_if_Sudoku_solved(Sudoku_grid); |
||||
|
TEST_ASSERT_FALSE(check_solved); |
||||
|
|
||||
|
|
||||
|
printf("Unit test for check_if_Sudoku_solved() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//6 |
||||
|
|
||||
|
void test_Game_loop_1(){ |
||||
|
test_help = true; |
||||
|
selected_difficulty = 1; |
||||
|
Game_loop(); |
||||
|
printf("Unit test for Game_loop() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
//7 |
||||
|
|
||||
|
void test_Level_Selection_2_2(){ |
||||
|
test_help = true; |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
selected_difficulty = 1; |
||||
|
selected_level = 1; |
||||
|
|
||||
|
Level_Selection(Sudoku_grid); |
||||
|
|
||||
|
int expected = EMPTY; |
||||
|
|
||||
|
|
||||
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; ++i) { |
||||
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; ++j) { |
||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected, Sudoku_grid[i][j], "Checking if level gets initialized correctly"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
printf("Unit test for Level_Selection() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
//8 |
||||
|
|
||||
|
void test_Player_actions_for_playing_print_and_solve(){ |
||||
|
test_help = true; |
||||
|
selected_difficulty = 1; |
||||
|
selected_level = 1; |
||||
|
|
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = { |
||||
|
{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}; |
||||
|
|
||||
|
Player_actions_for_playing(Sudoku_grid); |
||||
|
TEST_ASSERT_TRUE(check_solved); |
||||
|
printf("Unit test for Player_actions_for_playing() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
//9 |
||||
|
|
||||
|
void test_giving_hints_to_player(){ |
||||
|
test_help = true; |
||||
|
int selected_difficulty = 1; |
||||
|
int selected_level = 1; |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = |
||||
|
{ |
||||
|
{5, 3, 0, 0, 7, 0, 0, 0, 0}, |
||||
|
{6, 0, 0, 1, 9, 5, 0, 0, 0}, |
||||
|
{0, 9, 8, 0, 0, 0, 0, 6, 0}, |
||||
|
{8, 0, 0, 0, 6, 0, 0, 0, 3}, |
||||
|
{4, 0, 0, 8, 0, 3, 0, 0, 1}, |
||||
|
{7, 0, 0, 0, 2, 0, 0, 0, 6}, |
||||
|
{0, 6, 0, 0, 0, 0, 2, 8, 0}, |
||||
|
{0, 0, 0, 4, 1, 9, 0, 0, 5}, |
||||
|
{0, 0, 0, 0, 8, 0, 0, 7, 9} |
||||
|
}; |
||||
|
int expected_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y] = |
||||
|
{{4, 7, 3, 6, 2, 1, 8, 5, 9}, |
||||
|
{6, 8, 5, 9, 7, 4, 1, 3, 2}, |
||||
|
{9, 2, 1, 5, 3, 8, 7, 6, 4}, |
||||
|
{7, 6, 9, 3, 5, 2, 4, 8, 1}, |
||||
|
{8, 5, 4, 1, 9, 7, 6, 2, 3}, |
||||
|
{1, 3, 2, 4, 8, 6, 9, 7, 5}, |
||||
|
{2, 9, 7, 8, 1, 5, 3, 4, 6}, |
||||
|
{3, 4, 8, 2, 6, 9, 5, 1, 7}, |
||||
|
{5, 1, 6, 7, 4, 3, 2, 9, 8}}; |
||||
|
|
||||
|
giving_hints_to_player(Sudoku_grid); |
||||
|
|
||||
|
// Check if the generated Sudoku grid is valid |
||||
|
for (int i = 0; i < SIZE_OF_GAMEBORD_AXIS_X; ++i) { |
||||
|
for (int j = 0; j < SIZE_OF_GAMEBORD_AXIS_Y; ++j) { |
||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(expected_grid[i][j], Sudoku_grid[i][j], "Checking if every space is correct"); |
||||
|
}} |
||||
|
|
||||
|
|
||||
|
printf("Unit test for giving_hints_to_player() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 10 |
||||
|
|
||||
|
void test_write_userinput_into_Sudoku_9_into_empty(){ |
||||
|
test_help = true; |
||||
|
test_row_e = 1; |
||||
|
test_col_e = 1; |
||||
|
test_num = 9; |
||||
|
int Sudoku_grid[SIZE_OF_GAMEBORD_AXIS_X][SIZE_OF_GAMEBORD_AXIS_Y]; |
||||
|
|
||||
|
|
||||
|
write_userinput_into_Sudoku(Sudoku_grid); |
||||
|
|
||||
|
TEST_ASSERT_EQUAL_INT_MESSAGE(test_num, Sudoku_grid[test_row_e -1][test_col_e -1], "Checking if number input is correct"); |
||||
|
|
||||
|
|
||||
|
|
||||
|
printf("Unit test for write_userinput_into_Sudoku() executed.\n\n"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif // TEST |
Write
Preview
Loading…
Cancel
Save
Reference in new issue