src/chess/bishop.c

changeset 169
9962f5d98764
parent 163
2a6d83f4677e
child 170
bde99d803caf
--- a/src/chess/bishop.c	Sun Aug 02 15:19:47 2026 +0200
+++ b/src/chess/bishop.c	Thu Aug 06 14:45:55 2026 +0200
@@ -52,3 +52,35 @@
     
     return false;
 }
+
+size_t bishop_moves(GameState *gamestate, Color c, Row r, File f, Move *moves) {
+
+    size_t count = 0;
+    const int directions[4][2] = {
+        { 1,  1},
+        { 1, -1},
+        {-1,  1},
+        {-1, -1}
+    };
+
+    for (size_t i = 0 ; i < 4 ; i++) {
+        int row = r + directions[i][0];
+        int file = f + directions[i][1];
+
+        while (isidx(row) && isidx(file)) {
+            moves[count] = (Move){0};
+            moves[count].piece = mkpiece(BISHOP, c);
+            moves[count].fromrow = r;
+            moves[count].fromfile = f;
+            moves[count].torow = row;
+            moves[count].tofile = file;
+            moves[count].capture = piece_at(gamestate, row, file) != 0;
+            count++;
+
+            row += directions[i][0];
+            file += directions[i][1];
+        }
+    }
+
+    return count;
+}

mercurial