diff --git a/src/Bauernumwandlung.c b/src/Bauernumwandlung.c index 417a991..7f05e2b 100644 --- a/src/Bauernumwandlung.c +++ b/src/Bauernumwandlung.c @@ -1,21 +1,19 @@ #include -#include #include +#include #include "spieler.h" #include "Moving.h" #include "Bauer.h" #include "Input.h" bool ist_umwandlung_gerlaubt_Bauer(char** Brett, int startX, int startY, int endX, int endY, Player player) { - - if((player == PLAYER_WHITE) && (endY == 7) && (Brett[startY][startX] == 'P')){ + if ((player == PLAYER_WHITE) && (endY == 7) && (Brett[startY][startX] == 'P')) { return true; - }else if((player == PLAYER_BLACK) && (endY == 0) && (Brett[startY][startX] == 'p')){ - return true; - }else{ - return false; - } - + } else if ((player == PLAYER_BLACK) && (endY == 0) && (Brett[startY][startX] == 'p')) { + return true; + } else { + return false; + } } char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int endY, Player player){ @@ -31,24 +29,22 @@ char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int Figur = getUserInput(); } - if((player == PLAYER_WHITE && (Figur == 'Q' || Figur == 'R' || Figur == 'B' || Figur == 'N')) || - (player == PLAYER_BLACK && (Figur == 'q' || Figur == 'r' || Figur == 'b' || Figur == 'n'))){ + if ((player == PLAYER_WHITE && (Figur == 'Q' || Figur == 'R' || Figur == 'B' || Figur == 'N')) || + (player == PLAYER_BLACK && (Figur == 'q' || Figur == 'r' || Figur == 'b' || Figur == 'n'))) { return Figur; - }else{ - return 'W'; + } else { + return 'W'; // Undefiniertes Zeichen als Fehlerwert } } - + return 'W'; // Undefiniertes Zeichen als Fehlerwert } -void bauer_umwandeln(char** Brett, int startX, int startY, int endX, int endY, Player player){ - - char* Figur = bauer_umwandel_abfrage(Brett,startX,startY,endX,endY,player); - if(Figur != 'W'){ +void bauer_umwandeln(char** Brett, int startX, int startY, int endX, int endY, Player player) { + char Figur = bauer_umwandel_abfrage(Brett, startX, startY, endX, endY, player); + if (Figur != 'W') { Brett[endY][endX] = Figur; Brett[startY][startX] = ' '; }else{ printf("Invalid move"); } } - diff --git a/src/schach_in_ein_puzzle/PuzzleI.c b/src/schach_in_ein_puzzle/PuzzleI.c index d927864..8d6f5d8 100644 --- a/src/schach_in_ein_puzzle/PuzzleI.c +++ b/src/schach_in_ein_puzzle/PuzzleI.c @@ -59,4 +59,16 @@ void print_Puzzlebrett(char** Brett) { printf("\n"); } printf("\n"); +} + +void Puzzlebrettspeicher_freigeben(char** Brett) { + if (Brett == NULL) { + return; + } + + for (int i = 0; i < 8; i++) { + free(Brett[i]); + } + + free(Brett); } \ No newline at end of file diff --git a/src/schach_in_ein_puzzle/PuzzleI.h b/src/schach_in_ein_puzzle/PuzzleI.h index 867c5cd..112a9a2 100644 --- a/src/schach_in_ein_puzzle/PuzzleI.h +++ b/src/schach_in_ein_puzzle/PuzzleI.h @@ -5,5 +5,6 @@ char** Puzzlebrett_erstellen(); void print_Puzzlebrett(char** Brett); +void Puzzlebrettspeicher_freigeben(char** Brett); #endif // PUZZLEI_H \ No newline at end of file