From 1ae5132e050883be63c16d80335bd35d31ce36fc Mon Sep 17 00:00:00 2001 From: Emman Mensdorf Date: Mon, 5 Feb 2024 21:28:19 +0100 Subject: [PATCH] Dame bewegung erweiterung, Emman Mensdorf --- src/Dame.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Dame.c b/src/Dame.c index 210d10b..86291e7 100644 --- a/src/Dame.c +++ b/src/Dame.c @@ -12,5 +12,28 @@ bool istzugerlaubt_Dame(char** Brett, int startX, int startY, int endX, int endY if (endX < 0 || endX >= 8 || endY < 0 || endY >= 8) return false; + + int dx = abs(endX - startX); + int dy = abs(endY - startY); + + + if (dx != 0 && dy != 0 && dx != dy) + return false; + + + if (dx > 0) { + int dirX = (endX - startX) / dx; + for (int i = 1; i < dx; i++) { + if (Brett[startY + i * dirX][startX + i * dirX] != ' ') + return false; + } + } + if (dy > 0) { + int dirY = (endY - startY) / dy; + for (int i = 1; i < dy; i++) { + if (Brett[startY + i * dirY][startX + i * dirY] != ' ') + return false; + } + } } \ No newline at end of file