diff --git a/src/Bauernumwandlung.c b/src/Bauernumwandlung.c new file mode 100644 index 0000000..a8a0055 --- /dev/null +++ b/src/Bauernumwandlung.c @@ -0,0 +1,54 @@ +#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')){ + return true; + }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){ + + if(ist_umwandlung_gerlaubt_Bauer(Brett ,startX,startY,endX,endY,player) == true){ + char* Figur; + printf("Welche Figur soll erstellt werden?"); + if(player == PLAYER_WHITE){ + printf("Q für Dame, R für Turm, B für Läufer oder N für Springer"); + Figur = getUserInput(); + }else{ + printf("q für Dame, r für Turm, b für Läufer oder n für Springer"); + 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'))){ + return Figur; + }else{ + return '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("Zug ungültig"); + } +} + diff --git a/src/Bauernumwandlung.h b/src/Bauernumwandlung.h new file mode 100644 index 0000000..8f6d85f --- /dev/null +++ b/src/Bauernumwandlung.h @@ -0,0 +1,11 @@ +#ifndef BAUER_UM_H +#define BAUER_UM_H + +#include +#include "spieler.h" + +bool ist_umwandlung_gerlaubt_Bauer(char** Brett, int startX, int startY, int endX, int endY, Player player); +char* bauer_umwandel_abfrage(char** Brett, int startX, int startY, int endX, int endY, Player player); +void bauer_umwandeln(char** Brett, int startX, int startY, int endX, int endY, Player player); + +#endif // BAUER_UM_H diff --git a/test/test_Bauernumwandlung.c b/test/test_Bauernumwandlung.c new file mode 100644 index 0000000..f610822 --- /dev/null +++ b/test/test_Bauernumwandlung.c @@ -0,0 +1,38 @@ +#ifdef TEST +#include "unity.h" +#include +#include "Schachbrett.h" +#include "Bauer.h" +#include "Input.h" +#include "Bauernumwandlung.h" + +void setUp(void) { +} + +void tearDown(void) { +} + +void test_Bauernumwandlung_erlaubt(void) { + + char** brett = Schachbrett_erstellen(); + int startX = 6; + int startY = 6; + int endX = 6; + int endY = 7; + Player player = PLAYER_WHITE; + + + TEST_ASSERT_NOT_NULL(brett); + + brett[6][6] = 'P'; + brett[7][6] = ' '; + + TEST_ASSERT_TRUE(ist_umwandlung_gerlaubt_Bauer( brett, startX, startY, endX, endY, player)); + + + for (int i = 0; i < 8; i++) { + free(brett[i]); + } + free(brett); +} +#endif // TEST