From cef1efacb03d03cc8a4d3c307f6bcfc57869c0eb Mon Sep 17 00:00:00 2001 From: fdai7492 Date: Tue, 6 Feb 2024 04:59:56 +0000 Subject: [PATCH] =?UTF-8?q?K=C3=B6nig=20Hilfsfunktion,=20Anton=20Lohrey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Koenig.c | 18 ++++++++++++++++++ src/Koenig.h | 1 + 2 files changed, 19 insertions(+) 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