--- a/src/chess/knight.c Sun Aug 02 15:19:47 2026 +0200 +++ b/src/chess/knight.c Thu Aug 06 14:45:55 2026 +0200 @@ -37,3 +37,36 @@ return (dx == 2 && dy == 1) || (dx == 1 && dy == 2); } + +size_t knight_moves(GameState *gamestate, Color c, Row r, File f, Move *moves) { + + size_t count = 0; + const int offsets[8][2] = { + { 2, 1}, + { 2, -1}, + {-2, 1}, + {-2, -1}, + { 1, 2}, + { 1, -2}, + {-1, 2}, + {-1, -2} + }; + + for (size_t i = 0 ; i < 8 ; i++) { + int row = r + offsets[i][0]; + int file = f + offsets[i][1]; + + if (isidx(row) && isidx(file)) { + moves[count] = (Move){0}; + moves[count].piece = mkpiece(KNIGHT, 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++; + } + } + + return count; +}