Browse Source

König Hilfsfunktion, Anton Lohrey

remotes/origin/Läufer-fertig,-Hendrik-Voß
fdai7492 11 months ago
parent
commit
cef1efacb0
  1. 18
      src/Koenig.c
  2. 1
      src/Koenig.h

18
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;
}

1
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
Loading…
Cancel
Save