diff --git a/src/Koenig.c b/src/Koenig.c index 19b1c0e..c51ad4a 100644 --- a/src/Koenig.c +++ b/src/Koenig.c @@ -333,3 +333,21 @@ void rochiere(char** Brett, Player player, bool kingside, Spielstatus* status) { } } } +bool KannKoenigEntkommen(char** Brett, int koenigX, int koenigY, Player player) { + int directions[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; + for (int i = 0; i < 8; i++) { + int neuX = koenigX + directions[i][0]; + int neuY = koenigY + directions[i][1]; + + if (neuX >= 0 && neuX < 8 && neuY >= 0 && neuY < 8) { + char zielFeld = Brett[neuY][neuX]; + if ((player == PLAYER_WHITE && (zielFeld == ' ' || islower(zielFeld))) || + (player == PLAYER_BLACK && (zielFeld == ' ' || isupper(zielFeld)))) { + if (!istFeldUnsicher(Brett, neuX, neuY, player)) { + return true; + } + } + } + } + return false; +} \ No newline at end of file diff --git a/src/Koenig.h b/src/Koenig.h index 8bd6b03..cd99f44 100644 --- a/src/Koenig.h +++ b/src/Koenig.h @@ -14,4 +14,5 @@ bool istzugerlaubt_Koenig(char** Brett, int startX, int startY, int endX, int en void bewegeKoenig(char** Brett, int startX, int startY, int endX, int endY, Player player, Spielstatus* status); bool kannRochieren(char** Brett, int startX, int startY, Player player, Spielstatus* status, bool kingside); void rochiere(char** Brett, Player player, bool kingside, Spielstatus* status); +bool KannKoenigEntkommen(char** Brett, int koenigX, int koenigY, Player player); #endif // Koenig